incubator-depot-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nickcha...@apache.org
Subject svn commit: rev 36597 - in incubator/depot/trunk/version/src/test/java/org/apache/depot/version: . impl
Date Thu, 19 Aug 2004 08:05:28 GMT
Author: nickchalko
Date: Thu Aug 19 01:05:24 2004
New Revision: 36597

Modified:
   incubator/depot/trunk/version/src/test/java/org/apache/depot/version/VersionTestCase.java
   incubator/depot/trunk/version/src/test/java/org/apache/depot/version/impl/ApacheVersionTest.java
Log:
More tests.

Modified: incubator/depot/trunk/version/src/test/java/org/apache/depot/version/VersionTestCase.java
==============================================================================
--- incubator/depot/trunk/version/src/test/java/org/apache/depot/version/VersionTestCase.java
(original)
+++ incubator/depot/trunk/version/src/test/java/org/apache/depot/version/VersionTestCase.java
Thu Aug 19 01:05:24 2004
@@ -8,12 +8,11 @@
 
 import java.util.Comparator;
 
-import org.apache.depot.version.impl.data.VersionData;
+import junit.framework.TestCase;
+
 import org.apache.depot.version.specification.VersionSpecification;
 import org.apache.depot.version.specification.formatting.VersionFormatException;
 
-import junit.framework.TestCase;
-
 /**
  * @author Nick
  * 
@@ -21,6 +20,8 @@
  * Preferences - Java - Code Style - Code Templates
  */
 public class VersionTestCase extends TestCase {
+	private static final VersionManager MANAGER = VersionManager.getManager();
+
 	private final VersionSpecification specification;
 
 	private Version base;
@@ -50,37 +51,20 @@
 		base = null;
 	}
 
