001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.util;
022:
023: import junit.framework.TestCase;
024:
025: /**
026: * <a href="VersionTest.java.html"><b><i>View Source</i></b></a>
027: *
028: * @author Jorge Ferrer
029: *
030: */
031: public class VersionTest extends TestCase {
032:
033: public void testBugFixNumber() {
034: assertPrevious("1.1.0", "1.1.1");
035: assertLater("1.1.1", "1.1.0");
036: assertLater("1.2.0", "1.1.1");
037: }
038:
039: public void testMajorNumber() {
040: assertPrevious("1.1", "1.1.1");
041: assertLater("2", "1.1.1");
042: assertLater("2", "1");
043: }
044:
045: public void testMinorNumber() {
046: assertPrevious("1.1", "1.1.1");
047: assertLater("1.2", "1.1.1");
048: assertLater("1.2", "1.1");
049: }
050:
051: public void testPlus() {
052: assertNotIncludes("1+", "0");
053: assertIncludes("1+", "1");
054: assertIncludes("1+", "2");
055: assertNotIncludes("1.1+", "1.0");
056: assertIncludes("1.1+", "1.1");
057: assertIncludes("1.1+", "1.10");
058: assertIncludes("1.1+", "1.2");
059: assertNotIncludes("1.1+", "2");
060: assertNotIncludes("1.1.2+", "1.1.1");
061: assertIncludes("1.1.2+", "1.1.2");
062: assertIncludes("1.1.2+", "1.1.13");
063: assertNotIncludes("1.1.2+", "1.2");
064: }
065:
066: public void testStar() {
067: assertIncludes("1.1.*", "1.1.0");
068: assertIncludes("1.*", "1.1");
069: assertIncludes("*", "1");
070: assertIncludes("*", "1.2");
071: assertIncludes("*", "1.2.3");
072: }
073:
074: protected void assertIncludes(String first, String second) {
075: Version firstVersion = Version.getInstance(first);
076: Version secondVersion = Version.getInstance(second);
077:
078: assertTrue(first + " does not include " + second, firstVersion
079: .includes(secondVersion));
080: }
081:
082: protected void assertLater(String first, String second) {
083: Version firstVersion = Version.getInstance(first);
084:
085: assertTrue(first + " is not later than " + second, firstVersion
086: .isLaterVersionThan(second.toString()));
087: }
088:
089: protected void assertNotIncludes(String first, String second) {
090: Version firstVersion = Version.getInstance(first);
091: Version secondVersion = Version.getInstance(second);
092:
093: assertFalse(first + " includes " + second, firstVersion
094: .includes(secondVersion));
095: }
096:
097: protected void assertPrevious(String first, String second) {
098: Version firstVersion = Version.getInstance(first);
099:
100: assertTrue(first + " is not previous than " + second,
101: firstVersion.isPreviousVersionThan(second));
102: }
103:
104: }
|