View Javadoc
1   package org.apache.maven.rtinfo.internal;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.rtinfo.RuntimeInformation;
23  import org.codehaus.plexus.PlexusTestCase;
24  
25  public class DefaultRuntimeInformationTest
26      extends PlexusTestCase
27  {
28  
29      public void testGetMavenVersion()
30          throws Exception
31      {
32          RuntimeInformation rtInfo = lookup( RuntimeInformation.class );
33  
34          String mavenVersion = rtInfo.getMavenVersion();
35          assertNotNull( mavenVersion );
36          assertTrue( mavenVersion.length() > 0 );
37      }
38  
39      public void testIsMavenVersion()
40          throws Exception
41      {
42          RuntimeInformation rtInfo = lookup( RuntimeInformation.class );
43  
44          assertTrue( rtInfo.isMavenVersion( "2.0" ) );
45          assertFalse( rtInfo.isMavenVersion( "9.9" ) );
46  
47          assertTrue( rtInfo.isMavenVersion( "[2.0.11,2.1.0),[3.0,)" ) );
48          assertFalse( rtInfo.isMavenVersion( "[9.0,)" ) );
49  
50          try
51          {
52              rtInfo.isMavenVersion( "[3.0," );
53              fail( "Bad version range wasn't rejected" );
54          }
55          catch ( IllegalArgumentException e )
56          {
57              assertTrue( true );
58          }
59  
60          try
61          {
62              rtInfo.isMavenVersion( "" );
63              fail( "Bad version range wasn't rejected" );
64          }
65          catch ( IllegalArgumentException e )
66          {
67              assertTrue( true );
68          }
69  
70          try
71          {
72              rtInfo.isMavenVersion( null );
73              fail( "Bad version range wasn't rejected" );
74          }
75          catch ( NullPointerException e )
76          {
77              assertTrue( true );
78          }
79      }
80  
81  }