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 37362 - in incubator/depot/trunk/version/src: java/org/apache/depot/version/impl/gump test/java/org/apache/depot/version test/java/org/apache/depot/version/impl test/java/org/apache/depot/version/impl/gump
Date Thu, 02 Sep 2004 06:11:22 GMT
Author: nickchalko
Date: Wed Sep  1 23:11:22 2004
New Revision: 37362

Modified:
   incubator/depot/trunk/version/src/java/org/apache/depot/version/impl/gump/GumpVersion.java
   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
   incubator/depot/trunk/version/src/test/java/org/apache/depot/version/impl/gump/GumpVersionTest.java
Log:
Worked out a lot better test for compatibiltiy.

Need to make sure we have the definition of isCompatible right.

Modified: incubator/depot/trunk/version/src/java/org/apache/depot/version/impl/gump/GumpVersion.java
==============================================================================
--- incubator/depot/trunk/version/src/java/org/apache/depot/version/impl/gump/GumpVersion.java
(original)
+++ incubator/depot/trunk/version/src/java/org/apache/depot/version/impl/gump/GumpVersion.java
Wed Sep  1 23:11:22 2004
@@ -22,12 +22,21 @@
 import org.apache.depot.version.specification.VersionSpecification;
 
 /**
- * Gump version has the general format of gump-yyyyMMDD
- * Gump versions are NEVER compatible.
- * WARNING: gump version are UNTRUSTED builds.
+ * Gump version has the general format of gump-yyyyMMDD Gump versions are NEVER
+ * compatible. WARNING: gump version are UNTRUSTED builds.
  *  
  */
 public class GumpVersion implements Version {
+	public final static Comparator GUMP_COMPARATOR = new Comparator() {
+
+		public int compare(Object o1, Object o2) {
+			GumpVersion left = (GumpVersion) o1;
+			GumpVersion right = (GumpVersion) o2;
+			final long diff = left.buildNumber - right.buildNumber;
+			return (int) Math.min(Integer.MAX_VALUE, Math.max(
+					Integer.MIN_VALUE, diff));
+		}
+	};
 
 	public final static VersionSpecification SPECIFICATION = new GumpVersionSpecification();
 
@@ -50,7 +59,7 @@
 	 */
 	public boolean isCompatible(Version version) {
 
-		return false;
+		return equals(version);
 	}
 
 	/*
@@ -59,7 +68,7 @@
 	 * @see org.apache.depot.version.Version#increment(java.lang.String)
 	 */
 	public Version increment(String level) throws VersionException {
-		// TODO Auto-generated method stub
+
 		return new GumpVersion(buildNumber + 1);
 	}
 
@@ -69,8 +78,8 @@
 	 * @see org.apache.depot.version.Version#getComparator()
 	 */
 	public Comparator getComparator() {
-		// TODO Auto-generated method stub
-		return null;
+
+		return GUMP_COMPARATOR;
 	}
 
 	/*
@@ -79,8 +88,8 @@
 	 * @see java.lang.Comparable#compareTo(java.lang.Object)
 	 */
 	public int compareTo(Object o) {
-		// TODO Auto-generated method stub
-		return 0;
+
+		return GUMP_COMPARATOR.compare(this, o);
 	}
 
 	/**
@@ -98,8 +107,14 @@
 	 * @see java.lang.Object#equals(java.lang.Object)
 	 */
 	public boolean equals(Object obj) {
-		// TODO Auto-generated method stub
-		return super.equals(obj);
+		if (this == obj) {
+			return true;
+		}
+		if (!(obj instanceof GumpVersion)) {
+			return false;
+		}
+		GumpVersion other = (GumpVersion) obj;
+		return buildNumber == other.buildNumber;
 	}
 
 	/*

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
Wed Sep  1 23:11:22 2004
@@ -15,7 +15,10 @@
  */
 package org.apache.depot.version;
 
+import java.util.Arrays;
 import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
 
 import junit.framework.TestCase;
 
@@ -23,9 +26,31 @@
 import org.apache.depot.version.specification.formatting.VersionFormatException;
 
 /**
- * 
+ *  
  */
 public class VersionTestCase extends TestCase {
+	private final class Compatibility {
+
+		private String name;
+
+		/**
+		 * @param string
+		 */
+		public Compatibility(String string) {
+			name = string;
+		}
+
+		public String toString() {
+			return name;
+		}
+	};
+
+	public final Compatibility INCOMPATIBLE = new Compatibility("Incompatible");
+
+	public final Compatibility FORWARD = new Compatibility("Forward");
+
+	public final Compatibility BACKWARDS = new Compatibility("Backwards");
+
 	private static final VersionManager MANAGER = VersionManager.getManager();
 
 	private final VersionSpecification specification;
@@ -34,10 +59,6 @@
 
 	private Version same;
 
-	private Version nonCompatible;
-
-	private Version compatible;
-
 	/**
 	 * @param specification
 	 */
@@ -49,8 +70,7 @@
 	public void setUp() throws VersionException {
 		base = createVersion(getBaseVersionString());
 		same = createVersion(getBaseVersionString());
-		nonCompatible = base.increment(getNonCompatibleIncrement());
-		compatible = base.increment(getCompatibleIncrement());
+
 	}
 
 	public void tearDown() {
@@ -62,16 +82,23 @@
 				+ " should not be null", base);
 		assertSymetricNotEquals(base, Version.UNKNOWN);
 
-		assertVersionReleation(base, same, true, 0);
-		assertVersionReleation(compatible, base, true, 1);
-		assertVersionReleation(nonCompatible, base, false, 1);
+		assertVersionReleation(base, same, FORWARD, 0);
 
 	}
 
 	public void testIncrement() throws VersionException {
-		assert5Increments(base, getNonCompatibleIncrement(), false);
-		assert5Increments(base, getCompatibleIncrement(), true);
+		assert5Increments(base, getNonCompatibleIncrementList(), INCOMPATIBLE);
+		assert5Increments(base, getForwardCompatibleIncrementList(), FORWARD);
+		assert5Increments(base, getBackwardCompatibleIncrementList(), BACKWARDS);
+
+	}
+
+	/**
+	 * @return
+	 */
+	public List getBackwardCompatibleIncrementList() {
 
+		return Arrays.asList(new String[] { "minor" });
 	}
 
 	/**
@@ -80,10 +107,28 @@
 	 * @param compatible
 	 * @throws VersionException
 	 */
-	public void assert5Increments(Version start, final String incrementLevel,
-			final boolean compatible) throws VersionException {
+	public void assert5Increments(Version start, final List list,
+			Compatibility compatibility) throws VersionException {
+
+		assertIncrementing(start, list, compatibility, 5);
+	}
+
+	/**
+	 * @param start
+	 * @param list
+	 * @param compatibility
+	 * @param i
+	 * @throws VersionException
+	 */
+	private void assertIncrementing(Version start, List list,
+			Compatibility compatibility, int count) throws VersionException {
+
+		for (Iterator i = list.iterator(); i.hasNext();) {
+			String incrementLevel = (String) i.next();
+			assertIncrementing(start, incrementLevel, compatibility, count);
+
+		}
 
-		assertIncrementing(start, incrementLevel, compatible, 5);
 	}
 
 	/**
@@ -94,12 +139,13 @@
 	 * @throws VersionException
 	 */
 	public void assertIncrementing(Version start, final String incrementLevel,
-			final boolean compatible, int iterations) throws VersionException {
+			Compatibility compatability, int iterations)
+			throws VersionException {
 		Version last = start;
 		for (int i = 0; i < iterations; i++) {
 			Version next = last.increment(incrementLevel);
-			assertVersionReleation(start, next, compatible, -1);
-			assertVersionReleation(last, next, compatible, -1);
+			assertVersionReleation(start, next, compatability, -1);
+			assertVersionReleation(last, next, compatability, -1);
 
 		}
 	}
@@ -120,11 +166,11 @@
 	 * @throws VersionFormatException
 	 */
 	public void assertVersionReleation(String versionString1,
-			String versionString2, final boolean compatible, int compare)
+			String versionString2, Compatibility compatibility, int compare)
 			throws VersionFormatException {
 		Version v1 = createVersion(versionString1);
 		Version v2 = createVersion(versionString2);
-		assertVersionReleation(v1, v2, compatible, compare);
+		assertVersionReleation(v1, v2, compatibility, compare);
 
 	}
 
@@ -140,11 +186,11 @@
 	 * @param
 	 */
 	public void assertVersionReleation(Version v1, Version v2,
-			final boolean compatible, int compare) {
+			final Compatibility compatibility, int compare) {
 
-		if (compare == 0 && !compatible) {
+		if (compare == 0 && compatibility != FORWARD) {
 			throw new IllegalArgumentException(
-					"If a version is equal it must be compatable.  The test setup is illegal");
+					"If a version is equal it must be forward compatable.  The test setup is illegal");
 		}
 		if (compare == 0) {
 			assertSymetricEquals(v1, v2);
@@ -159,21 +205,44 @@
 			}
 			assertSymetricLess(less, more);
 		}
-		// FIXME compatability is not always symetric.
-		assertSymetricCompatability(v1, v2, compatible);
+
+		assertCompatability(v1, v2, compatibility);
+	}
+
+	/**
+	 * @param less
+	 * @param more
+	 * @param expected
+	 */
+	private void assertCompatability(Version less, Version more,
+			final Compatibility compatibility) {
+		if (compatibility == INCOMPATIBLE) {
+			assertCompatability(less, more, false);
+			assertCompatability(more, less, false);
+		} else if (compatibility == BACKWARDS) {
+			assertCompatability(less, more, false);
+			assertCompatability(more, less, true);
+		} else if (compatibility == FORWARD) {
+			assertCompatability(less, more, true);
+			assertCompatability(more, less, true);
+		} else {
+			throw new IllegalArgumentException("Uknown COMPATIBILITY "
+					+ compatibility);
+		}
+
 	}
 
 	/**
+	 * v1 is compatible v2
+	 * 
 	 * @param v1
 	 * @param v2
 	 * @param expected
 	 */