-	public void testCreation() {
+	public void testCore() {
 		assertNotNull("Version for " + getBaseVersionString()
 				+ " should not be null", base);
-	}
-
-	public void testEquality() {
 		assertSymetricNotEquals(base, Version.UNKNOWN);
 
-		assertSymetricEquals(base, same);
-		assertSymetricNotEquals(nonCompatible, base);
-		assertSymetricNotEquals(compatible, base);
-	}
-
-	public void testComparable() {
-		assertSymetricComparableEquals(base, same);
-		assertSymetricCompare(base, nonCompatible);
-	}
-
-	public void testComparator() {
-		Version v1 = base;
-		Version v2 = same;
-		assertSymetricComparatorEquals(base, same);
-		Version less = base;
-		Version more = nonCompatible;
-		assertSymetricComparator(less, more);
+		assertVersionReleation(base, same, true, 0);
+		assertVersionReleation(compatible, base, true, 1);
+		assertVersionReleation(nonCompatible, base, false, 1);
 
 	}
 
 	public void testIncrement() throws VersionException {
-		test5increments(base, getNonCompatibleIncrement(), false);
-		test5increments(base, getCompatibleIncrement(), true);
+		assert5Increments(base, getNonCompatibleIncrement(), false);
+		assert5Increments(base, getCompatibleIncrement(), true);
 
 	}
 
@@ -90,10 +74,10 @@
 	 * @param compatible
 	 * @throws VersionException
 	 */
-	public void test5increments(Version start, final String incrementLevel,
+	public void assert5Increments(Version start, final String incrementLevel,
 			final boolean compatible) throws VersionException {
 
-		testIncrement(start, incrementLevel, compatible, 5);
+		assertIncrementing(start, incrementLevel, compatible, 5);
 	}
 
 	/**
@@ -103,7 +87,7 @@
 	 * @param iterations
 	 * @throws VersionException
 	 */
-	public void testIncrement(Version start, final String incrementLevel,
+	public void assertIncrementing(Version start, final String incrementLevel,
 			final boolean compatible, int iterations) throws VersionException {
 		Version last = start;
 		for (int i = 0; i < iterations; i++) {
@@ -118,6 +102,30 @@
 	 * Assert the ordering, and compatablity of two versions. Tests eqauls,
 	 * Comparable,Comparator and isCompatible.
 	 * 
+	 * @param versionString1
+	 *            a Version String
+	 * @param versionString2
+	 *            a Version String
+	 * @param compatible
+	 * 
+	 * @param compare
+	 *            -1 if version1 less than version2, 0 if equals and 1 if
+	 *            greater than
+	 * @throws VersionFormatException
+	 */
+	public void assertVersionReleation(String versionString1,
+			String versionString2, final boolean compatible, int compare)
+			throws VersionFormatException {
+		Version v1 = createVersion(versionString1);
+		Version v2 = createVersion(versionString2);
+		assertVersionReleation(v1, v2, compatible, compare);
+
+	}
+
+	/**
+	 * Assert the ordering, and compatablity of two versions. Tests eqauls,
+	 * Comparable,Comparator and isCompatible.
+	 * 
 	 * @param v1
 	 *            a Version
 	 * @param v2
@@ -235,8 +243,7 @@
 	 */
 	private Version createVersion(String versionString)
 			throws VersionFormatException {
-		return VersionManager.getManager().createVersion(specification,
-				versionString);
+		return MANAGER.createVersion(specification, versionString);
 	}
 
 	/**
@@ -282,6 +289,31 @@
 	 */
 	private String getBaseVersionString() {
 		return "1";
+	}
+
+	/**
+	 * @param inOrder
+	 * @param compatible
+	 * @throws VersionFormatException
+	 */
+	public void assertVersionInOrder(String[] inOrder, boolean compatible) throws VersionFormatException
{
+		for (int i = 1; i < inOrder.length; i++) {
+			for (int j = 0; j < i; j++) {
+				assertVersionReleation(inOrder[j], inOrder[i], compatible, -1);
+			}
+		}
+	}
+
+	/**
+	 * @param same
+	 * @throws VersionFormatException
+	 */
+	public void assertAllEqual(String[] same) throws VersionFormatException {
+		for (int i = 1; i < same.length; i++) {
+			for (int j = 0; j < i; j++) {
+				assertVersionReleation(same[j], same[i], true, 0);
+			}
+		}
 	}
 
 }

Modified: incubator/depot/trunk/version/src/test/java/org/apache/depot/version/impl/ApacheVersionTest.java
==============================================================================
--- incubator/depot/trunk/version/src/test/java/org/apache/depot/version/impl/ApacheVersionTest.java
(original)
+++ incubator/depot/trunk/version/src/test/java/org/apache/depot/version/impl/ApacheVersionTest.java
Thu Aug 19 01:05:24 2004
@@ -7,6 +7,7 @@
 import org.apache.depot.version.VersionException;
 import org.apache.depot.version.VersionTestCase;
 import org.apache.depot.version.impl.data.ReleaseLevel;
+import org.apache.depot.version.specification.formatting.VersionFormatException;
 
 /**
  * @author <a href="http://nick.chalko.com">Nick Chalko </a>
@@ -20,7 +21,7 @@
 	 */
 	public ApacheVersionTest() {
 		super(ApacheVersion.UNKNOWN.getSpecification());
-		
+
 	}
 
 	/*
@@ -33,6 +34,18 @@
 		assertApacheVersion("1.2.1-dev", 1, 2, 1, ReleaseLevel.DEVELOPMENT);
 		assertApacheVersion("1.2", 1, 2, -1, ReleaseLevel.DEFAULT);
 		assertApacheVersion("1.2.99-b", 1, 2, 99, ReleaseLevel.BETA);
+	}
+
+	public void testEquals() throws VersionFormatException {
+		assertAllEqual(new String[] { "1","1", "1.0", "1.0.0","1.0-final" });
+	}
+
+	public void testNonCompatible() throws VersionFormatException {
+		assertVersionInOrder(new String[] { "1", "2" }, false);
+	}
+
+	public void testCompatible() throws VersionFormatException {
+		assertVersionInOrder(new String[] { "1.1-a7","1.1-beta1","1.1-rc2","1.1.0", "1.1.2" },
true);
 	}
 
 	/**

Mime
View raw message