View Javadoc

1   package org.codehaus.modello.model;
2   
3   /*
4    * Copyright (c) 2004, Jason van Zyl
5    *
6    * Permission is hereby granted, free of charge, to any person obtaining a copy of
7    * this software and associated documentation files (the "Software"), to deal in
8    * the Software without restriction, including without limitation the rights to
9    * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10   * of the Software, and to permit persons to whom the Software is furnished to do
11   * so, subject to the following conditions:
12   *
13   * The above copyright notice and this permission notice shall be included in all
14   * copies or substantial portions of the Software.
15   *
16   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22   * SOFTWARE.
23   */
24  
25  import junit.framework.TestCase;
26  
27  /**
28   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
29   */
30  public class VersionTest
31      extends TestCase
32  {
33      // TODO: Add testing for multidigit version numbers
34      // TODO: Add tests for invalid version strings
35      public void testVersionParsing()
36      {
37          Version version = new Version( "1.2.3" );
38  
39          assertEquals( 1, version.getMajor() );
40  
41          assertEquals( 2, version.getMinor() );
42  
43          assertEquals( 3, version.getMicro() );
44      }
45  
46      public void testVersionRange()
47      {
48          VersionRange range = new VersionRange( "2.0.0+" );
49  
50          assertFalse( new Version( "1.0.0" ).inside( range ) );
51  
52          assertTrue( new Version( "2.0.0" ).inside( range ) );
53  
54          assertTrue( new Version( "3.0.0" ).inside( range ) );
55  
56          assertTrue( new Version( "2.0.0" ).equals( range.getFromVersion() ) );
57  
58          assertTrue( Version.INFINITE.equals( range.getToVersion() ) );
59  
60          range = new VersionRange( "1.0.0" );
61  
62          assertTrue( new Version( "1.0.0" ).equals( range.getFromVersion() ) );
63  
64          assertTrue( new Version( "1.0.0" ).equals( range.getToVersion() ) );
65  
66          range = new VersionRange( "1.0.0/3.0.0" );
67  
68          assertTrue( new Version( "1.0.0" ).equals( range.getFromVersion() ) );
69  
70          assertTrue( new Version( "3.0.0" ).equals( range.getToVersion() ) );
71      }
72  
73      public void testGreaterThanWhenFooIsLessThanBar()
74      {
75          assertNotGreaterThan( "1.0.0", "2.9.9" );
76          assertNotGreaterThan( "1.9.9", "2.0.0" );
77          assertNotGreaterThan( "0.1.0", "0.2.9" );
78          assertNotGreaterThan( "0.1.1", "0.2.0" );
79          assertNotGreaterThan( "0.0.1", "0.0.1" );
80      }
81  
82      public void testGreaterThanWhenFooIsEqualBar()
83      {
84          assertNotGreaterThan( "1.2.3", "1.2.3" );
85      }
86  
87      public void testGreaterThanWhenFooIsGreaterThanBar()
88      {
89          assertGreaterThan( "2.0.0", "1.9.9" );
90          assertGreaterThan( "2.9.9", "1.0.0" );
91          assertGreaterThan( "0.2.9", "0.1.0" );
92          assertGreaterThan( "0.2.0", "0.1.9" );
93          assertGreaterThan( "0.0.2", "0.0.1" );
94      }
95  
96      private void assertGreaterThan( String foo, String bar )
97      {
98          assertTrue( new Version( foo ).greaterThan( new Version( bar ) ) );
99      }
100 
101     private void assertNotGreaterThan( String foo, String bar )
102     {
103         assertFalse( new Version( foo ).greaterThan( new Version( bar ) ) );
104     }
105 }