View Javadoc

1   package org.apache.maven.plugin.invoker;
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 java.util.ArrayList;
23  import java.util.Arrays;
24  import java.util.List;
25  
26  import junit.framework.TestCase;
27  
28  /**
29   * Tests {@link SelectorUtils}.
30   * 
31   * @author Benjamin Bentmann
32   */
33  public class SelectorUtilsTest
34      extends TestCase
35  {
36  
37      private List<Integer> list( int[] numbers )
38      {
39          List<Integer> result = new ArrayList<Integer>();
40  
41          for ( int i = 0; i < numbers.length; i++ )
42          {
43              result.add( new Integer( numbers[i] ) );
44          }
45  
46          return result;
47      }
48  
49      public void testParseList()
50      {
51          List<String> includes = new ArrayList<String>();
52          List<String> excludes = new ArrayList<String>();
53  
54          SelectorUtils.parseList( null, includes, excludes );
55  
56          SelectorUtils.parseList( " 1.5, !1.4, 1.6+ ", includes, excludes );
57          assertEquals( Arrays.asList( new String[] { "1.5", "1.6+" } ), includes );
58          assertEquals( Arrays.asList( new String[] { "1.4" } ), excludes );
59      }
60  
61      public void testParseVersion()
62      {
63          assertEquals( list( new int[] { 1, 6, 0, 12 } ), SelectorUtils.parseVersion( "1.6.0_12" ) );
64  
65          assertEquals( list( new int[] { 1, 6, 0, 12 } ), SelectorUtils.parseVersion( "1.6.0_12+" ) );
66          assertEquals( list( new int[] { 1, 6, 0, 12 } ), SelectorUtils.parseVersion( "1.6.0_12-" ) );
67      }
68  
69      public void testCompareVersions()
70      {
71          assertTrue( SelectorUtils.compareVersions( list( new int[] { 1, 6 } ), list( new int[] { 1, 6 } ) ) == 0 );
72  
73          assertTrue( SelectorUtils.compareVersions( list( new int[] { 1, 5 } ), list( new int[] { 1, 6 } ) ) < 0 );
74          assertTrue( SelectorUtils.compareVersions( list( new int[] { 1, 6 } ), list( new int[] { 1, 5 } ) ) > 0 );
75  
76          assertTrue( SelectorUtils.compareVersions( list( new int[] { 1 } ), list( new int[] { 1, 6 } ) ) < 0 );
77          assertTrue( SelectorUtils.compareVersions( list( new int[] { 1, 6 } ), list( new int[] { 1 } ) ) > 0 );
78      }
79  
80      public void testIsMatchingJre()
81      {
82          assertFalse( SelectorUtils.isJreVersion( list( new int[] { 1, 4, 2, 8 } ), "1.5" ) );
83          assertTrue( SelectorUtils.isJreVersion( list( new int[] { 1, 5 } ), "1.5" ) );
84          assertTrue( SelectorUtils.isJreVersion( list( new int[] { 1, 5, 9 } ), "1.5" ) );
85          assertFalse( SelectorUtils.isJreVersion( list( new int[] { 1, 6 } ), "1.5" ) );
86  
87          assertFalse( SelectorUtils.isJreVersion( list( new int[] { 1, 4, 2, 8 } ), "1.5+" ) );
88          assertTrue( SelectorUtils.isJreVersion( list( new int[] { 1, 5 } ), "1.5+" ) );
89          assertTrue( SelectorUtils.isJreVersion( list( new int[] { 1, 5, 9 } ), "1.5+" ) );
90          assertTrue( SelectorUtils.isJreVersion( list( new int[] { 1, 6 } ), "1.5+" ) );
91  
92          assertTrue( SelectorUtils.isJreVersion( list( new int[] { 1, 4, 2, 8 } ), "1.5-" ) );
93          assertFalse( SelectorUtils.isJreVersion( list( new int[] { 1, 5 } ), "1.5-" ) );
94          assertFalse( SelectorUtils.isJreVersion( list( new int[] { 1, 5, 9 } ), "1.5-" ) );
95          assertFalse( SelectorUtils.isJreVersion( list( new int[] { 1, 6 } ), "1.5-" ) );
96      }
97  
98  }