- right )
+ {
+ return left.hasNext()
+ ? integerItemOrZero( left.next() ).compareTo( ZERO )
+ : -right.next().compareTo( ZERO );
+ }
+
+ private static Item integerItemOrZero( Item item )
{
- int r;
- return !( comparisonLimit > 0 && right.hasNext() )
- ? 1
- : ( r = -( right.next().compareTo( left.hasNext() ? left.next() : ZERO ) ) ) != 0
- ? r
- : compareTo( left, right, comparisonLimit - 1 );
+ return item instanceof IntegerItem
+ ? item
+ : ZERO;
}
}
}
diff --git a/src/main/java/org/codehaus/mojo/versions/ordering/VersionComparator.java b/src/main/java/org/codehaus/mojo/versions/ordering/VersionComparator.java
index 50edfe7e89..91a40848c8 100644
--- a/src/main/java/org/codehaus/mojo/versions/ordering/VersionComparator.java
+++ b/src/main/java/org/codehaus/mojo/versions/ordering/VersionComparator.java
@@ -44,17 +44,6 @@ public interface VersionComparator
*/
int getSegmentCount( ArtifactVersion artifactVersion );
- /**
- * Increment the specified segment of the supplied version.
- *
- * @param artifactVersion The artifact version to increment.
- * @param segment The segment number to increment.
- * @return An artifact version with the specified segment incremented.
- * @since 1.0-beta-1
- * @throws InvalidSegmentException if {@code segment} ∉ [0, segmentCount)
- */
- ArtifactVersion incrementSegment( ArtifactVersion artifactVersion, Segment segment ) throws InvalidSegmentException;
-
/**
*
Returns a {@linkplain Restriction} object for computing version upgrades
* with the given segment allowing updates, with all more major segments locked in place.
@@ -73,10 +62,11 @@ public interface VersionComparator
default Restriction restrictionFor( ArtifactVersion currentVersion, Optional scope )
throws InvalidSegmentException
{
- ArtifactVersion nextVersion = scope.isPresent() && scope.get().isMajorTo( SUBINCREMENTAL )
- ? incrementSegment( currentVersion, scope.get() )
- : currentVersion;
- return new Restriction( nextVersion, nextVersion != currentVersion, scope.filter( MAJOR::isMajorTo )
+ ArtifactVersion nextVersion = scope.filter( s -> s.isMajorTo( SUBINCREMENTAL ) )
+ .map( s -> (ArtifactVersion)
+ new BoundArtifactVersion( currentVersion, Segment.of( s.value() + 1 ) ) )
+ .orElse( currentVersion );
+ return new Restriction( nextVersion, false, scope.filter( MAJOR::isMajorTo )
.map( s -> (ArtifactVersion) new BoundArtifactVersion( currentVersion, s ) ).orElse( null ),
false );
}
diff --git a/src/test/java/org/codehaus/mojo/versions/DependencyUpdatesReportMojoTest.java b/src/test/java/org/codehaus/mojo/versions/DependencyUpdatesReportMojoTest.java
index 3b31c751f4..37850e7dc9 100644
--- a/src/test/java/org/codehaus/mojo/versions/DependencyUpdatesReportMojoTest.java
+++ b/src/test/java/org/codehaus/mojo/versions/DependencyUpdatesReportMojoTest.java
@@ -343,4 +343,28 @@ public void testWrongReportBounds() throws IOException, MavenReportException
matchesPattern( ".*report.overview.numNewerMajorAvailable | \\s*1 | .*" ),
matchesPattern( ".*report.overview.numUpToDate | \\s*0 | .*" ) ) );
}
+
+ @Test
+ public void testIt001Overview() throws IOException, MavenReportException
+ {
+ OutputStream os = new ByteArrayOutputStream();
+ SinkFactory sinkFactory = new Xhtml5SinkFactory();
+ new TestDependencyUpdatesReportMojo()
+ .withOnlyUpgradable( true )
+ .withDependencies(
+ dependencyOf( "test-artifact", "1.1" ) )
+ .withArtifactMetadataSource( mockArtifactMetadataSource( new HashMap()
+ {{
+ put( "test-artifact", new String[] { "1.1.0-2", "1.1", "1.1.1", "1.1.1-2",
+ "1.1.2", "1.1.3", "1.2", "1.2.1", "1.2.2", "1.3", "2.0", "2.1", "3.0"} );
+ }} ) )
+ .generate( sinkFactory.createSink( os ), sinkFactory, Locale.getDefault() );
+
+ String output = os.toString()
+ .replaceAll( "<[^>]+>", " " )
+ .replaceAll( "&[^;]+;", " " )
+ .replaceAll( "\\s+", " " );
+ assertThat( "Did not generate summary correctly", output,
+ containsString( "groupA test-artifact 1.1 compile pom default 1.1.0-2 1.1.3 1.3 3.0" ) );
+ }
}
diff --git a/src/test/java/org/codehaus/mojo/versions/api/ArtifactVersionsTest.java b/src/test/java/org/codehaus/mojo/versions/api/ArtifactVersionsTest.java
index 05de76fc17..1f4b3633e1 100644
--- a/src/test/java/org/codehaus/mojo/versions/api/ArtifactVersionsTest.java
+++ b/src/test/java/org/codehaus/mojo/versions/api/ArtifactVersionsTest.java
@@ -26,15 +26,16 @@
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.artifact.versioning.VersionRange;
+import org.codehaus.mojo.versions.ordering.InvalidSegmentException;
import org.codehaus.mojo.versions.ordering.MavenVersionComparator;
import org.codehaus.mojo.versions.ordering.MercuryVersionComparator;
-import org.hamcrest.Matchers;
import org.junit.Test;
import static java.util.Optional.of;
import static org.codehaus.mojo.versions.api.Segment.INCREMENTAL;
import static org.codehaus.mojo.versions.api.Segment.SUBINCREMENTAL;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.arrayContaining;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
@@ -56,14 +57,14 @@ public void test4DigitVersions() throws Exception
assertEquals( "artifact", instance.getArtifactId() );
assertEquals( "group", instance.getGroupId() );
assertThat( instance.getVersions(),
- Matchers.arrayContaining( versions( "1.0.0.1", "1.0.0.2", "1.1.1", "2.100.0.1", "2.121.2.1",
+ arrayContaining( versions( "1.0.0.1", "1.0.0.2", "1.1.1", "2.100.0.1", "2.121.2.1",
"3.1.0.1" ) ) );
assertThat( instance.getVersions( new DefaultArtifactVersion( "1.1" ), null ),
- Matchers.arrayContaining( versions( "1.1.1", "2.100.0.1", "2.121.2.1", "3.1.0.1" ) ) );
+ arrayContaining( versions( "1.1.1", "2.100.0.1", "2.121.2.1", "3.1.0.1" ) ) );
assertThat( instance.getVersions( new DefaultArtifactVersion( "1.0.0.2" ), null ),
//Matchers.arrayContaining(versions("1.1.1", "2.121.2.1", "2.100.0.1", "3.1.0.1")));
- Matchers.arrayContaining( versions( "1.1.1", "2.100.0.1", "2.121.2.1", "3.1.0.1" ) ) );
+ arrayContaining( versions( "1.1.1", "2.100.0.1", "2.121.2.1", "3.1.0.1" ) ) );
assertEquals( new DefaultArtifactVersion( "2.121.2.1" ),
instance.getNewestVersion( new DefaultArtifactVersion( "1.0" ),
@@ -126,4 +127,18 @@ public void testReportLabels()
assertThat( instance.getNewestUpdate( of( SUBINCREMENTAL ) ).toString(), is( "1.1.0-2" ) );
assertThat( instance.getNewestUpdate( of( INCREMENTAL ) ).toString(), is( "1.1.3" ) );
}
+
+ @Test
+ public void testGetNewerVersionsWithSnapshot() throws InvalidSegmentException
+ {
+ ArtifactVersion[] versions = versions( "1.0.0-SNAPSHOT", "1.0.0" );
+ ArtifactVersions instance =
+ new ArtifactVersions( new DefaultArtifact( "default-group", "dummy-api",
+ "1.0.0-SNAPSHOT", "foo", "bar",
+ "jar", null ),
+ Arrays.asList( versions ), new MavenVersionComparator() );
+
+ assertThat( instance.getNewerVersions( "1.0.0-SNAPSHOT", of( SUBINCREMENTAL ), false, false ),
+ arrayContaining( new DefaultArtifactVersion( "1.0.0" ) ) );
+ }
}
diff --git a/src/test/java/org/codehaus/mojo/versions/ordering/BoundArtifactVersionTest.java b/src/test/java/org/codehaus/mojo/versions/ordering/BoundArtifactVersionTest.java
new file mode 100644
index 0000000000..d62e972303
--- /dev/null
+++ b/src/test/java/org/codehaus/mojo/versions/ordering/BoundArtifactVersionTest.java
@@ -0,0 +1,106 @@
+package org.codehaus.mojo.versions.ordering;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.artifact.versioning.ArtifactVersion;
+import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
+import org.codehaus.mojo.versions.api.Segment;
+import org.junit.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.greaterThan;
+import static org.hamcrest.Matchers.lessThan;
+
+/**
+ * Unit tests for {@link BoundArtifactVersion}
+ */
+public class BoundArtifactVersionTest
+{
+ @Test
+ public void testMajorUpperBoundGreaterThanNextMajor()
+ {
+ BoundArtifactVersion bound = new BoundArtifactVersion( new DefaultArtifactVersion( "1.2.3" ),
+ Segment.MAJOR );
+ ArtifactVersion artifactVersion = new DefaultArtifactVersion( "2.0.0" );
+ assertThat( bound.compareTo( artifactVersion ), greaterThan( 0 ) );
+ }
+
+ @Test
+ public void testSubIncrementalUpperBoundGreaterThanNextSubIncremental()
+ {
+ BoundArtifactVersion bound = new BoundArtifactVersion( new DefaultArtifactVersion( "1.2.3-2" ),
+ Segment.SUBINCREMENTAL );
+ ArtifactVersion artifactVersion = new DefaultArtifactVersion( "1.2.3-3" );
+ assertThat( bound.compareTo( artifactVersion ), greaterThan( 0 ) );
+ }
+
+ @Test
+ public void testVersionShorterThanSegment()
+ {
+ BoundArtifactVersion bound = new BoundArtifactVersion( new DefaultArtifactVersion( "1.1" ),
+ Segment.INCREMENTAL );
+ ArtifactVersion artifactVersion = new DefaultArtifactVersion( "1.1.3" );
+ assertThat( bound.compareTo( artifactVersion ), greaterThan( 0 ) );
+ }
+
+ @Test
+ public void testVersionBoundArtifactVersionShorterThanConcreteVersionAndSegment()
+ {
+ BoundArtifactVersion bound = new BoundArtifactVersion( new DefaultArtifactVersion( "1.1" ),
+ Segment.SUBINCREMENTAL );
+ ArtifactVersion artifactVersion = new DefaultArtifactVersion( "1.1.3" );
+ assertThat( bound.compareTo( artifactVersion ), lessThan( 0 ) );
+ }
+
+ @Test
+ public void testVersionSubIncrementalBoundGreaterThanSubIncremental()
+ {
+ BoundArtifactVersion bound = new BoundArtifactVersion( new DefaultArtifactVersion( "1.1" ),
+ Segment.SUBINCREMENTAL );
+ ArtifactVersion artifactVersion = new DefaultArtifactVersion( "1.1.0-2" );
+ assertThat( bound.compareTo( artifactVersion ), greaterThan( 0 ) );
+ }
+
+ @Test
+ public void testVersionSubIncrementalBoundGreaterThanIncremental()
+ {
+ BoundArtifactVersion bound = new BoundArtifactVersion( new DefaultArtifactVersion( "1.1" ),
+ Segment.INCREMENTAL );
+ ArtifactVersion artifactVersion = new DefaultArtifactVersion( "1.1.3" );
+ assertThat( bound.compareTo( artifactVersion ), greaterThan( 0 ) );
+ }
+
+ @Test
+ public void testVersionSubIncrementalBoundGreaterThanMinor()
+ {
+ BoundArtifactVersion bound = new BoundArtifactVersion( new DefaultArtifactVersion( "1.1" ),
+ Segment.MINOR );
+ ArtifactVersion artifactVersion = new DefaultArtifactVersion( "1.3" );
+ assertThat( bound.compareTo( artifactVersion ), greaterThan( 0 ) );
+ }
+
+ @Test
+ public void testSnapshotWithSubIncremental()
+ {
+ BoundArtifactVersion bound = new BoundArtifactVersion( new DefaultArtifactVersion( "1.0.0-SNAPSHOT" ),
+ Segment.MINOR );
+ ArtifactVersion artifactVersion = new DefaultArtifactVersion( "1.0.0" );
+ assertThat( bound.compareTo( artifactVersion ), greaterThan( 0 ) );
+ }
+}
diff --git a/src/test/java/org/codehaus/mojo/versions/ordering/MavenVersionComparatorTest.java b/src/test/java/org/codehaus/mojo/versions/ordering/MavenVersionComparatorTest.java
index 2369712084..452ef34786 100644
--- a/src/test/java/org/codehaus/mojo/versions/ordering/MavenVersionComparatorTest.java
+++ b/src/test/java/org/codehaus/mojo/versions/ordering/MavenVersionComparatorTest.java
@@ -20,88 +20,63 @@
*/
import org.apache.maven.artifact.versioning.ArtifactVersion;
-import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
-import org.codehaus.mojo.versions.api.Segment;
import org.junit.Test;
import static org.codehaus.mojo.versions.api.Segment.INCREMENTAL;
-import static org.codehaus.mojo.versions.api.Segment.MAJOR;
-import static org.codehaus.mojo.versions.api.Segment.MINOR;
import static org.codehaus.mojo.versions.api.Segment.SUBINCREMENTAL;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.lessThan;
import static org.hamcrest.core.Is.is;
-public class MavenVersionComparatorTest
+public class MavenVersionComparatorTest extends VersionComparatorTestBase
{
- private MavenVersionComparator instance = new MavenVersionComparator();
-
- @Test
- public void testSegmentCounting()
- throws Exception
+ public MavenVersionComparatorTest()
{
- assertThat( 3, is( instance.getSegmentCount( new DefaultArtifactVersion( "5" ) ) ) );
- assertThat( 3, is( instance.getSegmentCount( new DefaultArtifactVersion( "5.0" ) ) ) );
- assertThat( 4, is( instance.getSegmentCount( new DefaultArtifactVersion( "5-0" ) ) ) );
- assertThat( 1, is( instance.getSegmentCount( new DefaultArtifactVersion( "5.3.a" ) ) ) );
- assertThat( 1, is( instance.getSegmentCount( new DefaultArtifactVersion( "5.0.a.1.4.5" ) ) ) );
- assertThat( 3, is( instance.getSegmentCount( new DefaultArtifactVersion( "" ) ) ) );
+ super( new MavenVersionComparator() );
}
@Test
- public void testSegmentIncrementing() throws InvalidSegmentException
- {
- assertIncrement( "6-SNAPSHOT", "5", MAJOR );
- assertIncrement( "6.0-SNAPSHOT", "5.0", MAJOR );
- assertIncrement( "5.1-SNAPSHOT", "5.0", MINOR );
- assertIncrement( "5.1.0-SNAPSHOT", "5.0.1", MINOR );
- assertIncrement( "5.alpha.2-SNAPSHOT", "5.alpha.1", MAJOR );
- assertIncrement( "5.alpha-1.2-SNAPSHOT", "5.alpha-1.1", MAJOR );
- assertIncrement( "5.alpha-1.ba-SNAPSHOT", "5.alpha-1.az", MAJOR );
- assertIncrement( "5.alpha-wins.2-SNAPSHOT", "5.alpha-wins.1", MAJOR );
- assertIncrement( "1.0-alpha-3-SNAPSHOT", "1.0-alpha-2-SNAPSHOT", SUBINCREMENTAL );
- assertIncrement( "1.0-alpha-90-SNAPSHOT", "1.0-alpha-9-SNAPSHOT", SUBINCREMENTAL );
- assertIncrement( "1.0-za-SNAPSHOT", "1.0-z-SNAPSHOT", SUBINCREMENTAL );
- assertIncrement( "1.0-z90-SNAPSHOT", "1.0-z9-SNAPSHOT", SUBINCREMENTAL );
- }
-
- private void assertIncrement( String expected, String initial, Segment segment ) throws InvalidSegmentException
+ public void testSegmentCounting()
{
- assertThat( instance.incrementSegment( new DefaultArtifactVersion( initial ), segment ).toString(),
- is( expected ) );
+ assertThat( 3, is( instance.getSegmentCount( version( "5" ) ) ) );
+ assertThat( 3, is( instance.getSegmentCount( version( "5.0" ) ) ) );
+ assertThat( 4, is( instance.getSegmentCount( version( "5-0" ) ) ) );
+ assertThat( 1, is( instance.getSegmentCount( version( "5.3.a" ) ) ) );
+ assertThat( 1, is( instance.getSegmentCount( version( "5.0.a.1.4.5" ) ) ) );
+ assertThat( 3, is( instance.getSegmentCount( version( "" ) ) ) );
}
@Test
public void testUpperBoundaryCustom()
{
- assertThat( instance.compare( new BoundArtifactVersion( new DefaultArtifactVersion( "1.2.3" ),
- INCREMENTAL ), new DefaultArtifactVersion( "1.2.3-ANDRZEJ" ) ), greaterThan( 0 ) );
+ assertThat( instance.compare( new BoundArtifactVersion( version( "1.2.3" ),
+ INCREMENTAL ), version( "1.2.3-ANDRZEJ" ) ), greaterThan( 0 ) );
}
@Test
public void testUpperBoundaryRelease()
{
- assertThat( instance.compare( new BoundArtifactVersion( new DefaultArtifactVersion( "1.1.0" ),
- INCREMENTAL ), new DefaultArtifactVersion( "1.1.0" ) ), greaterThan( 0 ) );
+ assertThat( instance.compare( new BoundArtifactVersion( version( "1.1.0" ),
+ INCREMENTAL ), version( "1.1.0" ) ), greaterThan( 0 ) );
}
@Test
public void testUpperBoundarySnapshot()
{
- assertThat( instance.compare( new BoundArtifactVersion( new DefaultArtifactVersion( "1.1.0" ),
- INCREMENTAL ), new DefaultArtifactVersion( "1.1.0-SNAPSHOT" ) ), greaterThan( 0 ) );
+ assertThat( instance.compare( new BoundArtifactVersion( version( "1.1.0" ),
+ INCREMENTAL ), version( "1.1.0-SNAPSHOT" ) ), greaterThan( 0 ) );
}
@Test
public void testScopeLessThanNumSegmentsUpper()
{
- ArtifactVersion artifactVersion = new BoundArtifactVersion( new DefaultArtifactVersion( "1.1" ),
+ ArtifactVersion artifactVersion = new BoundArtifactVersion( version( "1.1" ),
SUBINCREMENTAL );
- assertThat( artifactVersion.compareTo( new DefaultArtifactVersion( "1.0.1" ) ), greaterThan( 0 ) );
- assertThat( artifactVersion.compareTo( new DefaultArtifactVersion( "1.1-SNAPSHOT" ) ), greaterThan( 0 ) );
- assertThat( artifactVersion.compareTo( new DefaultArtifactVersion( "1.1" ) ), greaterThan( 0 ) );
- assertThat( artifactVersion.compareTo( new DefaultArtifactVersion( "1.1.0-2" ) ), greaterThan( 0 ) );
- assertThat( artifactVersion.compareTo( new DefaultArtifactVersion( "1.1.1-2" ) ), lessThan( 0 ) );
+ assertThat( artifactVersion.compareTo( version( "1.0.1" ) ), greaterThan( 0 ) );
+ assertThat( artifactVersion.compareTo( version( "1.1-SNAPSHOT" ) ), greaterThan( 0 ) );
+ assertThat( artifactVersion.compareTo( version( "1.1" ) ), greaterThan( 0 ) );
+ assertThat( artifactVersion.compareTo( version( "1.1.0-2" ) ), greaterThan( 0 ) );
+ assertThat( artifactVersion.compareTo( version( "1.1.1-2" ) ), lessThan( 0 ) );
}
}
diff --git a/src/test/java/org/codehaus/mojo/versions/ordering/MercuryVersionComparatorTest.java b/src/test/java/org/codehaus/mojo/versions/ordering/MercuryVersionComparatorTest.java
index 52d2b6553d..9af7bbc4c6 100644
--- a/src/test/java/org/codehaus/mojo/versions/ordering/MercuryVersionComparatorTest.java
+++ b/src/test/java/org/codehaus/mojo/versions/ordering/MercuryVersionComparatorTest.java
@@ -22,17 +22,17 @@
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.junit.Test;
-import static org.codehaus.mojo.versions.api.Segment.INCREMENTAL;
-import static org.codehaus.mojo.versions.api.Segment.MAJOR;
-import static org.codehaus.mojo.versions.api.Segment.MINOR;
import static org.junit.Assert.assertEquals;
-public class MercuryVersionComparatorTest
+public class MercuryVersionComparatorTest extends VersionComparatorTestBase
{
- private MercuryVersionComparator instance = new MercuryVersionComparator();
+ public MercuryVersionComparatorTest()
+ {
+ super( new MercuryVersionComparator() );
+ }
@Test
- public void testSegmentCounting() throws Exception
+ public void testSegmentCounting()
{
assertEquals( 1, instance.getSegmentCount( new DefaultArtifactVersion( "5" ) ) );
assertEquals( 2, instance.getSegmentCount( new DefaultArtifactVersion( "5.0" ) ) );
@@ -42,24 +42,5 @@ public void testSegmentCounting() throws Exception
assertEquals( 0, instance.getSegmentCount( new DefaultArtifactVersion( "" ) ) );
}
- @Test
- public void testSegmentIncrementing() throws Exception
- {
- assertEquals( new DefaultArtifactVersion( "6-SNAPSHOT" ).toString(),
- instance.incrementSegment( new DefaultArtifactVersion( "5" ), MAJOR ).toString() );
- assertEquals( new DefaultArtifactVersion( "6.0-SNAPSHOT" ).toString(),
- instance.incrementSegment( new DefaultArtifactVersion( "5.0" ), MAJOR ).toString() );
- assertEquals( new DefaultArtifactVersion( "5.1-SNAPSHOT" ).toString(),
- instance.incrementSegment( new DefaultArtifactVersion( "5.0" ), MINOR ).toString() );
- assertEquals( new DefaultArtifactVersion( "5.1.0-SNAPSHOT" ).toString(),
- instance.incrementSegment( new DefaultArtifactVersion( "5.0.1" ), MINOR ).toString() );
- assertEquals( new DefaultArtifactVersion( "5.beta.0-SNAPSHOT" ).toString(),
- instance.incrementSegment( new DefaultArtifactVersion( "5.alpha.1" ), MINOR ).toString() );
- assertEquals( new DefaultArtifactVersion( "5.beta-0.0-SNAPSHOT" ).toString(),
- instance.incrementSegment( new DefaultArtifactVersion( "5.alpha-1.1" ), MINOR ).toString() );
- assertEquals( new DefaultArtifactVersion( "5.alpha-2.0-SNAPSHOT" ).toString(),
- instance.incrementSegment( new DefaultArtifactVersion( "5.alpha-1.1" ), INCREMENTAL ).toString() );
- assertEquals( new DefaultArtifactVersion( "5.beta-0.0-SNAPSHOT" ).toString(),
- instance.incrementSegment( new DefaultArtifactVersion( "5.alpha-wins.1" ), MINOR ).toString() );
- }
+
}
diff --git a/src/test/java/org/codehaus/mojo/versions/ordering/NumericVersionComparatorTest.java b/src/test/java/org/codehaus/mojo/versions/ordering/NumericVersionComparatorTest.java
index 817468f86d..3b858ee5d4 100644
--- a/src/test/java/org/codehaus/mojo/versions/ordering/NumericVersionComparatorTest.java
+++ b/src/test/java/org/codehaus/mojo/versions/ordering/NumericVersionComparatorTest.java
@@ -22,15 +22,15 @@
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.junit.Test;
-import static org.codehaus.mojo.versions.api.Segment.INCREMENTAL;
-import static org.codehaus.mojo.versions.api.Segment.MAJOR;
-import static org.codehaus.mojo.versions.api.Segment.MINOR;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-public class NumericVersionComparatorTest
+public class NumericVersionComparatorTest extends VersionComparatorTestBase
{
- private NumericVersionComparator instance = new NumericVersionComparator();
+ public NumericVersionComparatorTest()
+ {
+ super( new NumericVersionComparator() );
+ }
private int instanceCompare( String v1, String v2 )
{
@@ -39,7 +39,6 @@ private int instanceCompare( String v1, String v2 )
@Test
public void testSmokes()
- throws Exception
{
assertTrue( instanceCompare( "1.0.0.0.0", "1.0.0.0.1" ) < 0 );
assertTrue( instanceCompare( "1.0.0.0.0", "2.0.0.0.1" ) < 0 );
@@ -50,7 +49,6 @@ public void testSmokes()
@Test
public void testBigValues()
- throws Exception
{
assertTrue( instanceCompare( "1.92.0", "1.100000000000000000000000.0" ) < 0 );
assertTrue( instanceCompare( "1.100000000000000000000000.0", "1.92.0" ) > 0 );
@@ -59,7 +57,6 @@ public void testBigValues()
@Test
public void testStringValues()
- throws Exception
{
assertTrue( instanceCompare( "1.a20.0", "1.a3.0" ) < 0 );
assertTrue( instanceCompare( "1.a20.0", "1.b10.0" ) < 0 );
@@ -81,7 +78,6 @@ public void testStringValues()
@Test
public void testQualifiers()
- throws Exception
{
assertTrue( instanceCompare( "1.0-alpha.10", "1.0-alpha.20" ) < 0 );
assertTrue( instanceCompare( "1.0-alpha.10", "1.0-beta.1" ) < 0 );
@@ -92,7 +88,6 @@ public void testQualifiers()
@Test
public void testSegmentCounting()
- throws Exception
{
assertEquals( 1, instance.getSegmentCount( new DefaultArtifactVersion( "5" ) ) );
assertEquals( 2, instance.getSegmentCount( new DefaultArtifactVersion( "5.0" ) ) );
@@ -102,25 +97,15 @@ public void testSegmentCounting()
assertEquals( 0, instance.getSegmentCount( new DefaultArtifactVersion( "" ) ) );
}
- @Test
- public void testSegmentIncrementing() throws Exception
+ @Override
+ public void testVersionComparatorRow5()
+ {
+ // non-numeric -- does not apply
+ }
+
+ @Override
+ public void testVersionComparatorRow6()
{
- assertEquals( new DefaultArtifactVersion( "6-SNAPSHOT" ).toString(),
- instance.incrementSegment( new DefaultArtifactVersion( "5" ), MAJOR ).toString() );
- assertEquals( new DefaultArtifactVersion( "6.0-SNAPSHOT" ).toString(),
- instance.incrementSegment( new DefaultArtifactVersion( "5.0" ), MAJOR ).toString() );
- assertEquals( new DefaultArtifactVersion( "5.1-SNAPSHOT" ).toString(),
- instance.incrementSegment( new DefaultArtifactVersion( "5.0" ), MINOR ).toString() );
- assertEquals( new DefaultArtifactVersion( "5.1.0-SNAPSHOT" ).toString(),
- instance.incrementSegment( new DefaultArtifactVersion( "5.0.1" ), MINOR ).toString() );
- assertEquals( new DefaultArtifactVersion( "5.beta.0-SNAPSHOT" ).toString(),
- instance.incrementSegment( new DefaultArtifactVersion( "5.alpha.1" ), MINOR ).toString() );
- assertEquals( new DefaultArtifactVersion( "5.alpha-2.0-SNAPSHOT" ).toString(),
- instance.incrementSegment( new DefaultArtifactVersion( "5.alpha-1.1" ), MINOR ).toString() );
- assertEquals( new DefaultArtifactVersion( "5.alpha-1.2-SNAPSHOT" ).toString(),
- instance.incrementSegment( new DefaultArtifactVersion( "5.alpha-1.1" ), INCREMENTAL )
- .toString() );
- assertEquals( new DefaultArtifactVersion( "5.beta.0-SNAPSHOT" ).toString(),
- instance.incrementSegment( new DefaultArtifactVersion( "5.alpha-wins.1" ), MINOR ).toString() );
+ // non-numeric -- does not apply
}
}
diff --git a/src/test/java/org/codehaus/mojo/versions/ordering/VersionComparatorTestBase.java b/src/test/java/org/codehaus/mojo/versions/ordering/VersionComparatorTestBase.java
new file mode 100644
index 0000000000..28e326a2ec
--- /dev/null
+++ b/src/test/java/org/codehaus/mojo/versions/ordering/VersionComparatorTestBase.java
@@ -0,0 +1,100 @@
+package org.codehaus.mojo.versions.ordering;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.artifact.versioning.ArtifactVersion;
+import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
+import org.junit.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.lessThan;
+
+/**
+ * Abstract base class for {@link MavenVersionComparatorTest}, {@link MercuryVersionComparatorTest},
+ * and {@link NumericVersionComparatorTest}
+ */
+public abstract class VersionComparatorTestBase
+{
+ protected final VersionComparator instance;
+
+ public VersionComparatorTestBase( VersionComparator instance )
+ {
+ this.instance = instance;
+ }
+
+ protected static ArtifactVersion version( String version )
+ {
+ return new DefaultArtifactVersion( version );
+ }
+
+ @Test
+ public void testVersionComparatorRow1()
+ {
+ assertThat( instance.compare( version( "1" ), version( "2" ) ), lessThan( 0 ) );
+ assertThat( instance.compare( version( "1.0" ), version( "2.0" ) ), lessThan( 0 ) );
+ assertThat( instance.compare( version( "1.0" ), version( "1.1" ) ), lessThan( 0 ) );
+ assertThat( instance.compare( version( "1.0" ), version( "1.1" ) ), lessThan( 0 ) );
+ }
+
+ @Test
+ public void testVersionComparatorRow2()
+ {
+ assertThat( instance.compare( version( "1.0" ), version( "2.0" ) ), lessThan( 0 ) );
+ assertThat( instance.compare( version( "1.0" ), version( "1.1" ) ), lessThan( 0 ) );
+ }
+
+ @Test
+ public void testVersionComparatorRow3()
+ {
+ assertThat( instance.compare( version( "1.0.0" ), version( "2.0.0" ) ), lessThan( 0 ) );
+ assertThat( instance.compare( version( "1.0.0" ), version( "1.1.0" ) ), lessThan( 0 ) );
+ assertThat( instance.compare( version( "1.0.0" ), version( "1.0.1" ) ), lessThan( 0 ) );
+ }
+
+ @Test
+ public void testVersionComparatorRow4()
+ {
+ assertThat( instance.compare( version( "1.0.0-1" ), version( "2.0.0-1" ) ), lessThan( 0 ) );
+ assertThat( instance.compare( version( "1.0.0-1" ), version( "1.1.0-1" ) ), lessThan( 0 ) );
+ assertThat( instance.compare( version( "1.0.0-1" ), version( "1.0.1-1" ) ), lessThan( 0 ) );
+ assertThat( instance.compare( version( "1.0.0-1" ), version( "1.0.0-2" ) ), lessThan( 0 ) );
+ }
+
+ @Test
+ public void testVersionComparatorRow5()
+ {
+ assertThat( instance.compare( version( "1.0.0-sp1" ), version( "2.0.0-sp1" ) ), lessThan( 0 ) );
+ assertThat( instance.compare( version( "1.0.0-sp1" ), version( "1.1.0-sp1" ) ), lessThan( 0 ) );
+ assertThat( instance.compare( version( "1.0.0-sp1" ), version( "1.0.1-sp1" ) ), lessThan( 0 ) );
+ assertThat( instance.compare( version( "1.0.0-sp1" ), version( "1.0.0-1-sp1" ) ), lessThan( 0 ) );
+ }
+
+ @Test
+ public void testVersionComparatorRow6()
+ {
+ assertThat( instance.compare( version( "foobar" ), version( "foobar-1" ) ), lessThan( 0 ) );
+ }
+
+ @Test
+ public void testVersionComparatorRow7()
+ {
+ assertThat( instance.compare( version( "1-alpha-1" ), version( "2-alpha-1" ) ), lessThan( 0 ) );
+ assertThat( instance.compare( version( "1-alpha-1" ), version( "1-alpha-2" ) ), lessThan( 0 ) );
+ }
+}
diff --git a/src/test/java/org/codehaus/mojo/versions/ordering/VersionComparatorsTest.java b/src/test/java/org/codehaus/mojo/versions/ordering/VersionComparatorsTest.java
deleted file mode 100644
index c33852d23e..0000000000
--- a/src/test/java/org/codehaus/mojo/versions/ordering/VersionComparatorsTest.java
+++ /dev/null
@@ -1,78 +0,0 @@
-package org.codehaus.mojo.versions.ordering;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.maven.artifact.versioning.ArtifactVersion;
-import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
-import org.codehaus.mojo.versions.api.Segment;
-import org.junit.Test;
-
-import static org.junit.Assert.assertTrue;
-
-public class VersionComparatorsTest
-{
- private final String[] versionDataset = {
- "1",
- "1.0",
- "1.0.0",
- "1.0.0-1",
- "1.0.0-sp1",
- "foobar",
- "1-alpha-1",
- };
-
- @Test
- public void testMavenVersionComparator() throws InvalidSegmentException
- {
- assertVersions( new MavenVersionComparator() );
- }
-
- @Test
- public void testMercuryVersionComparator() throws InvalidSegmentException
- {
- assertVersions( new MercuryVersionComparator() );
- }
-
- @Test
- public void testNumericVersionComparator() throws InvalidSegmentException
- {
- assertVersions( new NumericVersionComparator() );
- }
-
- public void assertVersions( VersionComparator instance ) throws InvalidSegmentException
- {
- for ( String s : versionDataset )
- {
- assertLater( s, instance );
- assertLater( s + "-SNAPSHOT", instance );
- }
- }
-
- public void assertLater( String version, VersionComparator instance ) throws InvalidSegmentException
- {
- ArtifactVersion v1 = new DefaultArtifactVersion( version );
- int count = instance.getSegmentCount( v1 );
- for ( int i = 0; i < count; i++ )
- {
- ArtifactVersion v2 = instance.incrementSegment( v1, Segment.of( i ) );
- assertTrue( v1 + " < " + v2, instance.compare( v1, v2 ) < 0 );
- }
- }
-}