-	private void assertSymetricCompatability(Version v1, Version v2,
-			final boolean expected) {
+	private void assertCompatability(Version v1, Version v2, boolean expected) {
 		assertEquals(v1 + " compatbile with " + v2, expected, v1
 				.isCompatible(v2));
-		assertEquals(v2 + " compatbile with " + v1, expected, v2
-				.isCompatible(v1));
+
 	}
 
 	/**
@@ -256,15 +325,15 @@
 	/**
 	 * @return
 	 */
-	private String getNonCompatibleIncrement() {
-		return "major";
+	private List getNonCompatibleIncrementList() {
+		return Arrays.asList(new String[] { "major" });
 	}
 
 	/**
 	 * @return
 	 */
-	private String getCompatibleIncrement() {
-		return "point";
+	public List getForwardCompatibleIncrementList() {
+		return Arrays.asList(new String[] { "point" });
 	}
 
 	/**
@@ -303,10 +372,12 @@
 	 * @param compatible
 	 * @throws VersionFormatException
 	 */
-	public void assertVersionInOrder(String[] inOrder, boolean compatible) throws VersionFormatException
{
+	public void assertVersionInOrder(String[] inOrder,
+			Compatibility compatability) throws VersionFormatException {
 		for (int i = 1; i < inOrder.length; i++) {
 			for (int j = 0; j < i; j++) {
-				assertVersionReleation(inOrder[j], inOrder[i], compatible, -1);
+				assertVersionReleation(inOrder[j], inOrder[i], compatability,
+						-1);
 			}
 		}
 	}
@@ -318,7 +389,7 @@
 	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);
+				assertVersionReleation(same[j], same[i], FORWARD, 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
Wed Sep  1 23:11:22 2004
@@ -55,7 +55,7 @@
 	}
 
 	public void testNonCompatible() throws VersionFormatException {
-		assertVersionInOrder(new String[] { "1", "2" }, false);
+		assertVersionInOrder(new String[] { "1", "2" }, INCOMPATIBLE);
 	}
 
 	// :TODO:
@@ -63,7 +63,7 @@
 	// :TODO:
 	// "1.1" is 1.1 release, that is not compatible with 1.1 < release
 	public void testCompatible() throws VersionFormatException {
-		assertVersionInOrder(new String[] { "1.1-a7","1.1-beta1","1.1-rc2"}, true);
+		assertVersionInOrder(new String[] { "1.1-a7","1.1-beta1","1.1-rc2"}, FORWARD);
 	}
 
 	/**

Modified: incubator/depot/trunk/version/src/test/java/org/apache/depot/version/impl/gump/GumpVersionTest.java
==============================================================================
--- incubator/depot/trunk/version/src/test/java/org/apache/depot/version/impl/gump/GumpVersionTest.java
(original)
+++ incubator/depot/trunk/version/src/test/java/org/apache/depot/version/impl/gump/GumpVersionTest.java
Wed Sep  1 23:11:22 2004
@@ -16,7 +16,9 @@
 package org.apache.depot.version.impl.gump;
 
 import java.text.SimpleDateFormat;
+import java.util.Collections;
 import java.util.Date;
+import java.util.List;
 
 import org.apache.depot.version.VersionTestCase;
 import org.apache.depot.version.specification.formatting.VersionFormatException;
@@ -38,14 +40,14 @@
 		baseVersionString = "gump-" + format.format(now);
 	}
 
-
 	public void testEquals() throws VersionFormatException {
 		assertAllEqual(new String[] { "1", "gump-1", "GUMP-1" });
 	}
 
 	public void testNonCompatible() throws VersionFormatException {
 		assertVersionInOrder(
-				new String[] { "gump-1", "gump-2", "3", "GUMP-4" }, false);
+				new String[] { "gump-1", "gump-2", "3", "GUMP-4" },
+				INCOMPATIBLE);
 	}
 
 	/*
@@ -53,5 +55,23 @@
 	 */
 	protected String getBaseVersionString() {
 		return baseVersionString;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.depot.version.VersionTestCase#getBackwardCompatibleIncrementList()
+	 */
+	public List getBackwardCompatibleIncrementList() {
+		return Collections.EMPTY_LIST;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.depot.version.VersionTestCase#getForwardCompatibleIncrementList()
+	 */
+	public List getForwardCompatibleIncrementList() {
+		return Collections.EMPTY_LIST;
 	}
 }

Mime
View raw message