From 407c29c3e07e92655d3e74bea8be4c4d3644686f Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Tue, 19 Jul 2005 23:27:41 +0000 Subject: [PATCH] PR: MNG-505 test multiple ranges on each side git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@219808 13f79535-47bb-0310-9956-ffa450edef68 --- .../artifact/versioning/VersionRange.java | 2 +- .../artifact/versioning/VersionRangeTest.java | 174 +++++++++++++++++- 2 files changed, 174 insertions(+), 2 deletions(-) diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java b/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java index 95ef298f71..bdf07ee5fc 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java @@ -219,7 +219,7 @@ public class VersionRange private List intersection( List r1, List r2 ) { - List restrictions = new ArrayList( Math.min( r1.size(), r2.size() ) ); + List restrictions = new ArrayList( r1.size() + r2.size() ); Iterator i1 = r1.iterator(); Iterator i2 = r2.iterator(); Restriction res1 = (Restriction) i1.next(); diff --git a/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/VersionRangeTest.java b/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/VersionRangeTest.java index 43725eb8cd..17b11ff357 100644 --- a/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/VersionRangeTest.java +++ b/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/VersionRangeTest.java @@ -411,7 +411,179 @@ public class VersionRangeTest restrictions = mergedRange.getRestrictions(); assertEquals( CHECK_NUM_RESTRICTIONS, 0, restrictions.size() ); - // TODO: multiple on one side, multiple on both sides, boundaries + range1 = VersionRange.createFromVersionSpec( "[1.0,1.2],[1.3,1.5]" ); + range2 = VersionRange.createFromVersionSpec( "[1.1]" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + restriction = (Restriction) restrictions.get( 0 ); + assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.1", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + range1 = VersionRange.createFromVersionSpec( "[1.0,1.2],[1.3,1.5]" ); + range2 = VersionRange.createFromVersionSpec( "[1.4]" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + restriction = (Restriction) restrictions.get( 0 ); + assertEquals( CHECK_LOWER_BOUND, "1.4", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.4", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + range1 = VersionRange.createFromVersionSpec( "[1.0,1.2],[1.3,1.5]" ); + range2 = VersionRange.createFromVersionSpec( "[1.1,1.4]" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 2, restrictions.size() ); + restriction = (Restriction) restrictions.get( 0 ); + assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.2", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + restriction = (Restriction) restrictions.get( 1 ); + assertEquals( CHECK_LOWER_BOUND, "1.3", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.4", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + range1 = VersionRange.createFromVersionSpec( "[1.0,1.2),(1.3,1.5]" ); + range2 = VersionRange.createFromVersionSpec( "[1.1,1.4]" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 2, restrictions.size() ); + restriction = (Restriction) restrictions.get( 0 ); + assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.2", restriction.getUpperBound().toString() ); + assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + restriction = (Restriction) restrictions.get( 1 ); + assertEquals( CHECK_LOWER_BOUND, "1.3", restriction.getLowerBound().toString() ); + assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.4", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + range1 = VersionRange.createFromVersionSpec( "[1.0,1.2],[1.3,1.5]" ); + range2 = VersionRange.createFromVersionSpec( "(1.1,1.4)" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 2, restrictions.size() ); + restriction = (Restriction) restrictions.get( 0 ); + assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() ); + assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.2", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + restriction = (Restriction) restrictions.get( 1 ); + assertEquals( CHECK_LOWER_BOUND, "1.3", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.4", restriction.getUpperBound().toString() ); + assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + range1 = VersionRange.createFromVersionSpec( "[1.0,1.2),(1.3,1.5]" ); + range2 = VersionRange.createFromVersionSpec( "(1.1,1.4)" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 2, restrictions.size() ); + restriction = (Restriction) restrictions.get( 0 ); + assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() ); + assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.2", restriction.getUpperBound().toString() ); + assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + restriction = (Restriction) restrictions.get( 1 ); + assertEquals( CHECK_LOWER_BOUND, "1.3", restriction.getLowerBound().toString() ); + assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.4", restriction.getUpperBound().toString() ); + assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + range1 = VersionRange.createFromVersionSpec( "(,1.1),(1.4,)" ); + range2 = VersionRange.createFromVersionSpec( "[1.1,1.4]" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 0, restrictions.size() ); + + range1 = VersionRange.createFromVersionSpec( "(,1.1],[1.4,)" ); + range2 = VersionRange.createFromVersionSpec( "(1.1,1.4)" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 0, restrictions.size() ); + + range1 = VersionRange.createFromVersionSpec( "[,1.1],[1.4,]" ); + range2 = VersionRange.createFromVersionSpec( "[1.2,1.3]" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 0, restrictions.size() ); + + range1 = VersionRange.createFromVersionSpec( "[1.0,1.2],[1.3,1.5]" ); + range2 = VersionRange.createFromVersionSpec( "[1.1,1.4],[1.6,]" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 2, restrictions.size() ); + restriction = (Restriction) restrictions.get( 0 ); + assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.2", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + restriction = (Restriction) restrictions.get( 1 ); + assertEquals( CHECK_LOWER_BOUND, "1.3", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.4", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + range1 = VersionRange.createFromVersionSpec( "[1.0,1.2],[1.3,1.5]" ); + range2 = VersionRange.createFromVersionSpec( "[1.1,1.4],[1.5,]" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 3, restrictions.size() ); + restriction = (Restriction) restrictions.get( 0 ); + assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.2", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + restriction = (Restriction) restrictions.get( 1 ); + assertEquals( CHECK_LOWER_BOUND, "1.3", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.4", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + restriction = (Restriction) restrictions.get( 2 ); + assertEquals( CHECK_LOWER_BOUND, "1.5", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.5", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + range1 = VersionRange.createFromVersionSpec( "[1.0,1.2],[1.3,1.7]" ); + range2 = VersionRange.createFromVersionSpec( "[1.1,1.4],[1.5,1.6]" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 3, restrictions.size() ); + restriction = (Restriction) restrictions.get( 0 ); + assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.2", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + restriction = (Restriction) restrictions.get( 1 ); + assertEquals( CHECK_LOWER_BOUND, "1.3", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.4", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + restriction = (Restriction) restrictions.get( 2 ); + assertEquals( CHECK_LOWER_BOUND, "1.5", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.6", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); } private void checkInvalidRange( String version )