01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2006, Geotools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: */
16: package org.geotools.util;
17:
18: // JUnit dependencies
19: import junit.framework.Test;
20: import junit.framework.TestCase;
21: import junit.framework.TestSuite;
22:
23: /**
24: * Tests the {@link Version} class, especially the {@code compareTo} method.
25: *
26: * @since 2.4
27: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/metadata/src/test/java/org/geotools/util/VersionTest.java $
28: * @version $Id: VersionTest.java 24576 2007-02-24 00:07:40Z desruisseaux $
29: * @author Martin Desruisseaux
30: */
31: public final class VersionTest extends TestCase {
32: /**
33: * Run the suit from the command line.
34: */
35: public static void main(final String[] args) {
36: junit.textui.TestRunner.run(suite());
37: }
38:
39: /**
40: * Returns the test suite.
41: */
42: public static Test suite() {
43: return new TestSuite(VersionTest.class);
44: }
45:
46: /**
47: * Constructs a test case with the given name.
48: */
49: public VersionTest(final String name) {
50: super (name);
51: }
52:
53: /**
54: * Tests a numeric-only version.
55: */
56: public void testNumeric() {
57: final Version version = new Version("6.11.2");
58: assertEquals("6.11.2", version.toString());
59: assertEquals(new Integer(6), version.getMajor());
60: assertEquals(new Integer(11), version.getMinor());
61: assertEquals(new Integer(2), version.getRevision());
62: assertSame(version.getRevision(), version.getComponent(2));
63: assertNull(version.getComponent(3));
64:
65: assertTrue(version.compareTo(new Version("6.11.2")) == 0);
66: assertTrue(version.compareTo(new Version("6.8")) > 0);
67: assertTrue(version.compareTo(new Version("6.12.0")) < 0);
68: assertTrue(version.compareTo(new Version("6.11")) > 0);
69: }
70:
71: /**
72: * Tests a alpha-numeric version.
73: */
74: public void testAlphaNumeric() {
75: final Version version = new Version("1.6.b2");
76: assertEquals("1.6.b2", version.toString());
77: assertEquals(new Integer(1), version.getMajor());
78: assertEquals(new Integer(6), version.getMinor());
79: assertEquals("b2", version.getRevision());
80: assertSame(version.getRevision(), version.getComponent(2));
81: assertNull(version.getComponent(3));
82:
83: assertTrue(version.compareTo(new Version("1.6.b2")) == 0);
84: assertTrue(version.compareTo(new Version("1.6.b1")) > 0);
85: assertTrue(version.compareTo(new Version("1.07.b1")) < 0);
86: }
87: }
|