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 extends TestCase {
31      // TODO: Add testing for multidigit version numbers
32      // TODO: Add tests for invalid version strings
33      public void testVersionParsing() {
34          Version version = new Version("1.2.3");
35  
36          assertEquals(1, version.getMajor());
37  
38          assertEquals(2, version.getMinor());
39  
40          assertEquals(3, version.getMicro());
41      }
42  
43      public void testVersionRange() {
44          VersionRange range = new VersionRange("2.0.0+");
45  
46          assertFalse(new Version("1.0.0").inside(range));
47  
48          assertTrue(new Version("2.0.0").inside(range));
49  
50          assertTrue(new Version("3.0.0").inside(range));
51  
52          assertTrue(new Version("2.0.0").equals(range.getFromVersion()));
53  
54          assertTrue(Version.INFINITE.equals(range.getToVersion()));
55  
56          range = new VersionRange("1.0.0");
57  
58          assertTrue(new Version("1.0.0").equals(range.getFromVersion()));
59  
60          assertTrue(new Version("1.0.0").equals(range.getToVersion()));
61  
62          range = new VersionRange("1.0.0/3.0.0");
63  
64          assertTrue(new Version("1.0.0").equals(range.getFromVersion()));
65  
66          assertTrue(new Version("3.0.0").equals(range.getToVersion()));
67      }
68  
69      public void testGreaterThanWhenFooIsLessThanBar() {
70          assertNotGreaterThan("1.0.0", "2.9.9");
71          assertNotGreaterThan("1.9.9", "2.0.0");
72          assertNotGreaterThan("0.1.0", "0.2.9");
73          assertNotGreaterThan("0.1.1", "0.2.0");
74          assertNotGreaterThan("0.0.1", "0.0.1");
75      }
76  
77      public void testGreaterThanWhenFooIsEqualBar() {
78          assertNotGreaterThan("1.2.3", "1.2.3");
79      }
80  
81      public void testGreaterThanWhenFooIsGreaterThanBar() {
82          assertGreaterThan("2.0.0", "1.9.9");
83          assertGreaterThan("2.9.9", "1.0.0");
84          assertGreaterThan("0.2.9", "0.1.0");
85          assertGreaterThan("0.2.0", "0.1.9");
86          assertGreaterThan("0.0.2", "0.0.1");
87      }
88  
89      private void assertGreaterThan(String foo, String bar) {
90          assertTrue(new Version(foo).greaterThan(new Version(bar)));
91      }
92  
93      private void assertNotGreaterThan(String foo, String bar) {
94          assertFalse(new Version(foo).greaterThan(new Version(bar)));
95      }
96  }