diff --git a/apache-maven/src/test/java/org/apache/maven/settings/GlobalSettingsTest.java b/apache-maven/src/test/java/org/apache/maven/settings/GlobalSettingsTest.java index 2d34076f2b..70a11151fe 100644 --- a/apache-maven/src/test/java/org/apache/maven/settings/GlobalSettingsTest.java +++ b/apache-maven/src/test/java/org/apache/maven/settings/GlobalSettingsTest.java @@ -19,31 +19,33 @@ package org.apache.maven.settings; * under the License. */ -import junit.framework.TestCase; -import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader; - import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; import java.io.Reader; import java.nio.charset.StandardCharsets; +import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertTrue; + /** * Tests that the global settings.xml shipped with the distribution is in good state. * * @author Benjamin Bentmann */ public class GlobalSettingsTest - extends TestCase { + @Test public void testValidGlobalSettings() throws Exception { String basedir = System.getProperty( "basedir", System.getProperty( "user.dir" ) ); File globalSettingsFile = new File( basedir, "src/assembly/maven/conf/settings.xml" ); - assertTrue( globalSettingsFile.getAbsolutePath(), globalSettingsFile.isFile() ); + assertTrue( globalSettingsFile.isFile(), globalSettingsFile.getAbsolutePath() ); try ( Reader reader = new InputStreamReader( new FileInputStream( globalSettingsFile ), StandardCharsets.UTF_8) ) { diff --git a/maven-artifact/src/test/java/org/apache/maven/artifact/ArtifactUtilsTest.java b/maven-artifact/src/test/java/org/apache/maven/artifact/ArtifactUtilsTest.java index 333f6368bf..2cbe18e130 100644 --- a/maven-artifact/src/test/java/org/apache/maven/artifact/ArtifactUtilsTest.java +++ b/maven-artifact/src/test/java/org/apache/maven/artifact/ArtifactUtilsTest.java @@ -24,8 +24,10 @@ import java.util.List; import java.util.Map; import org.apache.maven.artifact.versioning.VersionRange; +import org.junit.jupiter.api.Test; -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * Tests {@link ArtifactUtils}. @@ -33,7 +35,6 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class ArtifactUtilsTest - extends TestCase { private Artifact newArtifact( String aid ) @@ -41,6 +42,7 @@ public class ArtifactUtilsTest return new DefaultArtifact( "group", aid, VersionRange.createFromVersion( "1.0" ), "test", "jar", "tests", null ); } + @Test public void testIsSnapshot() { assertEquals( false, ArtifactUtils.isSnapshot( null ) ); @@ -52,6 +54,7 @@ public class ArtifactUtilsTest assertEquals( false, ArtifactUtils.isSnapshot( "1.2.3-20090413X094722-2")); } + @Test public void testToSnapshotVersion() { assertEquals( "1.2.3", ArtifactUtils.toSnapshotVersion( "1.2.3" ) ); @@ -63,6 +66,7 @@ public class ArtifactUtilsTest /** * Tests that the ordering of the map resembles the ordering of the input collection of artifacts. */ + @Test public void testArtifactMapByVersionlessIdOrdering() throws Exception { diff --git a/maven-artifact/src/test/java/org/apache/maven/artifact/DefaultArtifactTest.java b/maven-artifact/src/test/java/org/apache/maven/artifact/DefaultArtifactTest.java index fbd0119161..3e9eb4de0f 100644 --- a/maven-artifact/src/test/java/org/apache/maven/artifact/DefaultArtifactTest.java +++ b/maven-artifact/src/test/java/org/apache/maven/artifact/DefaultArtifactTest.java @@ -19,13 +19,15 @@ package org.apache.maven.artifact; * under the License. */ -import junit.framework.TestCase; - import org.apache.maven.artifact.handler.ArtifactHandlerMock; import org.apache.maven.artifact.versioning.VersionRange; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class DefaultArtifactTest - extends TestCase { private DefaultArtifact artifact; @@ -43,10 +45,10 @@ public class DefaultArtifactTest private ArtifactHandlerMock artifactHandler; - protected void setUp() + @BeforeEach + public void setUp() throws Exception { - super.setUp(); artifactHandler = new ArtifactHandlerMock(); versionRange = VersionRange.createFromVersion( version ); artifact = new DefaultArtifact( groupId, artifactId, versionRange, scope, type, classifier, artifactHandler ); @@ -55,6 +57,7 @@ public class DefaultArtifactTest snapshotArtifact = new DefaultArtifact( groupId, artifactId, snapshotVersionRange, scope, type, classifier, artifactHandler ); } + @Test public void testGetVersionReturnsResolvedVersionOnSnapshot() { assertEquals( snapshotResolvedVersion, snapshotArtifact.getVersion() ); @@ -65,53 +68,62 @@ public class DefaultArtifactTest assertEquals( snapshotSpecVersion, snapshotArtifact.getBaseVersion() ); } + @Test public void testGetDependencyConflictId() { assertEquals( groupId + ":" + artifactId + ":" + type + ":" + classifier, artifact.getDependencyConflictId() ); } + @Test public void testGetDependencyConflictIdNullGroupId() { artifact.setGroupId( null ); assertEquals( null + ":" + artifactId + ":" + type + ":" + classifier, artifact.getDependencyConflictId() ); } + @Test public void testGetDependencyConflictIdNullClassifier() { artifact = new DefaultArtifact( groupId, artifactId, versionRange, scope, type, null, artifactHandler ); assertEquals( groupId + ":" + artifactId + ":" + type, artifact.getDependencyConflictId() ); } + @Test public void testGetDependencyConflictIdNullScope() { artifact.setScope( null ); assertEquals( groupId + ":" + artifactId + ":" + type + ":" + classifier, artifact.getDependencyConflictId() ); } + @Test public void testToString() { assertEquals( groupId + ":" + artifactId + ":" + type + ":" + classifier + ":" + version + ":" + scope, artifact.toString() ); } + @Test public void testToStringNullGroupId() { artifact.setGroupId( null ); assertEquals( artifactId + ":" + type + ":" + classifier + ":" + version + ":" + scope, artifact.toString() ); } + @Test public void testToStringNullClassifier() { artifact = new DefaultArtifact( groupId, artifactId, versionRange, scope, type, null, artifactHandler ); assertEquals( groupId + ":" + artifactId + ":" + type + ":" + version + ":" + scope, artifact.toString() ); } + @Test public void testToStringNullScope() { artifact.setScope( null ); assertEquals( groupId + ":" + artifactId + ":" + type + ":" + classifier + ":" + version, artifact.toString() ); } + @Test public void testComparisonByVersion() { Artifact artifact1 = new DefaultArtifact( groupId, artifactId, VersionRange.createFromVersion( "5.0" ), scope, @@ -128,6 +140,7 @@ public class DefaultArtifactTest assertTrue( artifact1.compareTo( artifact ) == 0 ); } + @Test public void testNonResolvedVersionRangeConsistentlyYieldsNullVersions() throws Exception { diff --git a/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionIT.java b/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionIT.java index 394b7f0565..cd63b4db3c 100644 --- a/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionIT.java +++ b/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionIT.java @@ -19,10 +19,8 @@ package org.apache.maven.artifact.versioning; * under the License. */ -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - import java.io.IOException; +import java.io.InterruptedIOException; import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.Path; @@ -31,7 +29,9 @@ import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import java.util.regex.Pattern; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class ComparableVersionIT { @@ -60,11 +60,11 @@ public class ComparableVersionIT try { - assertEquals( "Unexpected exit code", 0, p.waitFor() ); + assertEquals( 0, p.waitFor(), "Unexpected exit code" ); } catch ( InterruptedException e ) { - fail( e.getMessage() ); + throw new InterruptedIOException( e.toString() ); } return FileVisitResult.TERMINATE; } diff --git a/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java b/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java index 97fb46d55f..a36f605545 100644 --- a/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java +++ b/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java @@ -21,7 +21,10 @@ package org.apache.maven.artifact.versioning; import java.util.Locale; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Test ComparableVersion. @@ -30,7 +33,6 @@ import junit.framework.TestCase; */ @SuppressWarnings( "unchecked" ) public class ComparableVersionTest - extends TestCase { private Comparable newComparable( String version ) { @@ -39,8 +41,8 @@ public class ComparableVersionTest String parsedCanonical = new ComparableVersion( canonical ).getCanonical(); System.out.println( "canonical( " + version + " ) = " + canonical ); - assertEquals( "canonical( " + version + " ) = " + canonical + " -> canonical: " + parsedCanonical, canonical, - parsedCanonical ); + assertEquals( canonical, parsedCanonical, + "canonical( " + version + " ) = " + canonical + " -> canonical: " + parsedCanonical ); return ret; } @@ -68,8 +70,8 @@ public class ComparableVersionTest for ( int j = i; j < versions.length; j++ ) { Comparable high = c[j]; - assertTrue( "expected " + low + " < " + high, low.compareTo( high ) < 0 ); - assertTrue( "expected " + high + " > " + low, high.compareTo( low ) > 0 ); + assertTrue( low.compareTo( high ) < 0, "expected " + low + " < " + high ); + assertTrue( high.compareTo( low ) > 0, "expected " + high + " > " + low ); } } } @@ -78,11 +80,11 @@ public class ComparableVersionTest { Comparable c1 = newComparable( v1 ); Comparable c2 = newComparable( v2 ); - assertTrue( "expected " + v1 + " == " + v2, c1.compareTo( c2 ) == 0 ); - assertTrue( "expected " + v2 + " == " + v1, c2.compareTo( c1 ) == 0 ); - assertTrue( "expected same hashcode for " + v1 + " and " + v2, c1.hashCode() == c2.hashCode() ); - assertTrue( "expected " + v1 + ".equals( " + v2 + " )", c1.equals( c2 ) ); - assertTrue( "expected " + v2 + ".equals( " + v1 + " )", c2.equals( c1 ) ); + assertTrue( c1.compareTo( c2 ) == 0, "expected " + v1 + " == " + v2 ); + assertTrue( c2.compareTo( c1 ) == 0, "expected " + v2 + " == " + v1 ); + assertTrue( c1.hashCode() == c2.hashCode(), "expected same hashcode for " + v1 + " and " + v2 ); + assertTrue( c1.equals( c2 ), "expected " + v1 + ".equals( " + v2 + " )" ); + assertTrue( c2.equals( c1 ), "expected " + v2 + ".equals( " + v1 + " )" ); } private void checkVersionsArrayEqual( String[] array ) @@ -97,20 +99,23 @@ public class ComparableVersionTest { Comparable c1 = newComparable( v1 ); Comparable c2 = newComparable( v2 ); - assertTrue( "expected " + v1 + " < " + v2, c1.compareTo( c2 ) < 0 ); - assertTrue( "expected " + v2 + " > " + v1, c2.compareTo( c1 ) > 0 ); + assertTrue( c1.compareTo( c2 ) < 0, "expected " + v1 + " < " + v2 ); + assertTrue( c2.compareTo( c1 ) > 0, "expected " + v2 + " > " + v1 ); } + @Test public void testVersionsQualifier() { checkVersionsOrder( VERSIONS_QUALIFIER ); } + @Test public void testVersionsNumber() { checkVersionsOrder( VERSIONS_NUMBER ); } + @Test public void testVersionsEqual() { newComparable( "1.0-alpha" ); @@ -164,6 +169,7 @@ public class ComparableVersionTest checkVersionsEqual( "1m3", "1MILESTONE3" ); } + @Test public void testVersionComparing() { checkVersionsOrder( "1", "2" ); @@ -202,6 +208,7 @@ public class ComparableVersionTest * see Netbeans issues 240845 and * 226100 */ + @Test public void testMng5568() { String a = "6.1.0"; @@ -216,6 +223,7 @@ public class ComparableVersionTest /** * Test MNG-6572 optimization. */ + @Test public void testMng6572() { String a = "20190126.230843"; // resembles a SNAPSHOT @@ -235,6 +243,7 @@ public class ComparableVersionTest * Test all versions are equal when starting with many leading zeroes regardless of string length * (related to MNG-6572 optimization) */ + @Test public void testVersionEqualWithLeadingZeroes() { // versions with string lengths from 1 to 19 @@ -267,6 +276,7 @@ public class ComparableVersionTest * Test all "0" versions are equal when starting with many leading zeroes regardless of string length * (related to MNG-6572 optimization) */ + @Test public void testVersionZeroEqualWithLeadingZeroes() { // versions with string lengths from 1 to 19 @@ -299,6 +309,7 @@ public class ComparableVersionTest * Test MNG-6964 edge cases * for qualifiers that start with "-0.", which was showing A == C and B == C but A < B. */ + @Test public void testMng6964() { String a = "1-0.alpha"; @@ -310,6 +321,7 @@ public class ComparableVersionTest checkVersionsOrder( a, b ); // Should still be true } + @Test public void testLocaleIndependent() { Locale orig = Locale.getDefault(); @@ -328,6 +340,7 @@ public class ComparableVersionTest } } + @Test public void testReuse() { ComparableVersion c1 = new ComparableVersion( "1" ); @@ -335,6 +348,6 @@ public class ComparableVersionTest Comparable c2 = newComparable( "2" ); - assertEquals( "reused instance should be equivalent to new instance", c1, c2 ); + assertEquals( c1, c2, "reused instance should be equivalent to new instance" ); } } diff --git a/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/DefaultArtifactVersionTest.java b/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/DefaultArtifactVersionTest.java index fc5a2742ed..aba36bbe3f 100644 --- a/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/DefaultArtifactVersionTest.java +++ b/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/DefaultArtifactVersionTest.java @@ -19,7 +19,13 @@ package org.apache.maven.artifact.versioning; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Test DefaultArtifactVersion. @@ -27,7 +33,6 @@ import junit.framework.TestCase; * @author Brett Porter */ public class DefaultArtifactVersionTest - extends TestCase { private ArtifactVersion newArtifactVersion( String version ) { @@ -42,14 +47,15 @@ public class DefaultArtifactVersionTest "'" + version + "' parsed as ('" + artifactVersion.getMajorVersion() + "', '" + artifactVersion.getMinorVersion() + "', '" + artifactVersion.getIncrementalVersion() + "', '" + artifactVersion.getBuildNumber() + "', '" + artifactVersion.getQualifier() + "'), "; - assertEquals( parsed + "check major version", major, artifactVersion.getMajorVersion() ); - assertEquals( parsed + "check minor version", minor, artifactVersion.getMinorVersion() ); - assertEquals( parsed + "check incremental version", incremental, artifactVersion.getIncrementalVersion() ); - assertEquals( parsed + "check build number", buildnumber, artifactVersion.getBuildNumber() ); - assertEquals( parsed + "check qualifier", qualifier, artifactVersion.getQualifier() ); - assertEquals( "check " + version + " string value", version, artifactVersion.toString() ); + assertEquals( major, artifactVersion.getMajorVersion(), parsed + "check major version" ); + assertEquals( minor, artifactVersion.getMinorVersion(), parsed + "check minor version" ); + assertEquals( incremental, artifactVersion.getIncrementalVersion(), parsed + "check incremental version" ); + assertEquals( buildnumber, artifactVersion.getBuildNumber(), parsed + "check build number" ); + assertEquals( qualifier, artifactVersion.getQualifier(), parsed + "check qualifier" ); + assertEquals( version, artifactVersion.toString(), "check " + version + " string value" ); } + @Test public void testVersionParsing() { checkVersionParsing( "1", 1, 0, 0, 0, null ); @@ -87,6 +93,7 @@ public class DefaultArtifactVersionTest checkVersionParsing( "1.2.3-200705301630", 1, 2, 3, 0, "200705301630" ); } + @Test public void testVersionComparing() { assertVersionEqual( "1", "1" ); @@ -134,6 +141,7 @@ public class DefaultArtifactVersionTest assertVersionOlder( "2.0.0.v200706041905-7C78EK9E_EkMNfNOd2d8qq", "2.0.0.v200706041906-7C78EK9E_EkMNfNOd2d8qq" ); } + @Test public void testVersionSnapshotComparing() { assertVersionEqual( "1-SNAPSHOT", "1-SNAPSHOT" ); @@ -168,6 +176,7 @@ public class DefaultArtifactVersionTest assertVersionOlder( "2.0.1-xyz-SNAPSHOT", "2.0.1-123-SNAPSHOT" ); } + @Test public void testSnapshotVsReleases() { assertVersionOlder( "1.0-RC1", "1.0-SNAPSHOT" ); @@ -175,6 +184,7 @@ public class DefaultArtifactVersionTest assertVersionOlder( "1.0-rc-1", "1.0-SNAPSHOT" ); } + @Test public void testHashCode() { ArtifactVersion v1 = newArtifactVersion( "1" ); @@ -183,41 +193,45 @@ public class DefaultArtifactVersionTest assertEquals( v1.hashCode(), v2.hashCode() ); } + @Test public void testEqualsNullSafe() { assertFalse( newArtifactVersion( "1" ).equals( null ) ); } + @Test public void testEqualsTypeSafe() { assertFalse( newArtifactVersion( "1" ).equals( "non-an-artifact-version-instance" ) ); } + @Test + @Disabled("That one does not work") public void testNonNumericVersionRepresentationReturnsANumberFormatException() { - try - { - new DefaultArtifactVersion( "..." ); - } - catch ( Exception e ) - { - assertTrue( "We expect a NumberFormatException to be thrown.", e instanceof NumberFormatException ); - } + assertThrows( + NumberFormatException.class, + () -> new DefaultArtifactVersion( "..." ), + "We expect a NumberFormatException to be thrown." ); } private void assertVersionOlder( String left, String right ) { - assertTrue( left + " should be older than " + right, - newArtifactVersion( left ).compareTo( newArtifactVersion( right ) ) < 0 ); - assertTrue( right + " should be newer than " + left, - newArtifactVersion( right ).compareTo( newArtifactVersion( left ) ) > 0 ); + assertTrue( + newArtifactVersion( left ).compareTo( newArtifactVersion( right ) ) < 0, + left + " should be older than " + right ); + assertTrue( + newArtifactVersion( right ).compareTo( newArtifactVersion( left ) ) > 0, + right + " should be newer than " + left ); } private void assertVersionEqual( String left, String right ) { - assertTrue( left + " should be equal to " + right, - newArtifactVersion( left ).compareTo( newArtifactVersion( right ) ) == 0 ); - assertTrue( right + " should be equal to " + left, - newArtifactVersion( right ).compareTo( newArtifactVersion( left ) ) == 0 ); + assertTrue( + newArtifactVersion( left ).compareTo( newArtifactVersion( right ) ) == 0, + left + " should be equal to " + right ); + assertTrue( + newArtifactVersion( right ).compareTo( newArtifactVersion( left ) ) == 0, + right + " should be equal to " + left ); } } 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 2cf0fec930..50270a00d4 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 @@ -21,9 +21,15 @@ package org.apache.maven.artifact.versioning; import java.util.List; -import junit.framework.TestCase; - import org.apache.maven.artifact.Artifact; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests version range construction. @@ -31,7 +37,6 @@ import org.apache.maven.artifact.Artifact; * @author Brett Porter */ public class VersionRangeTest - extends TestCase { private static final String CHECK_NUM_RESTRICTIONS = "check number of restrictions"; @@ -49,6 +54,7 @@ public class VersionRangeTest private static final String CHECK_SELECTED_VERSION = "check selected version"; + @Test public void testRange() throws InvalidVersionSpecificationException, OverConstrainedVersionException { @@ -56,93 +62,93 @@ public class VersionRangeTest VersionRange range = VersionRange.createFromVersionSpec( "(,1.0]" ); List restrictions = range.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS ); Restriction restriction = restrictions.get( 0 ); - assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() ); - assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); - assertEquals( CHECK_UPPER_BOUND, "1.0", restriction.getUpperBound().toString() ); - assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); - assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() ); - assertFalse( CHECK_SELECTED_VERSION_KNOWN, range.isSelectedVersionKnown( artifact ) ); - assertNull( CHECK_SELECTED_VERSION, range.getSelectedVersion( artifact ) ); + assertNull( restriction.getLowerBound(), CHECK_LOWER_BOUND ); + assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.0", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); + assertNull( range.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION ); + assertFalse( range.isSelectedVersionKnown( artifact ), CHECK_SELECTED_VERSION_KNOWN ); + assertNull( range.getSelectedVersion( artifact ), CHECK_SELECTED_VERSION ); range = VersionRange.createFromVersionSpec( "1.0" ); - assertEquals( CHECK_VERSION_RECOMMENDATION, "1.0", range.getRecommendedVersion().toString() ); + assertEquals( "1.0", range.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION ); restrictions = range.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS ); restriction = restrictions.get( 0 ); - assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() ); - assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); - assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() ); - assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); - assertTrue( CHECK_SELECTED_VERSION_KNOWN, range.isSelectedVersionKnown( artifact ) ); - assertEquals( CHECK_SELECTED_VERSION, "1.0", range.getSelectedVersion( artifact ).toString() ); + assertNull( restriction.getLowerBound(), CHECK_LOWER_BOUND ); + assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertNull( restriction.getUpperBound(), CHECK_UPPER_BOUND ); + assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); + assertTrue( range.isSelectedVersionKnown( artifact ), CHECK_SELECTED_VERSION_KNOWN ); + assertEquals( "1.0", range.getSelectedVersion( artifact ).toString(), CHECK_SELECTED_VERSION ); range = VersionRange.createFromVersionSpec( "[1.0]" ); restrictions = range.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS ); restriction = restrictions.get( 0 ); - assertEquals( CHECK_LOWER_BOUND, "1.0", restriction.getLowerBound().toString() ); - assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); - assertEquals( CHECK_UPPER_BOUND, "1.0", restriction.getUpperBound().toString() ); - assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); - assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() ); - assertFalse( CHECK_SELECTED_VERSION_KNOWN, range.isSelectedVersionKnown( artifact ) ); - assertNull( CHECK_SELECTED_VERSION, range.getSelectedVersion( artifact ) ); + assertEquals( "1.0", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.0", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); + assertNull( range.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION ); + assertFalse( range.isSelectedVersionKnown( artifact ), CHECK_SELECTED_VERSION_KNOWN ); + assertNull( range.getSelectedVersion( artifact ), CHECK_SELECTED_VERSION ); range = VersionRange.createFromVersionSpec( "[1.2,1.3]" ); restrictions = range.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS ); restriction = restrictions.get( 0 ); - assertEquals( CHECK_LOWER_BOUND, "1.2", restriction.getLowerBound().toString() ); - assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); - assertEquals( CHECK_UPPER_BOUND, "1.3", restriction.getUpperBound().toString() ); - assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); - assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() ); - assertFalse( CHECK_SELECTED_VERSION_KNOWN, range.isSelectedVersionKnown( artifact ) ); - assertNull( CHECK_SELECTED_VERSION, range.getSelectedVersion( artifact ) ); + assertEquals( "1.2", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.3", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); + assertNull( range.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION ); + assertFalse( range.isSelectedVersionKnown( artifact ), CHECK_SELECTED_VERSION_KNOWN ); + assertNull( range.getSelectedVersion( artifact ), CHECK_SELECTED_VERSION ); range = VersionRange.createFromVersionSpec( "[1.0,2.0)" ); restrictions = range.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS ); restriction = restrictions.get( 0 ); - assertEquals( CHECK_LOWER_BOUND, "1.0", restriction.getLowerBound().toString() ); - assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); - assertEquals( CHECK_UPPER_BOUND, "2.0", restriction.getUpperBound().toString() ); - assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); - assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() ); - assertFalse( CHECK_SELECTED_VERSION_KNOWN, range.isSelectedVersionKnown( artifact ) ); - assertNull( CHECK_SELECTED_VERSION, range.getSelectedVersion( artifact ) ); + assertEquals( "1.0", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "2.0", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); + assertNull( range.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION ); + assertFalse( range.isSelectedVersionKnown( artifact ), CHECK_SELECTED_VERSION_KNOWN ); + assertNull( range.getSelectedVersion( artifact ), CHECK_SELECTED_VERSION ); range = VersionRange.createFromVersionSpec( "[1.5,)" ); restrictions = range.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS ); restriction = restrictions.get( 0 ); - assertEquals( CHECK_LOWER_BOUND, "1.5", restriction.getLowerBound().toString() ); - assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); - assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() ); - assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); - assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() ); - assertFalse( CHECK_SELECTED_VERSION_KNOWN, range.isSelectedVersionKnown( artifact ) ); - assertNull( CHECK_SELECTED_VERSION, range.getSelectedVersion( artifact ) ); + assertEquals( "1.5", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertNull( restriction.getUpperBound(), CHECK_UPPER_BOUND ); + assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); + assertNull( range.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION ); + assertFalse( range.isSelectedVersionKnown( artifact ), CHECK_SELECTED_VERSION_KNOWN ); + assertNull( range.getSelectedVersion( artifact ), CHECK_SELECTED_VERSION ); range = VersionRange.createFromVersionSpec( "(,1.0],[1.2,)" ); restrictions = range.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 2, restrictions.size() ); + assertEquals( 2, restrictions.size(), CHECK_NUM_RESTRICTIONS ); restriction = restrictions.get( 0 ); - assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() ); - assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); - assertEquals( CHECK_UPPER_BOUND, "1.0", restriction.getUpperBound().toString() ); - assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); - assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() ); + assertNull( restriction.getLowerBound(), CHECK_LOWER_BOUND ); + assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.0", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); + assertNull( range.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION ); restriction = restrictions.get( 1 ); - assertEquals( CHECK_LOWER_BOUND, "1.2", restriction.getLowerBound().toString() ); - assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); - assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() ); - assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); - assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() ); - assertFalse( CHECK_SELECTED_VERSION_KNOWN, range.isSelectedVersionKnown( artifact ) ); - assertNull( CHECK_SELECTED_VERSION, range.getSelectedVersion( artifact ) ); + assertEquals( "1.2", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertNull( restriction.getUpperBound(), CHECK_UPPER_BOUND ); + assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); + assertNull( range.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION ); + assertFalse( range.isSelectedVersionKnown( artifact ), CHECK_SELECTED_VERSION_KNOWN ); + assertNull( range.getSelectedVersion( artifact ), CHECK_SELECTED_VERSION ); range = VersionRange.createFromVersionSpec( "[1.0,)" ); assertFalse( range.containsVersion( new DefaultArtifactVersion( "1.0-SNAPSHOT" ) ) ); @@ -154,6 +160,7 @@ public class VersionRangeTest assertTrue( range.containsVersion( new DefaultArtifactVersion( "5.0.9.0" ) ) ); } + @Test public void testInvalidRanges() { checkInvalidRange( "(1.0)" ); @@ -172,6 +179,7 @@ public class VersionRangeTest checkInvalidRange( "(1.1,1.2],[1.0,1.1)" ); } + @Test public void testIntersections() throws InvalidVersionSpecificationException { @@ -179,481 +187,482 @@ public class VersionRangeTest VersionRange range2 = VersionRange.createFromVersionSpec( "1.1" ); VersionRange mergedRange = range1.restrict( range2 ); // TODO current policy is to retain the original version - is this correct, do we need strategies or is that handled elsewhere? -// assertEquals( CHECK_VERSION_RECOMMENDATION, "1.1", mergedRange.getRecommendedVersion().toString() ); - assertEquals( CHECK_VERSION_RECOMMENDATION, "1.0", mergedRange.getRecommendedVersion().toString() ); +// assertEquals( "1.1", mergedRange.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION ); + assertEquals( "1.0", mergedRange.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION ); List restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS ); Restriction restriction = restrictions.get( 0 ); - assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() ); - assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); - assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() ); - assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + assertNull( restriction.getLowerBound(), CHECK_LOWER_BOUND ); + assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertNull( restriction.getUpperBound(), CHECK_UPPER_BOUND ); + assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); mergedRange = range2.restrict( range1 ); - assertEquals( CHECK_VERSION_RECOMMENDATION, "1.1", mergedRange.getRecommendedVersion().toString() ); + assertEquals( "1.1", mergedRange.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION ); restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS ); restriction = restrictions.get( 0 ); - assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() ); - assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); - assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() ); - assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + assertNull( restriction.getLowerBound(), CHECK_LOWER_BOUND ); + assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertNull( restriction.getUpperBound(), CHECK_UPPER_BOUND ); + assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); // TODO test reversed restrictions on all below range1 = VersionRange.createFromVersionSpec( "[1.0,)" ); range2 = VersionRange.createFromVersionSpec( "1.1" ); mergedRange = range1.restrict( range2 ); - assertEquals( CHECK_VERSION_RECOMMENDATION, "1.1", mergedRange.getRecommendedVersion().toString() ); + assertEquals( "1.1", mergedRange.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION ); restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS ); restriction = restrictions.get( 0 ); - assertEquals( CHECK_LOWER_BOUND, "1.0", restriction.getLowerBound().toString() ); - assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); - assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() ); - assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + assertEquals( "1.0", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertNull( restriction.getUpperBound(), CHECK_UPPER_BOUND ); + assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); range1 = VersionRange.createFromVersionSpec( "[1.1,)" ); range2 = VersionRange.createFromVersionSpec( "1.1" ); mergedRange = range1.restrict( range2 ); - assertEquals( CHECK_VERSION_RECOMMENDATION, "1.1", mergedRange.getRecommendedVersion().toString() ); + assertEquals( "1.1", mergedRange.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION ); restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS ); restriction = restrictions.get( 0 ); - assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() ); - assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); - assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() ); - assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertNull( restriction.getUpperBound(), CHECK_UPPER_BOUND ); + assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); range1 = VersionRange.createFromVersionSpec( "[1.1]" ); range2 = VersionRange.createFromVersionSpec( "1.1" ); mergedRange = range1.restrict( range2 ); - assertEquals( CHECK_VERSION_RECOMMENDATION, "1.1", mergedRange.getRecommendedVersion().toString() ); + assertEquals( "1.1", mergedRange.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION ); restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS ); 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.getLowerBound().toString() ); - assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_UPPER_BOUND ); + assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); range1 = VersionRange.createFromVersionSpec( "(1.1,)" ); range2 = VersionRange.createFromVersionSpec( "1.1" ); mergedRange = range1.restrict( range2 ); - assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION ); restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS ); restriction = restrictions.get( 0 ); - assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() ); - assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); - assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() ); - assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertNull( restriction.getUpperBound(), CHECK_UPPER_BOUND ); + assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); range1 = VersionRange.createFromVersionSpec( "[1.2,)" ); range2 = VersionRange.createFromVersionSpec( "1.1" ); mergedRange = range1.restrict( range2 ); - assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION ); restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS ); restriction = restrictions.get( 0 ); - assertEquals( CHECK_LOWER_BOUND, "1.2", restriction.getLowerBound().toString() ); - assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); - assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() ); - assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + assertEquals( "1.2", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertNull( restriction.getUpperBound(), CHECK_UPPER_BOUND ); + assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); range1 = VersionRange.createFromVersionSpec( "(,1.2]" ); range2 = VersionRange.createFromVersionSpec( "1.1" ); mergedRange = range1.restrict( range2 ); - assertEquals( CHECK_VERSION_RECOMMENDATION, "1.1", mergedRange.getRecommendedVersion().toString() ); + assertEquals( "1.1", mergedRange.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION ); restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS ); restriction = restrictions.get( 0 ); - assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() ); - assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); - assertEquals( CHECK_UPPER_BOUND, "1.2", restriction.getUpperBound().toString() ); - assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + assertNull( restriction.getLowerBound(), CHECK_LOWER_BOUND ); + assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.2", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); range1 = VersionRange.createFromVersionSpec( "(,1.1]" ); range2 = VersionRange.createFromVersionSpec( "1.1" ); mergedRange = range1.restrict( range2 ); - assertEquals( CHECK_VERSION_RECOMMENDATION, "1.1", mergedRange.getRecommendedVersion().toString() ); + assertEquals( "1.1", mergedRange.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION ); restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS ); restriction = restrictions.get( 0 ); - assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() ); - assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); - assertEquals( CHECK_UPPER_BOUND, "1.1", restriction.getUpperBound().toString() ); - assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + assertNull( restriction.getLowerBound(), CHECK_LOWER_BOUND ); + assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.1", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); range1 = VersionRange.createFromVersionSpec( "(,1.1)" ); range2 = VersionRange.createFromVersionSpec( "1.1" ); mergedRange = range1.restrict( range2 ); - assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION ); restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS ); restriction = restrictions.get( 0 ); - assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() ); - assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); - assertEquals( CHECK_UPPER_BOUND, "1.1", restriction.getUpperBound().toString() ); - assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + assertNull( restriction.getLowerBound(), CHECK_LOWER_BOUND ); + assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.1", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); range1 = VersionRange.createFromVersionSpec( "(,1.0]" ); range2 = VersionRange.createFromVersionSpec( "1.1" ); mergedRange = range1.restrict( range2 ); - assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION ); restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS ); restriction = restrictions.get( 0 ); - assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() ); - assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); - assertEquals( CHECK_UPPER_BOUND, "1.0", restriction.getUpperBound().toString() ); - assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + assertNull( restriction.getLowerBound(), CHECK_LOWER_BOUND ); + assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.0", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); range1 = VersionRange.createFromVersionSpec( "(,1.0], [1.1,)" ); range2 = VersionRange.createFromVersionSpec( "1.2" ); mergedRange = range1.restrict( range2 ); - assertEquals( CHECK_VERSION_RECOMMENDATION, "1.2", mergedRange.getRecommendedVersion().toString() ); + assertEquals( "1.2", mergedRange.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION ); restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 2, restrictions.size() ); + assertEquals( 2, restrictions.size(), CHECK_NUM_RESTRICTIONS ); restriction = restrictions.get( 0 ); - assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() ); - assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); - assertEquals( CHECK_UPPER_BOUND, "1.0", restriction.getUpperBound().toString() ); - assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + assertNull( restriction.getLowerBound(), CHECK_LOWER_BOUND ); + assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.0", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); restriction = restrictions.get( 1 ); - assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() ); - assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); - assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() ); - assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertNull( restriction.getUpperBound(), CHECK_UPPER_BOUND ); + assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); range1 = VersionRange.createFromVersionSpec( "(,1.0], [1.1,)" ); range2 = VersionRange.createFromVersionSpec( "1.0.5" ); mergedRange = range1.restrict( range2 ); - assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION ); restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 2, restrictions.size() ); + assertEquals( 2, restrictions.size(), CHECK_NUM_RESTRICTIONS ); restriction = restrictions.get( 0 ); - assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() ); - assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); - assertEquals( CHECK_UPPER_BOUND, "1.0", restriction.getUpperBound().toString() ); - assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + assertNull( restriction.getLowerBound(), CHECK_LOWER_BOUND ); + assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.0", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); restriction = restrictions.get( 1 ); - assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() ); - assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); - assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() ); - assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertNull( restriction.getUpperBound(), CHECK_UPPER_BOUND ); + assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); range1 = VersionRange.createFromVersionSpec( "(,1.1), (1.1,)" ); range2 = VersionRange.createFromVersionSpec( "1.1" ); mergedRange = range1.restrict( range2 ); - assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION ); restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 2, restrictions.size() ); + assertEquals( 2, restrictions.size(), CHECK_NUM_RESTRICTIONS ); restriction = restrictions.get( 0 ); - assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() ); - assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); - assertEquals( CHECK_UPPER_BOUND, "1.1", restriction.getUpperBound().toString() ); - assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + assertNull( restriction.getLowerBound(), CHECK_LOWER_BOUND ); + assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.1", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); restriction = restrictions.get( 1 ); - assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() ); - assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); - assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() ); - assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertNull( restriction.getUpperBound(), CHECK_UPPER_BOUND ); + assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); range1 = VersionRange.createFromVersionSpec( "[1.1,1.3]" ); range2 = VersionRange.createFromVersionSpec( "(1.1,)" ); mergedRange = range1.restrict( range2 ); - assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION ); restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS ); 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.3", restriction.getUpperBound().toString() ); - assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.3", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); range1 = VersionRange.createFromVersionSpec( "(,1.3)" ); range2 = VersionRange.createFromVersionSpec( "[1.2,1.3]" ); mergedRange = range1.restrict( range2 ); - assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION ); restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS ); restriction = restrictions.get( 0 ); - assertEquals( CHECK_LOWER_BOUND, "1.2", restriction.getLowerBound().toString() ); - assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); - assertEquals( CHECK_UPPER_BOUND, "1.3", restriction.getUpperBound().toString() ); - assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + assertEquals( "1.2", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.3", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); range1 = VersionRange.createFromVersionSpec( "[1.1,1.3]" ); range2 = VersionRange.createFromVersionSpec( "[1.2,)" ); mergedRange = range1.restrict( range2 ); - assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION ); restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS ); restriction = restrictions.get( 0 ); - assertEquals( CHECK_LOWER_BOUND, "1.2", restriction.getLowerBound().toString() ); - assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); - assertEquals( CHECK_UPPER_BOUND, "1.3", restriction.getUpperBound().toString() ); - assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + assertEquals( "1.2", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.3", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); range1 = VersionRange.createFromVersionSpec( "(,1.3]" ); range2 = VersionRange.createFromVersionSpec( "[1.2,1.4]" ); mergedRange = range1.restrict( range2 ); - assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION ); restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS ); restriction = restrictions.get( 0 ); - assertEquals( CHECK_LOWER_BOUND, "1.2", restriction.getLowerBound().toString() ); - assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); - assertEquals( CHECK_UPPER_BOUND, "1.3", restriction.getUpperBound().toString() ); - assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + assertEquals( "1.2", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.3", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); range1 = VersionRange.createFromVersionSpec( "(1.2,1.3]" ); range2 = VersionRange.createFromVersionSpec( "[1.1,1.4]" ); mergedRange = range1.restrict( range2 ); - assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION ); restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS ); restriction = restrictions.get( 0 ); - assertEquals( CHECK_LOWER_BOUND, "1.2", restriction.getLowerBound().toString() ); - assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); - assertEquals( CHECK_UPPER_BOUND, "1.3", restriction.getUpperBound().toString() ); - assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + assertEquals( "1.2", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.3", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); range1 = VersionRange.createFromVersionSpec( "(1.2,1.3)" ); range2 = VersionRange.createFromVersionSpec( "[1.1,1.4]" ); mergedRange = range1.restrict( range2 ); - assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION ); restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS ); restriction = restrictions.get( 0 ); - assertEquals( CHECK_LOWER_BOUND, "1.2", restriction.getLowerBound().toString() ); - assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); - assertEquals( CHECK_UPPER_BOUND, "1.3", restriction.getUpperBound().toString() ); - assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + assertEquals( "1.2", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.3", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); range1 = VersionRange.createFromVersionSpec( "[1.2,1.3)" ); range2 = VersionRange.createFromVersionSpec( "[1.1,1.4]" ); mergedRange = range1.restrict( range2 ); - assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION ); restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS ); restriction = restrictions.get( 0 ); - assertEquals( CHECK_LOWER_BOUND, "1.2", restriction.getLowerBound().toString() ); - assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); - assertEquals( CHECK_UPPER_BOUND, "1.3", restriction.getUpperBound().toString() ); - assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + assertEquals( "1.2", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.3", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); range1 = VersionRange.createFromVersionSpec( "[1.0,1.1]" ); range2 = VersionRange.createFromVersionSpec( "[1.1,1.4]" ); mergedRange = range1.restrict( range2 ); - assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION ); restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS ); 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() ); + assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.1", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); range1 = VersionRange.createFromVersionSpec( "[1.0,1.1)" ); range2 = VersionRange.createFromVersionSpec( "[1.1,1.4]" ); mergedRange = range1.restrict( range2 ); - assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION ); restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 0, restrictions.size() ); + assertEquals( 0, restrictions.size(), CHECK_NUM_RESTRICTIONS ); 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() ); + assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION ); restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS ); 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() ); + assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.1", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); 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() ); + assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION ); restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS ); 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() ); + assertEquals( "1.4", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.4", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); 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() ); + assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION ); restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 2, restrictions.size() ); + assertEquals( 2, restrictions.size(), CHECK_NUM_RESTRICTIONS ); 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() ); + assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.2", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); 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() ); + assertEquals( "1.3", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.4", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); 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() ); + assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION ); restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 2, restrictions.size() ); + assertEquals( 2, restrictions.size(), CHECK_NUM_RESTRICTIONS ); 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() ); + assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.2", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); 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() ); + assertEquals( "1.3", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.4", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); 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() ); + assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION ); restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 2, restrictions.size() ); + assertEquals( 2, restrictions.size(), CHECK_NUM_RESTRICTIONS ); 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() ); + assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.2", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); 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() ); + assertEquals( "1.3", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.4", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); 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() ); + assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION ); restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 2, restrictions.size() ); + assertEquals( 2, restrictions.size(), CHECK_NUM_RESTRICTIONS ); 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() ); + assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.2", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); 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() ); + assertEquals( "1.3", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.4", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); range1 = VersionRange.createFromVersionSpec( "(,1.1),(1.4,)" ); range2 = VersionRange.createFromVersionSpec( "[1.1,1.4]" ); mergedRange = range1.restrict( range2 ); - assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION ); restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 0, restrictions.size() ); + assertEquals( 0, restrictions.size(), CHECK_NUM_RESTRICTIONS ); range1 = VersionRange.createFromVersionSpec( "(,1.1],[1.4,)" ); range2 = VersionRange.createFromVersionSpec( "(1.1,1.4)" ); mergedRange = range1.restrict( range2 ); - assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION ); restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 0, restrictions.size() ); + assertEquals( 0, restrictions.size(), CHECK_NUM_RESTRICTIONS ); range1 = VersionRange.createFromVersionSpec( "[,1.1],[1.4,]" ); range2 = VersionRange.createFromVersionSpec( "[1.2,1.3]" ); mergedRange = range1.restrict( range2 ); - assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION ); restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 0, restrictions.size() ); + assertEquals( 0, restrictions.size(), CHECK_NUM_RESTRICTIONS ); 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() ); + assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION ); restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 2, restrictions.size() ); + assertEquals( 2, restrictions.size(), CHECK_NUM_RESTRICTIONS ); 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() ); + assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.2", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); 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() ); + assertEquals( "1.3", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.4", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); 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() ); + assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION ); restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 3, restrictions.size() ); + assertEquals( 3, restrictions.size(), CHECK_NUM_RESTRICTIONS ); 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() ); + assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.2", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); 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() ); + assertEquals( "1.3", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.4", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); 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() ); + assertEquals( "1.5", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.5", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); 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() ); + assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION ); restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 3, restrictions.size() ); + assertEquals( 3, restrictions.size(), CHECK_NUM_RESTRICTIONS ); 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() ); + assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.2", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); 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() ); + assertEquals( "1.3", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.4", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); 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() ); + assertEquals( "1.5", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND ); + assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE ); + assertEquals( "1.6", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND ); + assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE ); // test restricting empty sets range1 = VersionRange.createFromVersionSpec( "[,1.1],[1.4,]" ); range2 = VersionRange.createFromVersionSpec( "[1.2,1.3]" ); range1 = range1.restrict( range2 ); mergedRange = range1.restrict( range2 ); - assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION ); restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 0, restrictions.size() ); + assertEquals( 0, restrictions.size(), CHECK_NUM_RESTRICTIONS ); range1 = VersionRange.createFromVersionSpec( "[,1.1],[1.4,]" ); range2 = VersionRange.createFromVersionSpec( "[1.2,1.3]" ); range2 = range1.restrict( range2 ); mergedRange = range1.restrict( range2 ); - assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION ); restrictions = mergedRange.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 0, restrictions.size() ); + assertEquals( 0, restrictions.size(), CHECK_NUM_RESTRICTIONS ); } + @Test public void testReleaseRangeBoundsContainsSnapshots() throws InvalidVersionSpecificationException { @@ -664,6 +673,7 @@ public class VersionRangeTest assertFalse( range.containsVersion( new DefaultArtifactVersion( "1.0-SNAPSHOT" ) ) ); } + @Test public void testSnapshotRangeBoundsCanContainSnapshots() throws InvalidVersionSpecificationException { @@ -678,6 +688,7 @@ public class VersionRangeTest assertTrue( range.containsVersion( new DefaultArtifactVersion( "1.1-SNAPSHOT" ) ) ); } + @Test public void testSnapshotSoftVersionCanContainSnapshot() throws InvalidVersionSpecificationException { @@ -688,17 +699,13 @@ public class VersionRangeTest private void checkInvalidRange( String version ) { - try - { - VersionRange.createFromVersionSpec( version ); - fail( "Version " + version + " should have failed to construct" ); - } - catch ( InvalidVersionSpecificationException expected ) - { - // expected - } + assertThrows( + InvalidVersionSpecificationException.class, + () -> VersionRange.createFromVersionSpec( version ), + "Version " + version + " should have failed to construct" ); } + @Test public void testContains() throws InvalidVersionSpecificationException { ArtifactVersion actualVersion = new DefaultArtifactVersion( "2.0.5" ); @@ -723,11 +730,13 @@ public class VersionRangeTest return vr.containsVersion( actualVersion ); } + @Test public void testOrder0() { // assertTrue( new DefaultArtifactVersion( "1.0-alpha10" ).compareTo( new DefaultArtifactVersion( "1.0-alpha1" ) ) > 0 ); } + @Test public void testCache() throws InvalidVersionSpecificationException { @@ -737,13 +746,13 @@ public class VersionRangeTest VersionRange spec = VersionRange.createFromVersionSpec( "1.0" ); assertSame( spec, VersionRange.createFromVersionSpec( "1.0" ) ); // same instance from spec cache List restrictions = spec.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS ); VersionRange version = VersionRange.createFromVersion( "1.0" ); assertSame( version, VersionRange.createFromVersion( "1.0" ) ); // same instance from version cache restrictions = version.getRestrictions(); - assertEquals( CHECK_NUM_RESTRICTIONS, 0, restrictions.size() ); + assertEquals( 0, restrictions.size(), CHECK_NUM_RESTRICTIONS ); - assertFalse( "check !VersionRange.createFromVersionSpec(x).equals(VersionRange.createFromVersion(x))", spec.equals( version ) ); + assertFalse( spec.equals( version ), "check !VersionRange.createFromVersionSpec(x).equals(VersionRange.createFromVersion(x))" ); } } diff --git a/maven-builder-support/src/test/java/org/apache/maven/building/DefaultProblemCollectorTest.java b/maven-builder-support/src/test/java/org/apache/maven/building/DefaultProblemCollectorTest.java index 57ddcfa1f8..dbde11ed52 100644 --- a/maven-builder-support/src/test/java/org/apache/maven/building/DefaultProblemCollectorTest.java +++ b/maven-builder-support/src/test/java/org/apache/maven/building/DefaultProblemCollectorTest.java @@ -19,10 +19,11 @@ package org.apache.maven.building; * under the License. */ -import static org.junit.Assert.*; - import org.apache.maven.building.Problem.Severity; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class DefaultProblemCollectorTest { diff --git a/maven-builder-support/src/test/java/org/apache/maven/building/DefaultProblemTest.java b/maven-builder-support/src/test/java/org/apache/maven/building/DefaultProblemTest.java index 1615fc3751..4d9a3d89cc 100644 --- a/maven-builder-support/src/test/java/org/apache/maven/building/DefaultProblemTest.java +++ b/maven-builder-support/src/test/java/org/apache/maven/building/DefaultProblemTest.java @@ -19,11 +19,11 @@ package org.apache.maven.building; * under the License. */ -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; - import org.apache.maven.building.Problem.Severity; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; public class DefaultProblemTest { diff --git a/maven-builder-support/src/test/java/org/apache/maven/building/FileSourceTest.java b/maven-builder-support/src/test/java/org/apache/maven/building/FileSourceTest.java index 40ab4956cf..9373c01e8d 100644 --- a/maven-builder-support/src/test/java/org/apache/maven/building/FileSourceTest.java +++ b/maven-builder-support/src/test/java/org/apache/maven/building/FileSourceTest.java @@ -19,14 +19,14 @@ package org.apache.maven.building; * under the License. */ -import org.junit.Test; - import java.io.File; import java.io.InputStream; import java.util.Scanner; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; public class FileSourceTest { @@ -34,15 +34,11 @@ public class FileSourceTest @Test public void testFileSource() { - try - { - new FileSource( null ); - fail( "Should fail, since you must specify a file" ); - } - catch ( NullPointerException e ) - { - assertEquals( "file cannot be null", e.getMessage() ); - } + NullPointerException e = assertThrows( + NullPointerException.class, + () -> new FileSource( null ), + "Should fail, since you must specify a file" ); + assertEquals( "file cannot be null", e.getMessage() ); } @Test diff --git a/maven-builder-support/src/test/java/org/apache/maven/building/ProblemCollectorFactoryTest.java b/maven-builder-support/src/test/java/org/apache/maven/building/ProblemCollectorFactoryTest.java index 2fdcbb70c4..ee2575b9f1 100644 --- a/maven-builder-support/src/test/java/org/apache/maven/building/ProblemCollectorFactoryTest.java +++ b/maven-builder-support/src/test/java/org/apache/maven/building/ProblemCollectorFactoryTest.java @@ -19,12 +19,12 @@ package org.apache.maven.building; * under the License. */ -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; - import java.util.Collections; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; public class ProblemCollectorFactoryTest { diff --git a/maven-builder-support/src/test/java/org/apache/maven/building/StringSourceTest.java b/maven-builder-support/src/test/java/org/apache/maven/building/StringSourceTest.java index 6d9a671e71..85309aa86b 100644 --- a/maven-builder-support/src/test/java/org/apache/maven/building/StringSourceTest.java +++ b/maven-builder-support/src/test/java/org/apache/maven/building/StringSourceTest.java @@ -19,12 +19,12 @@ package org.apache.maven.building; * under the License. */ -import org.junit.Test; - import java.io.InputStream; import java.util.Scanner; -import static org.junit.Assert.assertEquals; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class StringSourceTest { diff --git a/maven-builder-support/src/test/java/org/apache/maven/building/UrlSourceTest.java b/maven-builder-support/src/test/java/org/apache/maven/building/UrlSourceTest.java index 00f3a6835a..efdb9bb684 100644 --- a/maven-builder-support/src/test/java/org/apache/maven/building/UrlSourceTest.java +++ b/maven-builder-support/src/test/java/org/apache/maven/building/UrlSourceTest.java @@ -19,15 +19,15 @@ package org.apache.maven.building; * under the License. */ -import org.junit.Test; - import java.io.File; import java.io.InputStream; import java.net.URL; import java.util.Scanner; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; public class UrlSourceTest { @@ -35,15 +35,11 @@ public class UrlSourceTest @Test public void testUrlSource() { - try - { - new UrlSource( null ); - fail( "Should fail, since you must specify a url" ); - } - catch ( NullPointerException e ) - { - assertEquals( "url cannot be null", e.getMessage() ); - } + NullPointerException e = assertThrows( + NullPointerException.class, + () -> new UrlSource( null ), + "Should fail, since you must specify a url" ); + assertEquals( "url cannot be null", e.getMessage() ); } @Test diff --git a/maven-compat/pom.xml b/maven-compat/pom.xml index 73d1a2463c..be1cd35786 100644 --- a/maven-compat/pom.xml +++ b/maven-compat/pom.xml @@ -99,6 +99,11 @@ under the License. wagon-provider-api + + org.apache.maven + maven-test-support + test + org.codehaus.plexus plexus-cipher diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java b/maven-compat/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java index 3c0ce1371b..146ec685eb 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java @@ -19,6 +19,20 @@ package org.apache.maven.artifact; * under the License. */ +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; +import java.util.ArrayList; +import java.util.List; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.apache.maven.test.PlexusTestCase; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; @@ -28,10 +42,6 @@ import org.apache.maven.execution.DefaultMavenExecutionResult; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.LegacySupport; import org.apache.maven.repository.legacy.repository.ArtifactRepositoryFactory; -import org.codehaus.plexus.ContainerConfiguration; -import org.codehaus.plexus.DefaultPlexusContainer; -import org.codehaus.plexus.PlexusConstants; -import org.codehaus.plexus.PlexusTestCase; import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.collection.DependencyGraphTransformer; @@ -54,18 +64,11 @@ import org.eclipse.aether.util.graph.transformer.NearestVersionSelector; import org.eclipse.aether.util.graph.transformer.SimpleOptionalitySelector; import org.eclipse.aether.util.graph.traverser.FatArtifactTraverser; import org.eclipse.aether.util.repository.SimpleArtifactDescriptorPolicy; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; -import javax.inject.Inject; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.io.Writer; -import java.nio.charset.StandardCharsets; -import java.security.MessageDigest; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Jason van Zyl @@ -82,24 +85,15 @@ public abstract class AbstractArtifactComponentTestCase @Inject LegacySupport legacySupport; - @Override - protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration ) - { - super.customizeContainerConfiguration( containerConfiguration ); - containerConfiguration.setAutoWiring( true ); - containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); - } + @Inject @Named( "default" ) + ArtifactRepositoryLayout repoLayout; - @Override - protected void setUp() + @BeforeEach + public void setUp() throws Exception { super.setUp(); - ((DefaultPlexusContainer)getContainer()) - .addPlexusInjector( Collections.emptyList(), - binder -> binder.requestInjection( this ) ); - RepositorySystemSession repoSession = initRepoSession(); MavenSession session = new MavenSession( getContainer(), repoSession, new DefaultMavenExecutionRequest(), new DefaultMavenExecutionResult() ); @@ -107,15 +101,6 @@ public abstract class AbstractArtifactComponentTestCase legacySupport.setSession( session ); } - @Override - protected void tearDown() - throws Exception - { - release( artifactFactory ); - - super.tearDown(); - } - protected abstract String component(); /** @@ -132,9 +117,6 @@ public abstract class AbstractArtifactComponentTestCase f.createNewFile(); - ArtifactRepositoryLayout repoLayout = - (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); - return artifactRepositoryFactory.createArtifactRepository( "test", "file://" + f.getPath(), repoLayout, null, null ); } @@ -151,9 +133,6 @@ public abstract class AbstractArtifactComponentTestCase File f = new File( getBasedir(), path ); - ArtifactRepositoryLayout repoLayout = - (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); - return artifactRepositoryFactory.createArtifactRepository( "local", "file://" + f.getPath(), repoLayout, null, null ); } @@ -165,9 +144,6 @@ public abstract class AbstractArtifactComponentTestCase File f = new File( getBasedir(), path ); - ArtifactRepositoryLayout repoLayout = - (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); - return artifactRepositoryFactory.createArtifactRepository( "test", "file://" + f.getPath(), repoLayout, new ArtifactRepositoryPolicy(), new ArtifactRepositoryPolicy() ); @@ -176,9 +152,6 @@ public abstract class AbstractArtifactComponentTestCase protected ArtifactRepository badRemoteRepository() throws Exception { - ArtifactRepositoryLayout repoLayout = - (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); - return artifactRepositoryFactory.createArtifactRepository( "test", "http://foo.bar/repository", repoLayout, null, null ); } @@ -192,10 +165,7 @@ public abstract class AbstractArtifactComponentTestCase File file = new File( remoteRepo.getBasedir(), path ); - if ( !file.exists() ) - { - fail( "Remote artifact " + file + " should be present." ); - } + assertTrue( file.exists(), "Remote artifact " + file + " should be present." ); } protected void assertLocalArtifactPresent( Artifact artifact ) @@ -207,10 +177,7 @@ public abstract class AbstractArtifactComponentTestCase File file = new File( localRepo.getBasedir(), path ); - if ( !file.exists() ) - { - fail( "Local artifact " + file + " should be present." ); - } + assertTrue( file.exists(), "Local artifact " + file + " should be present." ); } protected void assertRemoteArtifactNotPresent( Artifact artifact ) @@ -222,10 +189,7 @@ public abstract class AbstractArtifactComponentTestCase File file = new File( remoteRepo.getBasedir(), path ); - if ( file.exists() ) - { - fail( "Remote artifact " + file + " should not be present." ); - } + assertFalse( file.exists(), "Remote artifact " + file + " should not be present." ); } protected void assertLocalArtifactNotPresent( Artifact artifact ) @@ -237,10 +201,7 @@ public abstract class AbstractArtifactComponentTestCase File file = new File( localRepo.getBasedir(), path ); - if ( file.exists() ) - { - fail( "Local artifact " + file + " should not be present." ); - } + assertFalse( file.exists(), "Local artifact " + file + " should not be present." ); } // ---------------------------------------------------------------------- diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java index 30b1ab3396..05191ae684 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java @@ -25,6 +25,11 @@ import org.apache.maven.artifact.AbstractArtifactComponentTestCase; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.repository.ArtifactRepository; import org.codehaus.plexus.util.FileUtils; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import javax.inject.Inject; @@ -42,6 +47,7 @@ public class ArtifactDeployerTest return "deployer"; } + @Test public void testArtifactInstallation() throws Exception { diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/factory/DefaultArtifactFactoryTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/factory/DefaultArtifactFactoryTest.java index cee9f5a11d..6dcf99acb0 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/factory/DefaultArtifactFactoryTest.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/factory/DefaultArtifactFactoryTest.java @@ -19,19 +19,14 @@ package org.apache.maven.artifact.factory; * under the License. */ +import javax.inject.Inject; + +import org.apache.maven.test.PlexusTestCase; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.versioning.VersionRange; -import org.apache.maven.execution.DefaultMavenExecutionRequest; -import org.apache.maven.execution.DefaultMavenExecutionResult; -import org.apache.maven.execution.MavenSession; -import org.codehaus.plexus.ContainerConfiguration; -import org.codehaus.plexus.DefaultPlexusContainer; -import org.codehaus.plexus.PlexusConstants; -import org.codehaus.plexus.PlexusTestCase; -import org.eclipse.aether.RepositorySystemSession; +import org.junit.jupiter.api.Test; -import javax.inject.Inject; -import java.util.Collections; +import static org.junit.jupiter.api.Assertions.assertEquals; public class DefaultArtifactFactoryTest extends PlexusTestCase @@ -40,25 +35,7 @@ public class DefaultArtifactFactoryTest @Inject ArtifactFactory factory; - @Override - protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration ) - { - super.customizeContainerConfiguration( containerConfiguration ); - containerConfiguration.setAutoWiring( true ); - containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); - } - - @Override - protected void setUp() - throws Exception - { - super.setUp(); - - ((DefaultPlexusContainer)getContainer()) - .addPlexusInjector( Collections.emptyList(), - binder -> binder.requestInjection( this ) ); - } - + @Test public void testPropagationOfSystemScopeRegardlessOfInheritedScope() { Artifact artifact = factory.createDependencyArtifact( "test-grp", "test-artifact", VersionRange.createFromVersion("1.0"), "type", null, "system", "provided" ); diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/installer/ArtifactInstallerTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/installer/ArtifactInstallerTest.java index df519b3b25..695c5cc2e5 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/installer/ArtifactInstallerTest.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/installer/ArtifactInstallerTest.java @@ -23,6 +23,8 @@ import java.io.File; import org.apache.maven.artifact.AbstractArtifactComponentTestCase; import org.apache.maven.artifact.Artifact; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import javax.inject.Inject; @@ -40,6 +42,7 @@ public class ArtifactInstallerTest return "installer"; } + @Test public void testArtifactInstallation() throws Exception { diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/repository/MavenArtifactRepositoryTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/repository/MavenArtifactRepositoryTest.java index 533f304207..4e7b5dc8c1 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/repository/MavenArtifactRepositoryTest.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/repository/MavenArtifactRepositoryTest.java @@ -20,10 +20,12 @@ package org.apache.maven.artifact.repository; */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; public class MavenArtifactRepositoryTest - extends TestCase { private static class MavenArtifactRepositorySubclass extends MavenArtifactRepository { @@ -41,6 +43,7 @@ public class MavenArtifactRepositoryTest } } + @Test public void testHashCodeEquals() { MavenArtifactRepositorySubclass r1 = new MavenArtifactRepositorySubclass( "foo" ); diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolutionExceptionTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolutionExceptionTest.java index 8b75149c0c..e6b0e567a2 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolutionExceptionTest.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolutionExceptionTest.java @@ -22,7 +22,9 @@ package org.apache.maven.artifact.resolver; import java.util.Arrays; import java.util.List; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Test the artifact resolution exception message @@ -30,10 +32,10 @@ import junit.framework.TestCase; * @author Mauro Talevi */ public class ArtifactResolutionExceptionTest - extends TestCase { private static final String LS = System.lineSeparator(); + @Test public void testMissingArtifactMessageFormat() { String message = "Missing artifact"; diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java index 00c1344da5..d621d906e9 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java @@ -29,12 +29,18 @@ import java.util.Set; import org.apache.maven.artifact.AbstractArtifactComponentTestCase; import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.metadata.ResolutionGroup; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import javax.inject.Inject; @@ -55,8 +61,9 @@ public class ArtifactResolverTest private Artifact projectArtifact; + @BeforeEach @Override - protected void setUp() + public void setUp() throws Exception { super.setUp(); @@ -64,8 +71,9 @@ public class ArtifactResolverTest projectArtifact = createLocalArtifact( "project", "3.0" ); } + @AfterEach @Override - protected void tearDown() + public void tearDown() throws Exception { projectArtifact = null; @@ -78,6 +86,7 @@ public class ArtifactResolverTest return "resolver"; } + @Test public void testResolutionOfASingleArtifactWhereTheArtifactIsPresentInTheLocalRepository() throws Exception { @@ -88,6 +97,7 @@ public class ArtifactResolverTest assertLocalArtifactPresent( a ); } + @Test public void testResolutionOfASingleArtifactWhereTheArtifactIsNotPresentLocallyAndMustBeRetrievedFromTheRemoteRepository() throws Exception { @@ -105,6 +115,7 @@ public class ArtifactResolverTest return super.createArtifact( groupId, artifactId, version, type ); } + @Test public void testTransitiveResolutionWhereAllArtifactsArePresentInTheLocalRepository() throws Exception { @@ -127,6 +138,7 @@ public class ArtifactResolverTest assertLocalArtifactPresent( h ); } + @Test public void testTransitiveResolutionWhereAllArtifactsAreNotPresentInTheLocalRepositoryAndMustBeRetrievedFromTheRemoteRepository() throws Exception { @@ -151,22 +163,19 @@ public class ArtifactResolverTest assertLocalArtifactPresent( j ); } + @Test public void testResolutionFailureWhenArtifactNotPresentInRemoteRepository() throws Exception { Artifact k = createArtifact( "k", "1.0" ); - try - { - artifactResolver.resolve( k, remoteRepositories(), localRepository() ); - fail( "Resolution succeeded when it should have failed" ); - } - catch ( ArtifactNotFoundException expected ) - { - assertTrue( true ); - } + assertThrows( + ArtifactNotFoundException.class, + () -> artifactResolver.resolve( k, remoteRepositories(), localRepository() ), + "Resolution succeeded when it should have failed" ); } + @Test public void testResolutionOfAnArtifactWhereOneRemoteRepositoryIsBadButOneIsGood() throws Exception { @@ -182,6 +191,7 @@ public class ArtifactResolverTest assertLocalArtifactPresent( l ); } + @Test public void testTransitiveResolutionOrder() throws Exception { @@ -237,8 +247,8 @@ public class ArtifactResolverTest printErrors( result ); Iterator i = result.getArtifacts().iterator(); - assertEquals( "n should be first", n, i.next() ); - assertEquals( "m should be second", m, i.next() ); + assertEquals( n, i.next(), "n should be first" ); + assertEquals( m, i.next(), "m should be second" ); // inverse order set = new LinkedHashSet<>(); @@ -251,8 +261,8 @@ public class ArtifactResolverTest printErrors( result ); i = result.getArtifacts().iterator(); - assertEquals( "m should be first", m, i.next() ); - assertEquals( "n should be second", n, i.next() ); + assertEquals( m, i.next(), "m should be first" ); + assertEquals( n, i.next(), "n should be second" ); } private void printErrors( ArtifactResolutionResult result ) diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactResolverTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactResolverTest.java index 9e221eeef7..fdd5f62bcf 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactResolverTest.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactResolverTest.java @@ -24,6 +24,11 @@ import java.util.Collections; import org.apache.maven.artifact.AbstractArtifactComponentTestCase; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.resolver.DefaultArtifactResolver.DaemonThreadCreator; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertTrue; import javax.inject.Inject; @@ -35,16 +40,18 @@ public class DefaultArtifactResolverTest private Artifact projectArtifact; + @BeforeEach @Override - protected void setUp() + public void setUp() throws Exception { super.setUp(); projectArtifact = createLocalArtifact( "project", "3.0" ); } + @AfterEach @Override - protected void tearDown() + public void tearDown() throws Exception { projectArtifact = null; @@ -57,6 +64,7 @@ public class DefaultArtifactResolverTest return "resolver"; } + @Test public void testMNG4738() throws Exception { @@ -94,14 +102,15 @@ public class DefaultArtifactResolverTest { String name = active.getName(); boolean daemon = active.isDaemon(); - assertTrue( name + " is no daemon Thread.", daemon ); + assertTrue( daemon, name + " is no daemon Thread." ); } } - assertTrue( "Could not find ThreadGroup: " + DaemonThreadCreator.THREADGROUP_NAME, seen ); + assertTrue( seen, "Could not find ThreadGroup: " + DaemonThreadCreator.THREADGROUP_NAME ); } + @Test public void testLookup() throws Exception { diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/AndArtifactFilterTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/AndArtifactFilterTest.java index 50517f4e20..96a8882232 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/AndArtifactFilterTest.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/AndArtifactFilterTest.java @@ -21,7 +21,11 @@ package org.apache.maven.artifact.resolver.filter; import java.util.Arrays; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@link AndArtifactFilter}. @@ -29,7 +33,6 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class AndArtifactFilterTest - extends TestCase { private ArtifactFilter newSubFilter() @@ -37,6 +40,7 @@ public class AndArtifactFilterTest return artifact -> false; } + @Test public void testEquals() { AndArtifactFilter filter1 = new AndArtifactFilter(); diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/FilterHashEqualsTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/FilterHashEqualsTest.java index fb4656637e..6c3df9e900 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/FilterHashEqualsTest.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/FilterHashEqualsTest.java @@ -22,15 +22,17 @@ package org.apache.maven.artifact.resolver.filter; import java.util.Arrays; import java.util.List; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Igor Fedorenko */ public class FilterHashEqualsTest - extends TestCase { + @Test public void testIncludesExcludesArtifactFilter() { List patterns = Arrays.asList( "c", "d", "e" ); diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/OrArtifactFilterTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/OrArtifactFilterTest.java index 5971cc3823..65d9caa2b2 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/OrArtifactFilterTest.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/OrArtifactFilterTest.java @@ -21,7 +21,11 @@ package org.apache.maven.artifact.resolver.filter; import java.util.Arrays; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@link OrArtifactFilter}. @@ -29,7 +33,6 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class OrArtifactFilterTest - extends TestCase { private ArtifactFilter newSubFilter() @@ -37,6 +40,7 @@ public class OrArtifactFilterTest return artifact -> false; } + @Test public void testEquals() { OrArtifactFilter filter1 = new OrArtifactFilter(); diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/ScopeArtifactFilterTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/ScopeArtifactFilterTest.java index 1a65eca082..914ff99bcb 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/ScopeArtifactFilterTest.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/ScopeArtifactFilterTest.java @@ -21,8 +21,10 @@ package org.apache.maven.artifact.resolver.filter; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DefaultArtifact; +import org.junit.jupiter.api.Test; -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@link ScopeArtifactFilter}. @@ -30,7 +32,6 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class ScopeArtifactFilterTest - extends TestCase { private Artifact newArtifact( String scope ) @@ -38,6 +39,7 @@ public class ScopeArtifactFilterTest return new DefaultArtifact( "g", "a", "1.0", scope, "jar", "", null ); } + @Test public void testInclude_Compile() { ScopeArtifactFilter filter = new ScopeArtifactFilter( Artifact.SCOPE_COMPILE ); @@ -49,6 +51,7 @@ public class ScopeArtifactFilterTest assertFalse( filter.include( newArtifact( Artifact.SCOPE_TEST ) ) ); } + @Test public void testInclude_CompilePlusRuntime() { ScopeArtifactFilter filter = new ScopeArtifactFilter( Artifact.SCOPE_COMPILE_PLUS_RUNTIME ); @@ -60,6 +63,7 @@ public class ScopeArtifactFilterTest assertFalse( filter.include( newArtifact( Artifact.SCOPE_TEST ) ) ); } + @Test public void testInclude_Runtime() { ScopeArtifactFilter filter = new ScopeArtifactFilter( Artifact.SCOPE_RUNTIME ); @@ -71,6 +75,7 @@ public class ScopeArtifactFilterTest assertFalse( filter.include( newArtifact( Artifact.SCOPE_TEST ) ) ); } + @Test public void testInclude_RuntimePlusSystem() { ScopeArtifactFilter filter = new ScopeArtifactFilter( Artifact.SCOPE_RUNTIME_PLUS_SYSTEM ); @@ -82,6 +87,7 @@ public class ScopeArtifactFilterTest assertFalse( filter.include( newArtifact( Artifact.SCOPE_TEST ) ) ); } + @Test public void testInclude_Test() { ScopeArtifactFilter filter = new ScopeArtifactFilter( Artifact.SCOPE_TEST ); diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/testutils/TestFileManager.java b/maven-compat/src/test/java/org/apache/maven/artifact/testutils/TestFileManager.java index 9761e75e52..558b5a5ca3 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/testutils/TestFileManager.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/testutils/TestFileManager.java @@ -45,7 +45,10 @@ import java.util.Iterator; import java.util.List; import org.codehaus.plexus.util.FileUtils; -import org.junit.Assert; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TestFileManager { @@ -157,11 +160,11 @@ public class TestFileManager if ( shouldExist ) { - Assert.assertTrue( file.exists() ); + assertTrue( file.exists() ); } else { - Assert.assertFalse( file.exists() ); + assertFalse( file.exists() ); } } @@ -174,7 +177,7 @@ public class TestFileManager String contents = FileUtils.fileRead( file, encoding ); - Assert.assertEquals( contentsTest, contents ); + assertEquals( contentsTest, contents ); } public File createFile( File dir, String filename, String contents, String encoding ) diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/transform/TransformationManagerTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/transform/TransformationManagerTest.java index ff0d3bbfa1..5c1ae2d289 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/transform/TransformationManagerTest.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/transform/TransformationManagerTest.java @@ -15,7 +15,6 @@ package org.apache.maven.artifact.transform; * the License. */ -import java.util.Collections; import java.util.List; import org.apache.maven.repository.legacy.resolver.transform.ArtifactTransformation; @@ -23,10 +22,11 @@ import org.apache.maven.repository.legacy.resolver.transform.ArtifactTransformat import org.apache.maven.repository.legacy.resolver.transform.LatestArtifactTransformation; import org.apache.maven.repository.legacy.resolver.transform.ReleaseArtifactTransformation; import org.apache.maven.repository.legacy.resolver.transform.SnapshotTransformation; -import org.codehaus.plexus.ContainerConfiguration; -import org.codehaus.plexus.DefaultPlexusContainer; -import org.codehaus.plexus.PlexusConstants; -import org.codehaus.plexus.PlexusTestCase; +import org.apache.maven.test.PlexusTestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import javax.inject.Inject; @@ -37,36 +37,18 @@ public class TransformationManagerTest @Inject ArtifactTransformationManager tm; - @Override - protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration ) - { - super.customizeContainerConfiguration( containerConfiguration ); - containerConfiguration.setAutoWiring( true ); - containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); - } - - @Override - protected void setUp() - throws Exception - { - super.setUp(); - - ((DefaultPlexusContainer)getContainer()) - .addPlexusInjector( Collections.emptyList(), - binder -> binder.requestInjection( this ) ); - } - + @Test public void testTransformationManager() { List tms = tm.getArtifactTransformations(); assertEquals( 3, tms.size() ); - assertTrue( "We expected the release transformation and got " + tms.get(0), tms.get(0) instanceof ReleaseArtifactTransformation ); + assertTrue( tms.get(0) instanceof ReleaseArtifactTransformation, "We expected the release transformation and got " + tms.get(0) ); - assertTrue( "We expected the latest transformation and got " + tms.get(1), tms.get(1) instanceof LatestArtifactTransformation ); + assertTrue( tms.get(1) instanceof LatestArtifactTransformation, "We expected the latest transformation and got " + tms.get(1) ); - assertTrue( "We expected the snapshot transformation and got " + tms.get(2), tms.get(2) instanceof SnapshotTransformation ); + assertTrue( tms.get(2) instanceof SnapshotTransformation, "We expected the snapshot transformation and got " + tms.get(2) ); } } diff --git a/maven-compat/src/test/java/org/apache/maven/profiles/manager/DefaultProfileManagerTest.java b/maven-compat/src/test/java/org/apache/maven/profiles/manager/DefaultProfileManagerTest.java index 6b8caabf0f..442493a64c 100644 --- a/maven-compat/src/test/java/org/apache/maven/profiles/manager/DefaultProfileManagerTest.java +++ b/maven-compat/src/test/java/org/apache/maven/profiles/manager/DefaultProfileManagerTest.java @@ -19,36 +19,25 @@ package org.apache.maven.profiles.manager; * under the License. */ -import java.util.Collections; import java.util.List; import java.util.Properties; -import org.apache.maven.execution.DefaultMavenExecutionRequest; -import org.apache.maven.execution.DefaultMavenExecutionResult; -import org.apache.maven.execution.MavenSession; +import org.apache.maven.test.PlexusTestCase; import org.apache.maven.model.Activation; import org.apache.maven.model.ActivationProperty; import org.apache.maven.model.Profile; import org.apache.maven.profiles.DefaultProfileManager; import org.apache.maven.profiles.ProfileManager; -import org.codehaus.plexus.ContainerConfiguration; -import org.codehaus.plexus.DefaultPlexusContainer; -import org.codehaus.plexus.PlexusConstants; -import org.codehaus.plexus.PlexusTestCase; -import org.eclipse.aether.RepositorySystemSession; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class DefaultProfileManagerTest extends PlexusTestCase { - @Override - protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration ) - { - super.customizeContainerConfiguration( containerConfiguration ); - containerConfiguration.setAutoWiring( true ); - containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); - } - + @Test public void testShouldActivateDefaultProfile() throws Exception { @@ -84,6 +73,7 @@ public class DefaultProfileManagerTest assertEquals( "defaultActivated", ( (Profile) active.get( 0 ) ).getId() ); } + @Test public void testShouldNotActivateDefaultProfile() throws Exception { @@ -123,6 +113,7 @@ public class DefaultProfileManagerTest } + @Test public void testShouldNotActivateReversalOfPresentSystemProperty() throws Exception { @@ -150,6 +141,7 @@ public class DefaultProfileManagerTest assertEquals( 0, active.size() ); } + @Test public void testShouldOverrideAndActivateInactiveProfile() throws Exception { @@ -180,6 +172,7 @@ public class DefaultProfileManagerTest assertEquals( "syspropActivated", ( (Profile) active.get( 0 ) ).getId() ); } + @Test public void testShouldOverrideAndDeactivateActiveProfile() throws Exception { diff --git a/maven-compat/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java b/maven-compat/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java index d05aa8f59a..338cffa6a0 100644 --- a/maven-compat/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java +++ b/maven-compat/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java @@ -21,25 +21,21 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.util.Arrays; -import java.util.Collections; +import javax.inject.Inject; + +import org.apache.maven.test.PlexusTestCase; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; -import org.apache.maven.execution.DefaultMavenExecutionRequest; -import org.apache.maven.execution.DefaultMavenExecutionResult; -import org.apache.maven.execution.MavenSession; import org.apache.maven.model.building.ModelBuildingException; import org.apache.maven.model.building.ModelProblem; import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.internal.MavenRepositorySystemUtils; -import org.codehaus.plexus.ContainerConfiguration; -import org.codehaus.plexus.DefaultPlexusContainer; -import org.codehaus.plexus.PlexusConstants; -import org.codehaus.plexus.PlexusTestCase; import org.eclipse.aether.DefaultRepositorySystemSession; -import org.eclipse.aether.RepositorySystemSession; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; -import javax.inject.Inject; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Jason van Zyl @@ -53,23 +49,12 @@ public abstract class AbstractMavenProjectTestCase protected RepositorySystem repositorySystem; @Override - protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration ) - { - super.customizeContainerConfiguration( containerConfiguration ); - containerConfiguration.setAutoWiring( true ); - containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); - } - - @Override - protected void setUp() - throws Exception + @BeforeEach + public void setUp() + throws Exception { super.setUp(); - ((DefaultPlexusContainer)getContainer()) - .addPlexusInjector( Collections.emptyList(), - binder -> binder.requestInjection( this ) ); - if ( getContainer().hasComponent( ProjectBuilder.class, "test" ) ) { projectBuilder = lookup( ProjectBuilder.class, "test" ); @@ -81,8 +66,8 @@ public abstract class AbstractMavenProjectTestCase } } - @Override - protected void tearDown() + @AfterEach + public void tearDown() throws Exception { projectBuilder = null; diff --git a/maven-compat/src/test/java/org/apache/maven/project/ModelUtilsTest.java b/maven-compat/src/test/java/org/apache/maven/project/ModelUtilsTest.java index 402ae74b91..74178d98c3 100644 --- a/maven-compat/src/test/java/org/apache/maven/project/ModelUtilsTest.java +++ b/maven-compat/src/test/java/org/apache/maven/project/ModelUtilsTest.java @@ -26,8 +26,6 @@ import java.util.Collections; import java.util.List; import java.util.Map; -import junit.framework.TestCase; - import org.apache.maven.model.Build; import org.apache.maven.model.Dependency; import org.apache.maven.model.Plugin; @@ -36,11 +34,17 @@ import org.apache.maven.model.PluginExecution; import org.codehaus.plexus.util.xml.Xpp3Dom; import org.codehaus.plexus.util.xml.Xpp3DomBuilder; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; public class ModelUtilsTest - extends TestCase { + @Test public void testShouldUseMainPluginDependencyVersionOverManagedDepVersion() { Plugin mgtPlugin = createPlugin( "group", "artifact", "1", Collections.EMPTY_MAP ); @@ -68,6 +72,7 @@ public class ModelUtilsTest return dep; } + @Test public void testShouldNotInheritPluginWithInheritanceSetToFalse() { PluginContainer parent = new PluginContainer(); @@ -108,6 +113,7 @@ public class ModelUtilsTest * X -> Y -> A -> B -> C -> D -> E -> F * */ + @Test public void testShouldPreserveChildOrderingOfPluginsAfterParentMerge() { PluginContainer parent = new PluginContainer(); @@ -176,6 +182,7 @@ public class ModelUtilsTest return plugin; } + @Test public void testShouldInheritOnePluginWithExecution() { Plugin parent = new Plugin(); @@ -198,6 +205,7 @@ public class ModelUtilsTest assertEquals( 1, child.getExecutions().size() ); } + @Test public void testShouldMergeInheritedPluginHavingExecutionWithLocalPlugin() { Plugin parent = new Plugin(); @@ -225,6 +233,7 @@ public class ModelUtilsTest assertEquals( 2, child.getExecutions().size() ); } + @Test public void testShouldMergeOnePluginWithInheritExecutionWithoutDuplicatingPluginInList() { Plugin parent = new Plugin(); @@ -259,6 +268,7 @@ public class ModelUtilsTest assertEquals( 1, plugin.getExecutions().size() ); } + @Test public void testShouldMergePluginWithDifferentExecutionFromParentWithoutDuplicatingPluginInList() { Plugin parent = new Plugin(); @@ -299,6 +309,7 @@ public class ModelUtilsTest assertEquals( 2, plugin.getExecutions().size() ); } + @Test public void testShouldNOTMergeInheritedPluginHavingInheritEqualFalse() { Plugin parent = new Plugin(); @@ -326,6 +337,7 @@ public class ModelUtilsTest * Verifies MNG-1499: The order of the merged list should be the plugins specified by the parent followed by the * child list. */ + @Test public void testShouldKeepOriginalPluginOrdering() { Plugin parentPlugin1 = new Plugin(); @@ -390,6 +402,7 @@ public class ModelUtilsTest /** * Verifies MNG-1499: The ordering of plugin executions should also be in the specified order. */ + @Test public void testShouldKeepOriginalPluginExecutionOrdering() { Plugin parent = new Plugin(); @@ -439,6 +452,7 @@ public class ModelUtilsTest assertEquals( dep.getManagementKey(), dep2.getManagementKey() ); } + @Test public void testShouldOverwritePluginConfigurationSubItemsByDefault() throws XmlPullParserException, IOException { @@ -465,6 +479,7 @@ public class ModelUtilsTest assertEquals( "three", item.getValue() ); } + @Test public void testShouldMergePluginConfigurationSubItemsWithMergeAttributeSet() throws XmlPullParserException, IOException { @@ -496,6 +511,7 @@ public class ModelUtilsTest assertEquals( expected, actual ); } + @Test public void testShouldNotMergePluginExecutionWhenExecInheritedIsFalseAndTreatAsInheritanceIsTrue() { String gid = "group"; @@ -533,9 +549,10 @@ public class ModelUtilsTest ModelUtils.mergePluginDefinitions( pChild, pParent, true ); Map executionMap = pChild.getExecutionsAsMap(); - assertNull( "test execution should not be inherited from parent.", executionMap.get( testId ) ); + assertNull( executionMap.get( testId ), "test execution should not be inherited from parent." ); } + @Test public void testShouldNotMergePluginExecutionWhenPluginInheritedIsFalseAndTreatAsInheritanceIsTrue() { String gid = "group"; @@ -573,9 +590,10 @@ public class ModelUtilsTest ModelUtils.mergePluginDefinitions( pChild, pParent, true ); Map executionMap = pChild.getExecutionsAsMap(); - assertNull( "test execution should not be inherited from parent.", executionMap.get( testId ) ); + assertNull( executionMap.get( testId ), "test execution should not be inherited from parent." ); } + @Test public void testShouldMergePluginExecutionWhenExecInheritedIsTrueAndTreatAsInheritanceIsTrue() { String gid = "group"; @@ -613,7 +631,7 @@ public class ModelUtilsTest ModelUtils.mergePluginDefinitions( pChild, pParent, true ); Map executionMap = pChild.getExecutionsAsMap(); - assertNotNull( "test execution should be inherited from parent.", executionMap.get( testId ) ); + assertNotNull( executionMap.get( testId ), "test execution should be inherited from parent." ); } } diff --git a/maven-compat/src/test/java/org/apache/maven/project/ProjectClasspathTest.java b/maven-compat/src/test/java/org/apache/maven/project/ProjectClasspathTest.java index 96f1feaa94..0cc449f863 100644 --- a/maven-compat/src/test/java/org/apache/maven/project/ProjectClasspathTest.java +++ b/maven-compat/src/test/java/org/apache/maven/project/ProjectClasspathTest.java @@ -20,20 +20,17 @@ package org.apache.maven.project; */ import java.io.File; -import java.util.Collections; import org.apache.maven.artifact.Artifact; -import org.apache.maven.execution.DefaultMavenExecutionRequest; -import org.apache.maven.execution.DefaultMavenExecutionResult; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.internal.DefaultArtifactDescriptorReader; -import org.codehaus.plexus.ContainerConfiguration; -import org.codehaus.plexus.DefaultPlexusContainer; -import org.codehaus.plexus.PlexusConstants; -import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.impl.ArtifactDescriptorReader; import org.eclipse.aether.impl.ArtifactResolver; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; public class ProjectClasspathTest extends AbstractMavenProjectTestCase @@ -41,23 +38,12 @@ public class ProjectClasspathTest static final String dir = "projects/scope/"; @Override - protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration ) - { - super.customizeContainerConfiguration( containerConfiguration ); - containerConfiguration.setAutoWiring( true ); - containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); - } - - @Override - protected void setUp() + @BeforeEach + public void setUp() throws Exception { super.setUp(); - ((DefaultPlexusContainer)getContainer()) - .addPlexusInjector( Collections.emptyList(), - binder -> binder.requestInjection( this ) ); - ArtifactResolver resolver = lookup( ArtifactResolver.class, "classpath" ); DefaultArtifactDescriptorReader pomReader = (DefaultArtifactDescriptorReader)lookup(ArtifactDescriptorReader.class); pomReader.setArtifactResolver( resolver ); @@ -71,6 +57,7 @@ public class ProjectClasspathTest return null; } + @Test public void testProjectClasspath() throws Exception { @@ -80,7 +67,7 @@ public class ProjectClasspathTest Artifact artifact; - assertNotNull( "Test project can't be null!", project ); + assertNotNull( project, "Test project can't be null!" ); checkArtifactIdScope( project, "provided", "provided" ); checkArtifactIdScope( project, "test", "test" ); @@ -90,53 +77,53 @@ public class ProjectClasspathTest // check all transitive deps of a test dependency are test, except test and provided which is skipped artifact = getArtifact( project, "maven-test-test", "scope-provided" ); - assertNull( "Check no provided dependencies are transitive", artifact ); + assertNull( artifact, "Check no provided dependencies are transitive" ); artifact = getArtifact( project, "maven-test-test", "scope-test" ); - assertNull( "Check no test dependencies are transitive", artifact ); + assertNull( artifact, "Check no test dependencies are transitive" ); artifact = getArtifact( project, "maven-test-test", "scope-compile" ); assertNotNull( artifact ); System.out.println( "a = " + artifact ); System.out.println( "b = " + artifact.getScope() ); - assertEquals( "Check scope", "test", artifact.getScope() ); + assertEquals( "test", artifact.getScope(), "Check scope" ); artifact = getArtifact( project, "maven-test-test", "scope-default" ); - assertEquals( "Check scope", "test", artifact.getScope() ); + assertEquals( "test", artifact.getScope(), "Check scope" ); artifact = getArtifact( project, "maven-test-test", "scope-runtime" ); - assertEquals( "Check scope", "test", artifact.getScope() ); + assertEquals( "test", artifact.getScope(), "Check scope" ); // check all transitive deps of a provided dependency are provided scope, except for test checkGroupIdScope( project, "provided", "maven-test-provided" ); artifact = getArtifact( project, "maven-test-provided", "scope-runtime" ); - assertEquals( "Check scope", "provided", artifact.getScope() ); + assertEquals( "provided", artifact.getScope(), "Check scope" ); // check all transitive deps of a runtime dependency are runtime scope, except for test checkGroupIdScope( project, "runtime", "maven-test-runtime" ); artifact = getArtifact( project, "maven-test-runtime", "scope-runtime" ); - assertEquals( "Check scope", "runtime", artifact.getScope() ); + assertEquals( "runtime", artifact.getScope(), "Check scope" ); // check all transitive deps of a compile dependency are compile scope, except for runtime and test checkGroupIdScope( project, "compile", "maven-test-compile" ); artifact = getArtifact( project, "maven-test-compile", "scope-runtime" ); - assertEquals( "Check scope", "runtime", artifact.getScope() ); + assertEquals( "runtime", artifact.getScope(), "Check scope" ); // check all transitive deps of a default dependency are compile scope, except for runtime and test checkGroupIdScope( project, "compile", "maven-test-default" ); artifact = getArtifact( project, "maven-test-default", "scope-runtime" ); - assertEquals( "Check scope", "runtime", artifact.getScope() ); + assertEquals( "runtime", artifact.getScope(), "Check scope" ); } private void checkGroupIdScope( MavenProject project, String scopeValue, String groupId ) { Artifact artifact; artifact = getArtifact( project, groupId, "scope-compile" ); - assertEquals( "Check scope", scopeValue, artifact.getScope() ); + assertEquals( scopeValue, artifact.getScope(), "Check scope" ); artifact = getArtifact( project, groupId, "scope-test" ); - assertNull( "Check test dependency is not transitive", artifact ); + assertNull( artifact, "Check test dependency is not transitive" ); artifact = getArtifact( project, groupId, "scope-provided" ); - assertNull( "Check provided dependency is not transitive", artifact ); + assertNull( artifact, "Check provided dependency is not transitive" ); artifact = getArtifact( project, groupId, "scope-default" ); - assertEquals( "Check scope", scopeValue, artifact.getScope() ); + assertEquals( scopeValue, artifact.getScope(), "Check scope" ); } private void checkArtifactIdScope( MavenProject project, String scope, String scopeValue ) @@ -144,7 +131,7 @@ public class ProjectClasspathTest String artifactId = "scope-" + scope; Artifact artifact = getArtifact( project, "maven-test", artifactId ); assertNotNull( artifact ); - assertEquals( "Check scope", scopeValue, artifact.getScope() ); + assertEquals( scopeValue, artifact.getScope(), "Check scope" ); } private Artifact getArtifact( MavenProject project, String groupId, String artifactId ) diff --git a/maven-compat/src/test/java/org/apache/maven/project/inheritance/t00/ProjectInheritanceTest.java b/maven-compat/src/test/java/org/apache/maven/project/inheritance/t00/ProjectInheritanceTest.java index 98da0f5aa4..936424dbac 100644 --- a/maven-compat/src/test/java/org/apache/maven/project/inheritance/t00/ProjectInheritanceTest.java +++ b/maven-compat/src/test/java/org/apache/maven/project/inheritance/t00/ProjectInheritanceTest.java @@ -21,6 +21,9 @@ package org.apache.maven.project.inheritance.t00; import org.apache.maven.project.MavenProject; import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; /** * A test which demonstrates maven's recursive inheritance where @@ -50,6 +53,7 @@ public class ProjectInheritanceTest // // ---------------------------------------------------------------------- + @Test public void testProjectInheritance() throws Exception { diff --git a/maven-compat/src/test/java/org/apache/maven/project/inheritance/t01/ProjectInheritanceTest.java b/maven-compat/src/test/java/org/apache/maven/project/inheritance/t01/ProjectInheritanceTest.java index 1aa749b598..8f8199e9c1 100644 --- a/maven-compat/src/test/java/org/apache/maven/project/inheritance/t01/ProjectInheritanceTest.java +++ b/maven-compat/src/test/java/org/apache/maven/project/inheritance/t01/ProjectInheritanceTest.java @@ -21,6 +21,9 @@ package org.apache.maven.project.inheritance.t01; import org.apache.maven.project.MavenProject; import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; /** * A test which demonstrates maven's recursive inheritance where @@ -46,6 +49,7 @@ public class ProjectInheritanceTest // // ---------------------------------------------------------------------- + @Test public void testProjectInheritance() throws Exception { diff --git a/maven-compat/src/test/java/org/apache/maven/project/inheritance/t02/ProjectInheritanceTest.java b/maven-compat/src/test/java/org/apache/maven/project/inheritance/t02/ProjectInheritanceTest.java index 2b783431ce..61a393238b 100644 --- a/maven-compat/src/test/java/org/apache/maven/project/inheritance/t02/ProjectInheritanceTest.java +++ b/maven-compat/src/test/java/org/apache/maven/project/inheritance/t02/ProjectInheritanceTest.java @@ -26,8 +26,14 @@ import java.util.Map; import org.apache.maven.model.Build; import org.apache.maven.model.Plugin; +import org.apache.maven.model.PluginExecution; import org.apache.maven.project.MavenProject; import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * A test which demonstrates maven's recursive inheritance where @@ -57,6 +63,7 @@ public class ProjectInheritanceTest // // ---------------------------------------------------------------------- + @Test public void testProjectInheritance() throws Exception { @@ -134,33 +141,25 @@ public class ProjectInheritanceTest { String pluginArtifactId = plugin.getArtifactId(); - if ( !validPluginCounts.containsKey( pluginArtifactId ) ) + assertTrue( validPluginCounts.containsKey( pluginArtifactId ), "Illegal plugin found: " + pluginArtifactId ); + + if ( pluginArtifactId.equals( testPluginArtifactId ) ) { - fail( "Illegal plugin found: " + pluginArtifactId ); + testPlugin = plugin; } - else - { - if ( pluginArtifactId.equals( testPluginArtifactId ) ) - { - testPlugin = plugin; - } - Integer count = validPluginCounts.get( pluginArtifactId ); + Integer count = validPluginCounts.get( pluginArtifactId ); - if ( count > 0 ) - { - fail( "Multiple copies of plugin: " + pluginArtifactId + " found in POM." ); - } - else - { - count = count + 1; + assertEquals( 0, (int) count, "Multiple copies of plugin: " + pluginArtifactId + " found in POM." ); - validPluginCounts.put( pluginArtifactId, count ); - } - } + count = count + 1; + + validPluginCounts.put( pluginArtifactId, count ); } - List executions = testPlugin.getExecutions(); + assertNotNull( testPlugin ); + + List executions = testPlugin.getExecutions(); assertEquals( 1, executions.size() ); } diff --git a/maven-compat/src/test/java/org/apache/maven/project/inheritance/t03/ProjectInheritanceTest.java b/maven-compat/src/test/java/org/apache/maven/project/inheritance/t03/ProjectInheritanceTest.java index edb6107ac9..3c658d8dbd 100644 --- a/maven-compat/src/test/java/org/apache/maven/project/inheritance/t03/ProjectInheritanceTest.java +++ b/maven-compat/src/test/java/org/apache/maven/project/inheritance/t03/ProjectInheritanceTest.java @@ -23,6 +23,9 @@ import java.io.File; import org.apache.maven.project.MavenProject; import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; /** * A test which demonstrates maven's recursive inheritance where @@ -49,6 +52,7 @@ public class ProjectInheritanceTest // // ---------------------------------------------------------------------- + @Test public void testProjectInheritance() throws Exception { diff --git a/maven-compat/src/test/java/org/apache/maven/project/inheritance/t04/ProjectInheritanceTest.java b/maven-compat/src/test/java/org/apache/maven/project/inheritance/t04/ProjectInheritanceTest.java index ab775ec1d6..34a31d5e21 100644 --- a/maven-compat/src/test/java/org/apache/maven/project/inheritance/t04/ProjectInheritanceTest.java +++ b/maven-compat/src/test/java/org/apache/maven/project/inheritance/t04/ProjectInheritanceTest.java @@ -25,6 +25,11 @@ import java.util.Set; import org.apache.maven.artifact.Artifact; import org.apache.maven.project.MavenProject; import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Verifies the version of a dependency listed in a parent's @@ -51,6 +56,7 @@ public class ProjectInheritanceTest // // ---------------------------------------------------------------------- + @Test public void testDependencyManagementOverridesTransitiveDependencyVersion() throws Exception { @@ -65,9 +71,9 @@ public class ProjectInheritanceTest assertEquals( pom0Basedir, project1.getParent().getBasedir() ); Set set = project1.getArtifacts(); - assertNotNull( "No artifacts", set ); - assertTrue( "No Artifacts", set.size() > 0 ); - assertTrue( "Set size should be 3, is " + set.size(), set.size() == 3 ); + assertNotNull( set, "No artifacts" ); + assertTrue( set.size() > 0, "No Artifacts" ); + assertTrue( set.size() == 3, "Set size should be 3, is " + set.size() ); for ( Object aSet : set ) { @@ -77,8 +83,8 @@ public class ProjectInheritanceTest artifact.isOptional() ? "true" : "false" ) ); - assertTrue( "Incorrect version for " + artifact.getDependencyConflictId(), - artifact.getVersion().equals( "1.0" ) ); + assertTrue( artifact.getVersion().equals( "1.0" ), + "Incorrect version for " + artifact.getDependencyConflictId() ); } } diff --git a/maven-compat/src/test/java/org/apache/maven/project/inheritance/t05/ProjectInheritanceTest.java b/maven-compat/src/test/java/org/apache/maven/project/inheritance/t05/ProjectInheritanceTest.java index 1517157033..8af4a2fdf7 100644 --- a/maven-compat/src/test/java/org/apache/maven/project/inheritance/t05/ProjectInheritanceTest.java +++ b/maven-compat/src/test/java/org/apache/maven/project/inheritance/t05/ProjectInheritanceTest.java @@ -25,6 +25,11 @@ import java.util.Set; import org.apache.maven.artifact.Artifact; import org.apache.maven.project.MavenProject; import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * A test which demonstrates maven's dependency management @@ -45,6 +50,7 @@ public class ProjectInheritanceTest // // ---------------------------------------------------------------------- + @Test public void testDependencyManagement() throws Exception { @@ -61,8 +67,8 @@ public class ProjectInheritanceTest assertEquals( pom0Basedir, project1.getParent().getBasedir() ); Set set = project1.getArtifacts(); - assertNotNull( "No artifacts", set ); - assertTrue( "No Artifacts", set.size() > 0 ); + assertNotNull( set, "No artifacts" ); + assertTrue( set.size() > 0, "No Artifacts" ); for ( Object aSet : set ) { @@ -70,8 +76,8 @@ public class ProjectInheritanceTest System.out.println( "Artifact: " + artifact.getDependencyConflictId() + " " + artifact.getVersion() + " Scope: " + artifact.getScope() ); - assertTrue( "Incorrect version for " + artifact.getDependencyConflictId(), - artifact.getVersion().equals( "1.0" ) ); + assertTrue( artifact.getVersion().equals( "1.0" ), + "Incorrect version for " + artifact.getDependencyConflictId() ); } } diff --git a/maven-compat/src/test/java/org/apache/maven/project/inheritance/t06/ProjectInheritanceTest.java b/maven-compat/src/test/java/org/apache/maven/project/inheritance/t06/ProjectInheritanceTest.java index 60e37719a2..bc37066a05 100644 --- a/maven-compat/src/test/java/org/apache/maven/project/inheritance/t06/ProjectInheritanceTest.java +++ b/maven-compat/src/test/java/org/apache/maven/project/inheritance/t06/ProjectInheritanceTest.java @@ -26,6 +26,11 @@ import java.util.Set; import org.apache.maven.artifact.Artifact; import org.apache.maven.project.MavenProject; import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * A test which demonstrates maven's dependency management @@ -46,6 +51,7 @@ public class ProjectInheritanceTest // // ---------------------------------------------------------------------- + @Test public void testDependencyManagement() throws Exception { @@ -62,18 +68,18 @@ public class ProjectInheritanceTest assertEquals( pom0Basedir, project1.getParent().getBasedir() ); Set set = project1.getArtifacts(); - assertNotNull( "No artifacts", set ); - assertTrue( "No Artifacts", set.size() > 0 ); + assertNotNull( set, "No artifacts" ); + assertTrue( set.size() > 0, "No Artifacts" ); Iterator iter = set.iterator(); - assertTrue( "Set size should be 4, is " + set.size(), set.size() == 4 ); + assertTrue( set.size() == 4, "Set size should be 4, is " + set.size() ); while ( iter.hasNext() ) { Artifact artifact = (Artifact) iter.next(); System.out.println( "Artifact: " + artifact.getDependencyConflictId() + " " + artifact.getVersion() + " Optional=" + ( artifact.isOptional() ? "true" : "false" ) ); - assertTrue( "Incorrect version for " + artifact.getDependencyConflictId(), - artifact.getVersion().equals( "1.0" ) ); + assertTrue( artifact.getVersion().equals( "1.0" ), + "Incorrect version for " + artifact.getDependencyConflictId() ); } } diff --git a/maven-compat/src/test/java/org/apache/maven/project/inheritance/t07/ProjectInheritanceTest.java b/maven-compat/src/test/java/org/apache/maven/project/inheritance/t07/ProjectInheritanceTest.java index b9685e39a6..87b07d3a80 100644 --- a/maven-compat/src/test/java/org/apache/maven/project/inheritance/t07/ProjectInheritanceTest.java +++ b/maven-compat/src/test/java/org/apache/maven/project/inheritance/t07/ProjectInheritanceTest.java @@ -25,6 +25,12 @@ import java.util.Set; import org.apache.maven.artifact.Artifact; import org.apache.maven.project.MavenProject; import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * A test which demonstrates maven's dependency management @@ -45,6 +51,7 @@ public class ProjectInheritanceTest // // ---------------------------------------------------------------------- + @Test public void testDependencyManagement() throws Exception { @@ -61,21 +68,21 @@ public class ProjectInheritanceTest assertEquals( pom0Basedir, project1.getParent().getBasedir() ); System.out.println("Project " + project1.getId() + " " + project1); Set set = project1.getArtifacts(); - assertNotNull("No artifacts", set); - assertTrue("No Artifacts", set.size() > 0); - assertTrue("Set size should be 3, is " + set.size(), set.size() == 3 ); + assertNotNull( set, "No artifacts" ); + assertTrue( set.size() > 0, "No Artifacts" ); + assertTrue( set.size() == 3, "Set size should be 3, is " + set.size() ); for ( Object aSet : set ) { Artifact artifact = (Artifact) aSet; - assertFalse( "", artifact.getArtifactId().equals( "t07-d" ) ); + assertFalse( artifact.getArtifactId().equals( "t07-d" ) ); System.out.println( "Artifact: " + artifact.getDependencyConflictId() + " " + artifact.getVersion() + " Optional=" + ( artifact.isOptional() ? "true" : "false" ) ); - assertTrue( "Incorrect version for " + artifact.getDependencyConflictId(), - artifact.getVersion().equals( "1.0" ) ); + assertTrue( artifact.getVersion().equals( "1.0" ), + "Incorrect version for " + artifact.getDependencyConflictId() ); } } } diff --git a/maven-compat/src/test/java/org/apache/maven/project/inheritance/t08/ProjectInheritanceTest.java b/maven-compat/src/test/java/org/apache/maven/project/inheritance/t08/ProjectInheritanceTest.java index b0a7873bdf..c4562dc67e 100644 --- a/maven-compat/src/test/java/org/apache/maven/project/inheritance/t08/ProjectInheritanceTest.java +++ b/maven-compat/src/test/java/org/apache/maven/project/inheritance/t08/ProjectInheritanceTest.java @@ -26,6 +26,11 @@ import java.util.Set; import org.apache.maven.artifact.Artifact; import org.apache.maven.project.MavenProject; import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * A test which demonstrates maven's dependency management @@ -46,6 +51,7 @@ public class ProjectInheritanceTest // // ---------------------------------------------------------------------- + @Test public void testDependencyManagement() throws Exception { @@ -63,18 +69,17 @@ public class ProjectInheritanceTest assertEquals( pom0Basedir, project1.getParent().getBasedir() ); System.out.println( "Project " + project1.getId() + " " + project1 ); Set set = project1.getArtifacts(); - assertNotNull( "No artifacts", set ); - assertTrue( "No Artifacts", set.size() > 0 ); + assertNotNull( set, "No artifacts" ); + assertTrue( set.size() > 0, "No Artifacts" ); Iterator iter = set.iterator(); - assertTrue( "Set size should be 4, is " + set.size(), set.size() == 4 ); + assertTrue( set.size() == 4, "Set size should be 4, is " + set.size() ); while ( iter.hasNext() ) { Artifact artifact = (Artifact) iter.next(); System.out.println( "Artifact: " + artifact.getDependencyConflictId() + " " + artifact.getVersion() + " Optional=" + ( artifact.isOptional() ? "true" : "false" ) ); - assertTrue( "Incorrect version for " + artifact.getDependencyConflictId(), - artifact.getVersion().equals( "1.0" ) ); + assertTrue( artifact.getVersion().equals( "1.0" ), "Incorrect version for " + artifact.getDependencyConflictId() ); } } diff --git a/maven-compat/src/test/java/org/apache/maven/project/inheritance/t09/ProjectInheritanceTest.java b/maven-compat/src/test/java/org/apache/maven/project/inheritance/t09/ProjectInheritanceTest.java index 29cd2ea6ab..dcc4e8bf7e 100644 --- a/maven-compat/src/test/java/org/apache/maven/project/inheritance/t09/ProjectInheritanceTest.java +++ b/maven-compat/src/test/java/org/apache/maven/project/inheritance/t09/ProjectInheritanceTest.java @@ -23,6 +23,12 @@ import java.util.Map; import org.apache.maven.project.MavenProject; import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Verifies exclusions listed in dependencyManagement are valid for @@ -56,6 +62,7 @@ public class ProjectInheritanceTest * We should see that the resulting size of collected artifacts is two: * a & b only. */ + @Test public void testDependencyManagementExclusionsExcludeTransitively() throws Exception { @@ -69,17 +76,17 @@ public class ProjectInheritanceTest MavenProject project0 = getProjectWithDependencies( pom0 ); MavenProject project1 = getProjectWithDependencies( pom1 ); - assertNotNull("Parent is null", project1.getParent()); + assertNotNull( project1.getParent(), "Parent is null" ); assertEquals( pom0Basedir, project1.getParent().getBasedir() ); Map map = project1.getArtifactMap(); - assertNotNull("No artifacts", map); - assertTrue("No Artifacts", map.size() > 0); - assertTrue("Set size should be 2, is " + map.size(), map.size() == 2); + assertNotNull( map, "No artifacts" ); + assertTrue( map.size() > 0, "No Artifacts" ); + assertTrue( map.size() == 2, "Set size should be 2, is " + map.size() ); - assertTrue("maven-test:t09-a is not in the project", map.containsKey( "maven-test:t09-a" )); - assertTrue("maven-test:t09-b is not in the project", map.containsKey( "maven-test:t09-b" )); - assertFalse("maven-test:t09-c is in the project", map.containsKey( "maven-test:t09-c" )); + assertTrue( map.containsKey( "maven-test:t09-a" ), "maven-test:t09-a is not in the project" ); + assertTrue( map.containsKey( "maven-test:t09-b" ), "maven-test:t09-b is not in the project" ); + assertFalse( map.containsKey( "maven-test:t09-c" ), "maven-test:t09-c is in the project" ); } /** @@ -92,6 +99,7 @@ public class ProjectInheritanceTest * * @throws Exception */ + @Test public void testDependencyManagementExclusionDoesNotOverrideGloballyForTransitives() throws Exception { @@ -107,13 +115,13 @@ public class ProjectInheritanceTest assertEquals( pom0Basedir, project2.getParent().getBasedir() ); Map map = project2.getArtifactMap(); - assertNotNull( "No artifacts", map ); - assertTrue( "No Artifacts", map.size() > 0 ); - assertTrue( "Set size should be 4, is " + map.size(), map.size() == 4 ); + assertNotNull( map, "No artifacts" ); + assertTrue( map.size() > 0, "No Artifacts" ); + assertTrue( map.size() == 4, "Set size should be 4, is " + map.size() ); - assertTrue( "maven-test:t09-a is not in the project", map.containsKey( "maven-test:t09-a" ) ); - assertTrue( "maven-test:t09-b is not in the project", map.containsKey( "maven-test:t09-b" ) ); - assertTrue( "maven-test:t09-c is not in the project", map.containsKey( "maven-test:t09-c" ) ); - assertTrue( "maven-test:t09-d is not in the project", map.containsKey( "maven-test:t09-d" ) ); + assertTrue( map.containsKey( "maven-test:t09-a" ), "maven-test:t09-a is not in the project" ); + assertTrue( map.containsKey( "maven-test:t09-b" ), "maven-test:t09-b is not in the project" ); + assertTrue( map.containsKey( "maven-test:t09-c" ), "maven-test:t09-c is not in the project" ); + assertTrue( map.containsKey( "maven-test:t09-d" ), "maven-test:t09-d is not in the project" ); } } diff --git a/maven-compat/src/test/java/org/apache/maven/project/inheritance/t10/ProjectInheritanceTest.java b/maven-compat/src/test/java/org/apache/maven/project/inheritance/t10/ProjectInheritanceTest.java index b24f70f39c..b1e74087ba 100644 --- a/maven-compat/src/test/java/org/apache/maven/project/inheritance/t10/ProjectInheritanceTest.java +++ b/maven-compat/src/test/java/org/apache/maven/project/inheritance/t10/ProjectInheritanceTest.java @@ -25,6 +25,11 @@ import java.util.Map; import org.apache.maven.artifact.Artifact; import org.apache.maven.project.MavenProject; import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Verifies scope inheritance of direct and transitive dependencies. @@ -52,6 +57,7 @@ public class ProjectInheritanceTest // // ---------------------------------------------------------------------- + @Test public void testDependencyManagementOverridesTransitiveDependencyVersion() throws Exception { @@ -68,9 +74,9 @@ public class ProjectInheritanceTest assertEquals( pom0Basedir, project1.getParent().getBasedir() ); System.out.println("Project " + project1.getId() + " " + project1); Map map = project1.getArtifactMap(); - assertNotNull("No artifacts", map); - assertTrue("No Artifacts", map.size() > 0); - assertTrue("Set size should be 3, is " + map.size(), map.size() == 3); + assertNotNull( map, "No artifacts" ); + assertTrue( map.size() > 0, "No Artifacts" ); + assertTrue( map.size() == 3, "Set size should be 3, is " + map.size() ); Artifact a = (Artifact) map.get("maven-test:t10-a"); Artifact b = (Artifact) map.get("maven-test:t10-b"); @@ -82,13 +88,13 @@ public class ProjectInheritanceTest // inherited from depMgmt System.out.println(a.getScope()); - assertTrue("Incorrect scope for " + a.getDependencyConflictId(), a.getScope().equals("test")); + assertTrue( a.getScope().equals("test"), "Incorrect scope for " + a.getDependencyConflictId() ); // transitive dep, overridden b depMgmt - assertTrue("Incorrect scope for " + b.getDependencyConflictId(), b.getScope().equals("runtime")); + assertTrue( b.getScope().equals("runtime"), "Incorrect scope for " + b.getDependencyConflictId() ); // direct dep, overrides depMgmt - assertTrue("Incorrect scope for " + c.getDependencyConflictId(), c.getScope().equals("runtime")); + assertTrue( c.getScope().equals("runtime"), "Incorrect scope for " + c.getDependencyConflictId() ); } } diff --git a/maven-compat/src/test/java/org/apache/maven/project/inheritance/t11/ProjectInheritanceTest.java b/maven-compat/src/test/java/org/apache/maven/project/inheritance/t11/ProjectInheritanceTest.java index d8a3926742..3f21d5e0ad 100644 --- a/maven-compat/src/test/java/org/apache/maven/project/inheritance/t11/ProjectInheritanceTest.java +++ b/maven-compat/src/test/java/org/apache/maven/project/inheritance/t11/ProjectInheritanceTest.java @@ -23,6 +23,10 @@ import java.io.File; import org.apache.maven.project.MavenProject; import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; /** * Verifies scope of root project is preserved regardless of parent dependency management. @@ -44,6 +48,7 @@ public class ProjectInheritanceTest // // ---------------------------------------------------------------------- + @Test public void testDependencyManagementDoesNotOverrideScopeOfCurrentArtifact() throws Exception { @@ -58,7 +63,7 @@ public class ProjectInheritanceTest MavenProject project1 = getProjectWithDependencies( pom1 ); assertEquals( pom0Basedir, project1.getParent().getBasedir() ); - assertNull( "dependencyManagement has overwritten the scope of the currently building child project", - project1.getArtifact().getScope() ); + assertNull( project1.getArtifact().getScope(), + "dependencyManagement has overwritten the scope of the currently building child project" ); } } diff --git a/maven-compat/src/test/java/org/apache/maven/project/inheritance/t12/ProjectInheritanceTest.java b/maven-compat/src/test/java/org/apache/maven/project/inheritance/t12/ProjectInheritanceTest.java index 814e48719e..086d710eb2 100644 --- a/maven-compat/src/test/java/org/apache/maven/project/inheritance/t12/ProjectInheritanceTest.java +++ b/maven-compat/src/test/java/org/apache/maven/project/inheritance/t12/ProjectInheritanceTest.java @@ -25,6 +25,10 @@ import java.util.Map; import org.apache.maven.model.Plugin; import org.apache.maven.project.MavenProject; import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; /** * Verifies that plugin execution sections in the parent POM that have @@ -43,6 +47,7 @@ public class ProjectInheritanceTest extends AbstractProjectInheritanceTestCase // // ---------------------------------------------------------------------- + @Test public void testFalsePluginExecutionInheritValue() throws Exception { File localRepo = getLocalRepositoryPath(); @@ -60,6 +65,6 @@ public class ProjectInheritanceTest extends AbstractProjectInheritanceTestCase assertNotNull( compilerPlugin ); Map executionMap = compilerPlugin.getExecutionsAsMap(); - assertNull( "Plugin execution: \'test\' should NOT exist in the compiler plugin specification for the child project!", executionMap.get( "test" ) ); + assertNull( executionMap.get( "test" ), "Plugin execution: \'test\' should NOT exist in the compiler plugin specification for the child project!" ); } } \ No newline at end of file diff --git a/maven-compat/src/test/java/org/apache/maven/project/inheritance/t12scm/ProjectInheritanceTest.java b/maven-compat/src/test/java/org/apache/maven/project/inheritance/t12scm/ProjectInheritanceTest.java index 7627c1355d..82aee6c70f 100644 --- a/maven-compat/src/test/java/org/apache/maven/project/inheritance/t12scm/ProjectInheritanceTest.java +++ b/maven-compat/src/test/java/org/apache/maven/project/inheritance/t12scm/ProjectInheritanceTest.java @@ -23,6 +23,9 @@ import java.io.File; import org.apache.maven.project.MavenProject; import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Verifies SCM inheritance uses modules statement from parent. @@ -43,6 +46,7 @@ public class ProjectInheritanceTest // // ---------------------------------------------------------------------- + @Test public void testScmInfoCalculatedCorrectlyOnParentAndChildRead() throws Exception { @@ -76,6 +80,7 @@ public class ProjectInheritanceTest + "/modules/p1" ); } + @Test public void testScmInfoCalculatedCorrectlyOnChildOnlyRead() throws Exception { diff --git a/maven-compat/src/test/java/org/apache/maven/project/path/DefaultPathTranslatorTest.java b/maven-compat/src/test/java/org/apache/maven/project/path/DefaultPathTranslatorTest.java index b19ef99683..022ccd5592 100644 --- a/maven-compat/src/test/java/org/apache/maven/project/path/DefaultPathTranslatorTest.java +++ b/maven-compat/src/test/java/org/apache/maven/project/path/DefaultPathTranslatorTest.java @@ -21,13 +21,14 @@ package org.apache.maven.project.path; import java.io.File; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; @SuppressWarnings( "deprecation" ) public class DefaultPathTranslatorTest - extends TestCase { + @Test public void testAlignToBasedirWhereBasedirExpressionIsTheCompleteValue() { File basedir = new File( System.getProperty( "java.io.tmpdir" ), "test" ).getAbsoluteFile(); @@ -37,6 +38,7 @@ public class DefaultPathTranslatorTest assertEquals( basedir.getAbsolutePath(), aligned ); } + @Test public void testAlignToBasedirWhereBasedirExpressionIsTheValuePrefix() { File basedir = new File( System.getProperty( "java.io.tmpdir" ), "test" ).getAbsoluteFile(); @@ -46,6 +48,7 @@ public class DefaultPathTranslatorTest assertEquals( new File( basedir, "dir" ).getAbsolutePath(), aligned ); } + @Test public void testUnalignToBasedirWherePathEqualsBasedir() { File basedir = new File( System.getProperty( "java.io.tmpdir" ), "test" ).getAbsoluteFile(); diff --git a/maven-compat/src/test/java/org/apache/maven/repository/DefaultMirrorSelectorTest.java b/maven-compat/src/test/java/org/apache/maven/repository/DefaultMirrorSelectorTest.java index 5735db0ec5..97687e3207 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/DefaultMirrorSelectorTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/DefaultMirrorSelectorTest.java @@ -21,9 +21,9 @@ package org.apache.maven.repository; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.DefaultArtifactRepository; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertFalse; public class DefaultMirrorSelectorTest { diff --git a/maven-compat/src/test/java/org/apache/maven/repository/LegacyRepositorySystemTest.java b/maven-compat/src/test/java/org/apache/maven/repository/LegacyRepositorySystemTest.java index 65dbd892a1..eb56bc8590 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/LegacyRepositorySystemTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/LegacyRepositorySystemTest.java @@ -17,7 +17,6 @@ package org.apache.maven.repository; import java.io.File; import java.util.Arrays; -import java.util.Collections; import java.util.List; import org.apache.maven.artifact.Artifact; @@ -32,16 +31,18 @@ import org.apache.maven.model.Dependency; import org.apache.maven.model.Repository; import org.apache.maven.model.RepositoryPolicy; import org.apache.maven.plugin.LegacySupport; -import org.apache.maven.project.ProjectBuilder; -import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.legacy.LegacyRepositorySystem; -import org.codehaus.plexus.ContainerConfiguration; -import org.codehaus.plexus.DefaultPlexusContainer; -import org.codehaus.plexus.PlexusConstants; -import org.codehaus.plexus.PlexusTestCase; +import org.apache.maven.test.PlexusTestCase; import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; import org.eclipse.aether.repository.LocalRepository; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import javax.inject.Inject; @@ -58,25 +59,6 @@ public class LegacyRepositorySystemTest @Inject private ResolutionErrorHandler resolutionErrorHandler; - @Override - protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration ) - { - super.customizeContainerConfiguration( containerConfiguration ); - containerConfiguration.setAutoWiring( true ); - containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); - } - - @Override - protected void setUp() - throws Exception - { - super.setUp(); - - ((DefaultPlexusContainer)getContainer()) - .addPlexusInjector( Collections.emptyList(), - binder -> binder.requestInjection( this ) ); - } - protected List getRemoteRepositories() throws Exception { @@ -104,6 +86,7 @@ public class LegacyRepositorySystemTest return repositorySystem.createLocalRepository( repoDir ); } + @Test public void testThatASystemScopedDependencyIsNotResolvedFromRepositories() throws Exception { @@ -186,6 +169,7 @@ public class LegacyRepositorySystemTest } } + @Test public void testLocalRepositoryBasedir() throws Exception { diff --git a/maven-compat/src/test/java/org/apache/maven/repository/MirrorProcessorTest.java b/maven-compat/src/test/java/org/apache/maven/repository/MirrorProcessorTest.java index 8492f7bcad..443bc44135 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/MirrorProcessorTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/MirrorProcessorTest.java @@ -20,17 +20,21 @@ package org.apache.maven.repository; */ import java.util.Arrays; -import java.util.Collections; import java.util.List; +import org.apache.maven.test.PlexusTestCase; import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.repository.legacy.repository.ArtifactRepositoryFactory; import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; +import org.apache.maven.repository.legacy.repository.ArtifactRepositoryFactory; import org.apache.maven.settings.Mirror; -import org.codehaus.plexus.ContainerConfiguration; -import org.codehaus.plexus.DefaultPlexusContainer; -import org.codehaus.plexus.PlexusConstants; -import org.codehaus.plexus.PlexusTestCase; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; import javax.inject.Inject; @@ -39,28 +43,11 @@ public class MirrorProcessorTest { @Inject private DefaultMirrorSelector mirrorSelector; + @Inject private ArtifactRepositoryFactory repositorySystem; - @Override - protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration ) - { - super.customizeContainerConfiguration( containerConfiguration ); - containerConfiguration.setAutoWiring( true ); - containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); - } - - @Override - protected void setUp() - throws Exception - { - super.setUp(); - - ((DefaultPlexusContainer)getContainer()) - .addPlexusInjector( Collections.emptyList(), - binder -> binder.requestInjection( this ) ); - } - + @Test public void testExternalURL() { assertTrue( DefaultMirrorSelector.isExternalRepo( getRepo( "foo", "http://somehost" ) ) ); @@ -83,6 +70,7 @@ public class MirrorProcessorTest assertFalse( DefaultMirrorSelector.isExternalRepo( getRepo( "foo", "" ) ) ); } + @Test public void testMirrorLookup() { Mirror mirrorA = newMirror( "a", "a", "http://a" ); @@ -97,6 +85,7 @@ public class MirrorProcessorTest assertNull( mirrorSelector.getMirror( getRepo( "c", "http://c.c" ), mirrors ) ); } + @Test public void testMirrorWildcardLookup() { Mirror mirrorA = newMirror( "a", "a", "http://a" ); @@ -112,6 +101,7 @@ public class MirrorProcessorTest assertSame( mirrorC, mirrorSelector.getMirror( getRepo( "c", "http://c.c" ), mirrors ) ); } + @Test public void testMirrorStopOnFirstMatch() { // exact matches win first @@ -140,6 +130,7 @@ public class MirrorProcessorTest assertSame( mirrorC2, mirrorSelector.getMirror( getRepo( "f", "http://f" ), mirrors ) ); } + @Test public void testPatterns() { assertTrue( DefaultMirrorSelector.matchPattern( getRepo( "a" ), "*" ) ); @@ -176,6 +167,7 @@ public class MirrorProcessorTest assertFalse( DefaultMirrorSelector.matchPattern( getRepo( "d" ), "!a,!c*" ) ); } + @Test public void testPatternsWithExternal() { assertTrue( DefaultMirrorSelector.matchPattern( getRepo( "a", "http://localhost" ), "*" ) ); @@ -190,6 +182,7 @@ public class MirrorProcessorTest assertTrue( DefaultMirrorSelector.matchPattern( getRepo( "c", "http://somehost" ), "!a,external:*" ) ); } + @Test public void testLayoutPattern() { assertTrue( DefaultMirrorSelector.matchesLayout( "default", null ) ); @@ -209,6 +202,7 @@ public class MirrorProcessorTest assertFalse( DefaultMirrorSelector.matchesLayout( "default", "!default,*" ) ); } + @Test public void testMirrorLayoutConsideredForMatching() { ArtifactRepository repo = getRepo( "a" ); diff --git a/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultUpdateCheckManagerTest.java b/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultUpdateCheckManagerTest.java index 1c5f34c3c7..e826505124 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultUpdateCheckManagerTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultUpdateCheckManagerTest.java @@ -21,20 +21,32 @@ package org.apache.maven.repository.legacy; import java.io.File; +import javax.inject.Inject; + import org.apache.maven.artifact.AbstractArtifactComponentTestCase; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata; import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; -import org.apache.maven.repository.legacy.DefaultUpdateCheckManager; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.console.ConsoleLogger; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class DefaultUpdateCheckManagerTest extends AbstractArtifactComponentTestCase { + @Inject + private ArtifactFactory artifactFactory; + DefaultUpdateCheckManager updateCheckManager; @Override @@ -43,8 +55,9 @@ public class DefaultUpdateCheckManagerTest return "updateCheckManager"; } + @BeforeEach @Override - protected void setUp() + public void setUp() throws Exception { super.setUp(); @@ -52,6 +65,7 @@ public class DefaultUpdateCheckManagerTest updateCheckManager = new DefaultUpdateCheckManager( new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ) ); } + @Test public void testArtifact() throws Exception { ArtifactRepository remoteRepository = remoteRepository(); @@ -81,6 +95,7 @@ public class DefaultUpdateCheckManagerTest assertFalse( updateCheckManager.getTouchfile( a ).exists() ); } + @Test public void testMissingArtifact() throws Exception { @@ -108,6 +123,7 @@ public class DefaultUpdateCheckManagerTest updateCheckManager.getRepositoryKey( remoteRepository ) ) ); } + @Test public void testPom() throws Exception { ArtifactRepository remoteRepository = remoteRepository(); @@ -137,6 +153,7 @@ public class DefaultUpdateCheckManagerTest assertFalse( updateCheckManager.getTouchfile( a ).exists() ); } + @Test public void testMissingPom() throws Exception { @@ -164,6 +181,7 @@ public class DefaultUpdateCheckManagerTest updateCheckManager.getRepositoryKey( remoteRepository ) ) ); } + @Test public void testMetadata() throws Exception { ArtifactRepository remoteRepository = remoteRepository(); @@ -191,6 +209,7 @@ public class DefaultUpdateCheckManagerTest assertNotNull( updateCheckManager.readLastUpdated( touchFile, updateCheckManager.getMetadataKey( remoteRepository, file ) ) ); } + @Test public void testMissingMetadata() throws Exception { ArtifactRepository remoteRepository = remoteRepository(); @@ -216,10 +235,9 @@ public class DefaultUpdateCheckManagerTest assertNotNull( updateCheckManager.readLastUpdated( touchFile, updateCheckManager.getMetadataKey( remoteRepository, file ) ) ); } + @Test public void testArtifactTouchFileName() throws Exception { - ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); - ArtifactRepository localRepository = localRepository(); Artifact a = artifactFactory.createArtifactWithClassifier( "groupdId", "a", "0.0.1-SNAPSHOT", "jar", null ); diff --git a/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultWagonManagerTest.java b/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultWagonManagerTest.java index 9ddbe32ab9..e6177c722a 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultWagonManagerTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultWagonManagerTest.java @@ -22,7 +22,6 @@ package org.apache.maven.repository.legacy; import java.io.File; import java.io.IOException; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import org.apache.maven.artifact.Artifact; @@ -30,25 +29,32 @@ import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.repository.legacy.repository.ArtifactRepositoryFactory; import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.repository.legacy.repository.ArtifactRepositoryFactory; import org.apache.maven.wagon.ResourceDoesNotExistException; import org.apache.maven.wagon.TransferFailedException; import org.apache.maven.wagon.UnsupportedProtocolException; import org.apache.maven.wagon.Wagon; -import org.apache.maven.wagon.authorization.AuthorizationException; import org.apache.maven.wagon.events.TransferEvent; import org.apache.maven.wagon.events.TransferListener; import org.apache.maven.wagon.observers.AbstractTransferListener; import org.apache.maven.wagon.observers.Debug; -import org.codehaus.plexus.ContainerConfiguration; -import org.codehaus.plexus.DefaultPlexusContainer; -import org.codehaus.plexus.PlexusConstants; -import org.codehaus.plexus.PlexusTestCase; +import org.apache.maven.test.PlexusTestCase; import org.codehaus.plexus.util.FileUtils; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import javax.inject.Inject; @@ -69,25 +75,7 @@ public class DefaultWagonManagerTest @Inject private ArtifactRepositoryFactory artifactRepositoryFactory; - @Override - protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration ) - { - super.customizeContainerConfiguration( containerConfiguration ); - containerConfiguration.setAutoWiring( true ); - containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); - } - - @Override - protected void setUp() - throws Exception - { - super.setUp(); - - ((DefaultPlexusContainer)getContainer()) - .addPlexusInjector( Collections.emptyList(), - binder -> binder.requestInjection( this ) ); - } - + @Test public void testUnnecessaryRepositoryLookup() throws Exception { @@ -123,46 +111,33 @@ public class DefaultWagonManagerTest assertEquals( 1, listener.events.size() ); } + @Test public void testGetMissingJar() throws TransferFailedException, UnsupportedProtocolException, IOException { Artifact artifact = createTestArtifact( "target/test-data/get-missing-jar", "jar" ); ArtifactRepository repo = createStringRepo(); - try - { - wagonManager.getArtifact( artifact, repo, null, false ); - - fail(); - } - catch ( ResourceDoesNotExistException e ) - { - assertTrue( true ); - } + assertThrows( ResourceDoesNotExistException.class, + () -> wagonManager.getArtifact( artifact, repo, null, false ) ); assertFalse( artifact.getFile().exists() ); } + @Test public void testGetMissingJarForced() throws TransferFailedException, UnsupportedProtocolException, IOException { Artifact artifact = createTestArtifact( "target/test-data/get-missing-jar", "jar" ); ArtifactRepository repo = createStringRepo(); - try - { - wagonManager.getArtifact( artifact, repo, null, true ); - - fail(); - } - catch ( ResourceDoesNotExistException e ) - { - assertTrue( true ); - } + assertThrows( ResourceDoesNotExistException.class, + () -> wagonManager.getArtifact( artifact, repo, null, true ) ); assertFalse( artifact.getFile().exists() ); } + @Test public void testGetRemoteJar() throws TransferFailedException, ResourceDoesNotExistException, UnsupportedProtocolException, IOException { @@ -240,6 +215,7 @@ public class DefaultWagonManagerTest return getRepo( id, "http://something" ); } + @Test public void testDefaultWagonManager() throws Exception { @@ -251,22 +227,13 @@ public class DefaultWagonManagerTest assertWagon( "string" ); - try - { - assertWagon( "d" ); - - fail( "Expected :" + UnsupportedProtocolException.class.getName() ); - } - catch ( UnsupportedProtocolException e ) - { - // ok - assertTrue( true ); - } + assertThrows( UnsupportedProtocolException.class, () -> assertWagon( "d" ) ); } /** * Check that transfer listeners are properly removed after getArtifact and putArtifact */ + @Test public void testWagonTransferListenerRemovedAfterGetArtifactAndPutArtifact() throws Exception { @@ -277,25 +244,29 @@ public class DefaultWagonManagerTest wagon.addExpectedContent( repo.getLayout().pathOf( artifact ) + ".md5", "cd26d9e10ce691cc69aa2b90dcebbdac" ); /* getArtifact */ - assertFalse( "Transfer listener is registered before test", - wagon.getTransferEventSupport().hasTransferListener( transferListener ) ); + assertFalse( wagon.getTransferEventSupport().hasTransferListener( transferListener ), + "Transfer listener is registered before test" ); wagonManager.getArtifact( artifact, repo, transferListener, false ); - assertFalse( "Transfer listener still registered after getArtifact", - wagon.getTransferEventSupport().hasTransferListener( transferListener ) ); + assertFalse( wagon.getTransferEventSupport().hasTransferListener( transferListener ), + "Transfer listener still registered after getArtifact" ); /* putArtifact */ File sampleFile = getTestFile( "target/test-file" ); FileUtils.fileWrite( sampleFile.getAbsolutePath(), "sample file" ); - assertFalse( "Transfer listener is registered before test", wagon.getTransferEventSupport().hasTransferListener( transferListener ) ); + assertFalse( wagon.getTransferEventSupport().hasTransferListener( transferListener ), + "Transfer listener is registered before test" ); wagonManager.putArtifact( sampleFile, artifact, repo, transferListener ); - assertFalse( "Transfer listener still registered after putArtifact", wagon.getTransferEventSupport().hasTransferListener( transferListener ) ); + assertFalse( wagon.getTransferEventSupport().hasTransferListener( transferListener ), + "Transfer listener still registered after putArtifact" ); } /** * Checks the verification of checksums. */ - public void xtestChecksumVerification() + @Disabled + @Test + public void testChecksumVerification() throws Exception { ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_FAIL ); @@ -312,84 +283,41 @@ public class DefaultWagonManagerTest wagon.clearExpectedContent(); wagon.addExpectedContent( "path", "lower-case-checksum" ); wagon.addExpectedContent( "path.sha1", "2a25dc564a3b34f68237fc849066cbc7bb7a36a1" ); - - try - { - wagonManager.getArtifact( artifact, repo, null, false ); - } - catch ( ChecksumFailedException e ) - { - fail( "Checksum verification did not pass: " + e.getMessage() ); - } + wagonManager.getArtifact( artifact, repo, null, false ); wagon.clearExpectedContent(); wagon.addExpectedContent( "path", "upper-case-checksum" ); wagon.addExpectedContent( "path.sha1", "B7BB97D7D0B9244398D9B47296907F73313663E6" ); - - try - { - wagonManager.getArtifact( artifact, repo, null, false ); - } - catch ( ChecksumFailedException e ) - { - fail( "Checksum verification did not pass: " + e.getMessage() ); - } + wagonManager.getArtifact( artifact, repo, null, false ); wagon.clearExpectedContent(); wagon.addExpectedContent( "path", "expected-failure" ); wagon.addExpectedContent( "path.sha1", "b7bb97d7d0b9244398d9b47296907f73313663e6" ); - - try - { - wagonManager.getArtifact( artifact, repo, null, false ); - fail( "Checksum verification did not fail" ); - } - catch ( ChecksumFailedException e ) - { - // expected - } + assertThrows( + ChecksumFailedException.class, () -> + wagonManager.getArtifact( artifact, repo, null, false ), + "Checksum verification did not fail" ); wagon.clearExpectedContent(); wagon.addExpectedContent( "path", "lower-case-checksum" ); wagon.addExpectedContent( "path.md5", "50b2cf50a103a965efac62b983035cac" ); - - try - { - wagonManager.getArtifact( artifact, repo, null, false ); - } - catch ( ChecksumFailedException e ) - { - fail( "Checksum verification did not pass: " + e.getMessage() ); - } + wagonManager.getArtifact( artifact, repo, null, false ); wagon.clearExpectedContent(); wagon.addExpectedContent( "path", "upper-case-checksum" ); wagon.addExpectedContent( "path.md5", "842F568FCCFEB7E534DC72133D42FFDC" ); - - try - { - wagonManager.getArtifact( artifact, repo, null, false ); - } - catch ( ChecksumFailedException e ) - { - fail( "Checksum verification did not pass: " + e.getMessage() ); - } + wagonManager.getArtifact( artifact, repo, null, false ); wagon.clearExpectedContent(); wagon.addExpectedContent( "path", "expected-failure" ); wagon.addExpectedContent( "path.md5", "b7bb97d7d0b9244398d9b47296907f73313663e6" ); - - try - { - wagonManager.getArtifact( artifact, repo, null, false ); - fail( "Checksum verification did not fail" ); - } - catch ( ChecksumFailedException e ) - { - // expected - } + assertThrows( + ChecksumFailedException.class, + () -> wagonManager.getArtifact( artifact, repo, null, false ), + "Checksum verification did not fail" ); } + @Test public void testPerLookupInstantiation() throws Exception { @@ -406,7 +334,7 @@ public class DefaultWagonManagerTest { Wagon wagon = wagonManager.getWagon( protocol ); - assertNotNull( "Check wagon, protocol=" + protocol, wagon ); + assertNotNull( wagon, "Check wagon, protocol=" + protocol ); } private final class ArtifactRepositoryLayoutStub diff --git a/maven-compat/src/test/java/org/apache/maven/repository/legacy/LegacyRepositorySystemTest.java b/maven-compat/src/test/java/org/apache/maven/repository/legacy/LegacyRepositorySystemTest.java index d5f281fba5..61f16cceb1 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/legacy/LegacyRepositorySystemTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/legacy/LegacyRepositorySystemTest.java @@ -17,16 +17,18 @@ package org.apache.maven.repository.legacy; import java.io.File; import java.util.Arrays; -import java.util.Collections; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.Authentication; import org.apache.maven.repository.RepositorySystem; import org.apache.maven.settings.Server; -import org.codehaus.plexus.ContainerConfiguration; -import org.codehaus.plexus.DefaultPlexusContainer; -import org.codehaus.plexus.PlexusConstants; -import org.codehaus.plexus.PlexusTestCase; +import org.apache.maven.test.PlexusTestCase; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import javax.inject.Inject; @@ -41,25 +43,7 @@ public class LegacyRepositorySystemTest @Inject private RepositorySystem repositorySystem; - @Override - protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration ) - { - super.customizeContainerConfiguration( containerConfiguration ); - containerConfiguration.setAutoWiring( true ); - containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); - } - - @Override - protected void setUp() - throws Exception - { - super.setUp(); - - ((DefaultPlexusContainer)getContainer()) - .addPlexusInjector( Collections.emptyList(), - binder -> binder.requestInjection( this ) ); - } - + @Test public void testThatLocalRepositoryWithSpacesIsProperlyHandled() throws Exception { @@ -68,6 +52,7 @@ public class LegacyRepositorySystemTest assertEquals( basedir, new File( repo.getBasedir() ) ); } + @Test public void testAuthenticationHandling() { Server server = new Server(); diff --git a/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/DefaultArtifactCollectorTest.java b/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/DefaultArtifactCollectorTest.java index 5d88702136..0ef67d9be4 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/DefaultArtifactCollectorTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/DefaultArtifactCollectorTest.java @@ -19,6 +19,18 @@ package org.apache.maven.repository.legacy.resolver; * under the License. */ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.inject.Inject; + import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; @@ -37,19 +49,16 @@ import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException import org.apache.maven.artifact.versioning.OverConstrainedVersionException; import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest; -import org.codehaus.plexus.ContainerConfiguration; -import org.codehaus.plexus.PlexusConstants; -import org.codehaus.plexus.PlexusTestCase; +import org.apache.maven.test.PlexusTestCase; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Test the default artifact collector. @@ -59,8 +68,10 @@ import java.util.Set; public class DefaultArtifactCollectorTest extends PlexusTestCase { + @Inject private LegacyArtifactCollector artifactCollector; + @Inject private ArtifactFactory artifactFactory; private ArtifactSpec projectArtifact; @@ -69,72 +80,47 @@ public class DefaultArtifactCollectorTest private static final String GROUP_ID = "test"; + @BeforeEach @Override - protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration ) - { - super.customizeContainerConfiguration( containerConfiguration ); - containerConfiguration.setAutoWiring( true ); - containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); - } - - @Override - protected void setUp() + public void setUp() throws Exception { super.setUp(); source = new Source(); - artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); - artifactCollector = lookup( LegacyArtifactCollector.class ); projectArtifact = createArtifactSpec( "project", "1.0", null ); } - @Override - protected void tearDown() - throws Exception - { - artifactCollector = null; - artifactFactory = null; - super.tearDown(); - } - - // works, but we don't fail on cycles presently - public void disabledtestCircularDependencyNotIncludingCurrentProject() + @Test + @Disabled("works, but we don't fail on cycles presently") + public void testCircularDependencyNotIncludingCurrentProject() throws ArtifactResolutionException, InvalidVersionSpecificationException { ArtifactSpec a = createArtifactSpec( "a", "1.0" ); ArtifactSpec b = a.addDependency( "b", "1.0" ); b.addDependency( "a", "1.0" ); - try - { - collect( a ); - fail( "Should have failed on cyclic dependency not involving project" ); - } - catch ( CyclicDependencyException expected ) - { - assertTrue( true ); - } + assertThrows( + CyclicDependencyException.class, + () -> collect( a ), + "Should have failed on cyclic dependency not involving project" ); } - // works, but we don't fail on cycles presently - public void disabledtestCircularDependencyIncludingCurrentProject() + @Test + @Disabled("works, but we don't fail on cycles presently") + public void testCircularDependencyIncludingCurrentProject() throws ArtifactResolutionException, InvalidVersionSpecificationException { ArtifactSpec a = createArtifactSpec( "a", "1.0" ); ArtifactSpec b = a.addDependency( "b", "1.0" ); b.addDependency( "project", "1.0" ); - try - { - collect( a ); - fail( "Should have failed on cyclic dependency involving project" ); - } - catch ( CyclicDependencyException expected ) - { - assertTrue( true ); - } + assertThrows( + CyclicDependencyException.class, + () -> collect( a ), + "Should have failed on cyclic dependency not involving project" ); } + @Test public void testResolveWithFilter() throws ArtifactResolutionException, InvalidVersionSpecificationException { @@ -146,14 +132,15 @@ public class DefaultArtifactCollectorTest ArtifactSpec d = b.addDependency( "d", "4.0" ); ArtifactResolutionResult res = collect( a ); - assertEquals( "Check artifact list", - createSet( new Object[] { a.artifact, b.artifact, c.artifact, d.artifact } ), res.getArtifacts() ); + assertEquals( createSet( new Object[] { a.artifact, b.artifact, c.artifact, d.artifact } ), res.getArtifacts(), + "Check artifact list" ); ArtifactFilter filter = new ExclusionSetFilter( new String[] { "b" } ); res = collect( a, filter ); - assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, c.artifact } ), res.getArtifacts() ); + assertEquals( createSet( new Object[] { a.artifact, c.artifact } ), res.getArtifacts(), "Check artifact list" ); } + @Test public void testResolveCorrectDependenciesWhenDifferentDependenciesOnNearest() throws ArtifactResolutionException, InvalidVersionSpecificationException { @@ -167,12 +154,14 @@ public class DefaultArtifactCollectorTest ArtifactSpec f = c1.addDependency( "f", "1.0" ); ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact, e.artifact } ) ); - assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, b.artifact, e.artifact, c1.artifact, - f.artifact } ), res.getArtifacts() ); - assertEquals( "Check version", "1.0", getArtifact( "c", res.getArtifacts() ).getVersion() ); + assertEquals( createSet( new Object[] { a.artifact, b.artifact, e.artifact, c1.artifact, f.artifact } ), + res.getArtifacts(), "Check artifact list" ); + assertEquals( "1.0", getArtifact( "c", res.getArtifacts() ).getVersion(), "Check version" ); } - public void disabledtestResolveCorrectDependenciesWhenDifferentDependenciesOnNewest() + @Test + @Disabled + public void testResolveCorrectDependenciesWhenDifferentDependenciesOnNewest() throws ArtifactResolutionException, InvalidVersionSpecificationException { // TODO use newest conflict resolver @@ -186,12 +175,13 @@ public class DefaultArtifactCollectorTest c1.addDependency( "f", "1.0" ); ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact, e.artifact } ) ); - assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, b.artifact, e.artifact, c2.artifact, - d.artifact } ), res.getArtifacts() ); - assertEquals( "Check version", "2.0", getArtifact( "c", res.getArtifacts() ).getVersion() ); + assertEquals( createSet( new Object[] { a.artifact, b.artifact, e.artifact, c2.artifact, d.artifact } ), res.getArtifacts(), "Check artifact list" ); + assertEquals( "2.0", getArtifact( "c", res.getArtifacts() ).getVersion(), "Check version" ); } - public void disabledtestResolveCorrectDependenciesWhenDifferentDependenciesOnNewestVersionReplaced() + @Test + @Disabled + public void testResolveCorrectDependenciesWhenDifferentDependenciesOnNewestVersionReplaced() throws ArtifactResolutionException, InvalidVersionSpecificationException { // TODO use newest conflict resolver @@ -207,11 +197,12 @@ public class DefaultArtifactCollectorTest ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact } ) ); Object[] artifacts = new Object[] { a.artifact, c.artifact, d1.artifact, b2.artifact, e.artifact, g.artifact }; - assertEquals( "Check artifact list", createSet( artifacts ), res.getArtifacts() ); - assertEquals( "Check version", "1.0", getArtifact( "d", res.getArtifacts() ).getVersion() ); - assertEquals( "Check version", "2.0", getArtifact( "b", res.getArtifacts() ).getVersion() ); + assertEquals( createSet( artifacts ), res.getArtifacts(), "Check artifact list" ); + assertEquals( "1.0", getArtifact( "d", res.getArtifacts() ).getVersion(), "Check version" ); + assertEquals( "2.0", getArtifact( "b", res.getArtifacts() ).getVersion(), "Check version" ); } + @Test public void testResolveNearestNewestIsNearest() throws ArtifactResolutionException, InvalidVersionSpecificationException { @@ -222,11 +213,11 @@ public class DefaultArtifactCollectorTest b.addDependency( "c", "2.0" ); ArtifactResolutionResult res = collect( a ); - assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, b.artifact, c.artifact } ), - res.getArtifacts() ); - assertEquals( "Check version", "3.0", getArtifact( "c", res.getArtifacts() ).getVersion() ); + assertEquals( createSet( new Object[] { a.artifact, b.artifact, c.artifact } ), res.getArtifacts(), "Check artifact list" ); + assertEquals( "3.0", getArtifact( "c", res.getArtifacts() ).getVersion(), "Check version" ); } + @Test public void testResolveNearestOldestIsNearest() throws ArtifactResolutionException, InvalidVersionSpecificationException { @@ -237,11 +228,11 @@ public class DefaultArtifactCollectorTest b.addDependency( "c", "3.0" ); ArtifactResolutionResult res = collect( a ); - assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, b.artifact, c.artifact } ), - res.getArtifacts() ); - assertEquals( "Check version", "2.0", getArtifact( "c", res.getArtifacts() ).getVersion() ); + assertEquals( createSet( new Object[] { a.artifact, b.artifact, c.artifact } ), res.getArtifacts(), "Check artifact list" ); + assertEquals( "2.0", getArtifact( "c", res.getArtifacts() ).getVersion(), "Check version" ); } + @Test public void testResolveLocalNewestIsLocal() throws ArtifactResolutionException, InvalidVersionSpecificationException { @@ -250,10 +241,11 @@ public class DefaultArtifactCollectorTest ArtifactSpec b = createArtifactSpec( "b", "3.0" ); ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact, b.artifact } ) ); - assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, b.artifact } ), res.getArtifacts() ); - assertEquals( "Check version", "3.0", getArtifact( "b", res.getArtifacts() ).getVersion() ); + assertEquals( createSet( new Object[] { a.artifact, b.artifact } ), res.getArtifacts(), "Check artifact list" ); + assertEquals( "3.0", getArtifact( "b", res.getArtifacts() ).getVersion(), "Check version" ); } + @Test public void testResolveLocalOldestIsLocal() throws ArtifactResolutionException, InvalidVersionSpecificationException { @@ -262,10 +254,11 @@ public class DefaultArtifactCollectorTest ArtifactSpec b = createArtifactSpec( "b", "2.0" ); ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact, b.artifact } ) ); - assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, b.artifact } ), res.getArtifacts() ); - assertEquals( "Check version", "2.0", getArtifact( "b", res.getArtifacts() ).getVersion() ); + assertEquals( createSet( new Object[] { a.artifact, b.artifact } ), res.getArtifacts(), "Check artifact list" ); + assertEquals( "2.0", getArtifact( "b", res.getArtifacts() ).getVersion(), "Check version" ); } + @Test public void testResolveLocalWithNewerVersionButLesserScope() throws ArtifactResolutionException, InvalidVersionSpecificationException { @@ -274,11 +267,12 @@ public class DefaultArtifactCollectorTest ArtifactSpec b = createArtifactSpec( "junit", "3.8.1", Artifact.SCOPE_TEST ); ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact, b.artifact } ) ); - assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, b.artifact } ), res.getArtifacts() ); - assertEquals( "Check version", "3.8.1", getArtifact( "junit", res.getArtifacts() ).getVersion() ); - assertEquals( "Check artifactScope", Artifact.SCOPE_TEST, getArtifact( "junit", res.getArtifacts() ).getScope() ); + assertEquals( createSet( new Object[] { a.artifact, b.artifact } ), res.getArtifacts(), "Check artifact list" ); + assertEquals( "3.8.1", getArtifact( "junit", res.getArtifacts() ).getVersion(), "Check version" ); + assertEquals( Artifact.SCOPE_TEST, getArtifact( "junit", res.getArtifacts() ).getScope(), "Check artifactScope" ); } + @Test public void testResolveLocalWithNewerVersionButLesserScopeResolvedFirst() throws ArtifactResolutionException, InvalidVersionSpecificationException { @@ -287,11 +281,12 @@ public class DefaultArtifactCollectorTest a.addDependency( "junit", "3.7" ); ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact, b.artifact } ) ); - assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, b.artifact } ), res.getArtifacts() ); - assertEquals( "Check version", "3.8.1", getArtifact( "junit", res.getArtifacts() ).getVersion() ); - assertEquals( "Check artifactScope", Artifact.SCOPE_TEST, getArtifact( "junit", res.getArtifacts() ).getScope() ); + assertEquals( createSet( new Object[] { a.artifact, b.artifact } ), res.getArtifacts(), "Check artifact list" ); + assertEquals( "3.8.1", getArtifact( "junit", res.getArtifacts() ).getVersion(), "Check version" ); + assertEquals( Artifact.SCOPE_TEST, getArtifact( "junit", res.getArtifacts() ).getScope(), "Check artifactScope" ); } + @Test public void testResolveNearestWithRanges() throws ArtifactResolutionException, InvalidVersionSpecificationException { @@ -302,11 +297,11 @@ public class DefaultArtifactCollectorTest b.addDependency( "c", "[1.0,3.0]" ); ArtifactResolutionResult res = collect( a ); - assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, b.artifact, c.artifact } ), - res.getArtifacts() ); - assertEquals( "Check version", "2.0", getArtifact( "c", res.getArtifacts() ).getVersion() ); + assertEquals( createSet( new Object[] { a.artifact, b.artifact, c.artifact } ), res.getArtifacts(), "Check artifact list" ); + assertEquals( "2.0", getArtifact( "c", res.getArtifacts() ).getVersion(), "Check version" ); } + @Test public void testResolveRangeWithManagedVersion() throws ArtifactResolutionException, InvalidVersionSpecificationException { @@ -316,11 +311,11 @@ public class DefaultArtifactCollectorTest ArtifactSpec managedB = createArtifactSpec( "b", "5.0" ); ArtifactResolutionResult res = collect( a, managedB.artifact ); - assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, managedB.artifact } ), - res.getArtifacts() ); - assertEquals( "Check version", "5.0", getArtifact( "b", res.getArtifacts() ).getVersion() ); + assertEquals( createSet( new Object[] { a.artifact, managedB.artifact } ), res.getArtifacts(), "Check artifact list" ); + assertEquals( "5.0", getArtifact( "b", res.getArtifacts() ).getVersion(), "Check version" ); } + @Test public void testCompatibleRanges() throws ArtifactResolutionException, InvalidVersionSpecificationException { @@ -332,11 +327,11 @@ public class DefaultArtifactCollectorTest ArtifactResolutionResult res = collect( a ); - assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, b.artifact, c.artifact } ), - res.getArtifacts() ); - assertEquals( "Check version", "2.5", getArtifact( "c", res.getArtifacts() ).getVersion() ); + assertEquals( createSet( new Object[] { a.artifact, b.artifact, c.artifact } ), res.getArtifacts(), "Check artifact list" ); + assertEquals( "2.5", getArtifact( "c", res.getArtifacts() ).getVersion(), "Check version" ); } + @Test public void testIncompatibleRanges() throws ArtifactResolutionException, InvalidVersionSpecificationException { @@ -351,6 +346,7 @@ public class DefaultArtifactCollectorTest assertTrue( res.hasVersionRangeViolations() ); } + @Test public void testUnboundedRangeWhenVersionUnavailable() throws ArtifactResolutionException, InvalidVersionSpecificationException { @@ -364,6 +360,7 @@ public class DefaultArtifactCollectorTest assertTrue( res.hasVersionRangeViolations() ); } + @Test public void testUnboundedRangeBelowLastRelease() throws ArtifactResolutionException, InvalidVersionSpecificationException { @@ -375,10 +372,11 @@ public class DefaultArtifactCollectorTest ArtifactResolutionResult res = collect( a ); - assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, c.artifact } ), res.getArtifacts() ); - assertEquals( "Check version", "2.0", getArtifact( "c", res.getArtifacts() ).getVersion() ); + assertEquals( createSet( new Object[] { a.artifact, c.artifact } ), res.getArtifacts(), "Check artifact list" ); + assertEquals( "2.0", getArtifact( "c", res.getArtifacts() ).getVersion(), "Check version" ); } + @Test public void testUnboundedRangeAboveLastRelease() throws ArtifactResolutionException, InvalidVersionSpecificationException { @@ -391,6 +389,7 @@ public class DefaultArtifactCollectorTest assertTrue( res.hasVersionRangeViolations() ); } + @Test public void testResolveManagedVersion() throws ArtifactResolutionException, InvalidVersionSpecificationException { @@ -401,9 +400,10 @@ public class DefaultArtifactCollectorTest Artifact modifiedB = createArtifactSpec( "b", "5.0", Artifact.SCOPE_RUNTIME ).artifact; ArtifactResolutionResult res = collect( a, managedVersion ); - assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, modifiedB } ), res.getArtifacts() ); + assertEquals( createSet( new Object[] { a.artifact, modifiedB } ), res.getArtifacts(), "Check artifact list" ); } + @Test public void testCollectChangesVersionOfOriginatingArtifactIfInDependencyManagementHasDifferentVersion() throws ArtifactResolutionException, InvalidVersionSpecificationException { @@ -414,13 +414,14 @@ public class DefaultArtifactCollectorTest ArtifactResolutionResult result = collect( a, managedVersion ); - assertEquals( "collect has modified version in originating artifact", "1.0", artifact.getVersion() ); + assertEquals( "1.0", artifact.getVersion(), "collect has modified version in originating artifact" ); Artifact resolvedArtifact = result.getArtifacts().iterator().next(); - assertEquals( "Resolved version don't match original artifact version", "1.0", resolvedArtifact.getVersion() ); + assertEquals( "1.0", resolvedArtifact.getVersion(), "Resolved version don't match original artifact version" ); } + @Test public void testResolveCompileScopeOverTestScope() throws ArtifactResolutionException, InvalidVersionSpecificationException { @@ -432,13 +433,14 @@ public class DefaultArtifactCollectorTest Artifact modifiedC = createArtifactSpec( "c", "3.0", Artifact.SCOPE_COMPILE ).artifact; ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact, c.artifact } ) ); - assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, modifiedC } ), res.getArtifacts() ); + assertEquals( createSet( new Object[] { a.artifact, modifiedC } ), res.getArtifacts(), "Check artifact list" ); Artifact artifact = getArtifact( "c", res.getArtifacts() ); // local wins now, and irrelevant if not local as test/provided aren't transitive - // assertEquals( "Check artifactScope", Artifact.SCOPE_COMPILE, artifact.getArtifactScope() ); - assertEquals( "Check artifactScope", Artifact.SCOPE_TEST, artifact.getScope() ); + // assertEquals( Artifact.SCOPE_COMPILE, artifact.getArtifactScope(), "Check artifactScope" ); + assertEquals( Artifact.SCOPE_TEST, artifact.getScope(), "Check artifactScope" ); } + @Test public void testResolveRuntimeScopeOverTestScope() throws ArtifactResolutionException, InvalidVersionSpecificationException { @@ -450,13 +452,14 @@ public class DefaultArtifactCollectorTest Artifact modifiedC = createArtifactSpec( "c", "3.0", Artifact.SCOPE_RUNTIME ).artifact; ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact, c.artifact } ) ); - assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, modifiedC } ), res.getArtifacts() ); + assertEquals( createSet( new Object[] { a.artifact, modifiedC } ), res.getArtifacts(), "Check artifact list" ); Artifact artifact = getArtifact( "c", res.getArtifacts() ); // local wins now, and irrelevant if not local as test/provided aren't transitive - // assertEquals( "Check artifactScope", Artifact.SCOPE_RUNTIME, artifact.getArtifactScope() ); - assertEquals( "Check artifactScope", Artifact.SCOPE_TEST, artifact.getScope() ); + // assertEquals( Artifact.SCOPE_RUNTIME, artifact.getArtifactScope(), "Check artifactScope" ); + assertEquals( Artifact.SCOPE_TEST, artifact.getScope(), "Check artifactScope" ); } + @Test public void testResolveCompileScopeOverRuntimeScope() throws ArtifactResolutionException, InvalidVersionSpecificationException { @@ -469,12 +472,12 @@ public class DefaultArtifactCollectorTest Artifact modifiedC = createArtifactSpec( "c", "3.0", Artifact.SCOPE_COMPILE ).artifact; ArtifactResolutionResult res = collect( createSet( new Object[] { root.artifact } ) ); - assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, root.artifact, modifiedC } ), - res.getArtifacts() ); + assertEquals( createSet( new Object[] { a.artifact, root.artifact, modifiedC } ), res.getArtifacts(), "Check artifact list" ); Artifact artifact = getArtifact( "c", res.getArtifacts() ); - assertEquals( "Check artifactScope", Artifact.SCOPE_COMPILE, artifact.getScope() ); + assertEquals( Artifact.SCOPE_COMPILE, artifact.getScope(), "Check artifactScope" ); } + @Test public void testResolveCompileScopeOverProvidedScope() throws ArtifactResolutionException, InvalidVersionSpecificationException { @@ -486,13 +489,14 @@ public class DefaultArtifactCollectorTest Artifact modifiedC = createArtifactSpec( "c", "3.0", Artifact.SCOPE_COMPILE ).artifact; ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact, c.artifact } ) ); - assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, modifiedC } ), res.getArtifacts() ); + assertEquals( createSet( new Object[] { a.artifact, modifiedC } ), res.getArtifacts(), "Check artifact list" ); Artifact artifact = getArtifact( "c", res.getArtifacts() ); // local wins now, and irrelevant if not local as test/provided aren't transitive - // assertEquals( "Check artifactScope", Artifact.SCOPE_COMPILE, artifact.getArtifactScope() ); - assertEquals( "Check artifactScope", Artifact.SCOPE_PROVIDED, artifact.getScope() ); + // assertEquals( Artifact.SCOPE_COMPILE, artifact.getArtifactScope(), "Check artifactScope" ); + assertEquals( Artifact.SCOPE_PROVIDED, artifact.getScope(), "Check artifactScope" ); } + @Test public void testResolveRuntimeScopeOverProvidedScope() throws ArtifactResolutionException, InvalidVersionSpecificationException { @@ -504,13 +508,14 @@ public class DefaultArtifactCollectorTest Artifact modifiedC = createArtifactSpec( "c", "3.0", Artifact.SCOPE_RUNTIME ).artifact; ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact, c.artifact } ) ); - assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, modifiedC } ), res.getArtifacts() ); + assertEquals( createSet( new Object[] { a.artifact, modifiedC } ), res.getArtifacts(), "Check artifact list" ); Artifact artifact = getArtifact( "c", res.getArtifacts() ); // local wins now, and irrelevant if not local as test/provided aren't transitive - // assertEquals( "Check artifactScope", Artifact.SCOPE_RUNTIME, artifact.getArtifactScope() ); - assertEquals( "Check artifactScope", Artifact.SCOPE_PROVIDED, artifact.getScope() ); + // assertEquals( Artifact.SCOPE_RUNTIME, artifact.getArtifactScope(), "Check artifactScope" ); + assertEquals( Artifact.SCOPE_PROVIDED, artifact.getScope(), "Check artifactScope" ); } + @Test public void testProvidedScopeNotTransitive() throws ArtifactResolutionException, InvalidVersionSpecificationException { @@ -519,9 +524,10 @@ public class DefaultArtifactCollectorTest b.addDependency( "c", "3.0", Artifact.SCOPE_PROVIDED ); ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact, b.artifact } ) ); - assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, b.artifact } ), res.getArtifacts() ); + assertEquals( createSet( new Object[] { a.artifact, b.artifact } ), res.getArtifacts(), "Check artifact list" ); } + @Test public void testOptionalNotTransitive() throws ArtifactResolutionException, InvalidVersionSpecificationException { @@ -530,9 +536,10 @@ public class DefaultArtifactCollectorTest b.addDependency( "c", "3.0", true ); ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact, b.artifact } ) ); - assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, b.artifact } ), res.getArtifacts() ); + assertEquals( createSet( new Object[] { a.artifact, b.artifact } ), res.getArtifacts(), "Check artifact list" ); } + @Test public void testOptionalIncludedAtRoot() throws ArtifactResolutionException, InvalidVersionSpecificationException { @@ -541,9 +548,10 @@ public class DefaultArtifactCollectorTest ArtifactSpec b = createArtifactSpec( "b", "1.0", true ); ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact, b.artifact } ) ); - assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, b.artifact } ), res.getArtifacts() ); + assertEquals( createSet( new Object[] { a.artifact, b.artifact } ), res.getArtifacts(), "Check artifact list" ); } + @Test public void testScopeUpdate() throws InvalidVersionSpecificationException, ArtifactResolutionException { @@ -643,19 +651,21 @@ public class DefaultArtifactCollectorTest ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact, b.artifact } ), filter ); Artifact artifact = getArtifact( "d", res.getArtifacts() ); - assertNotNull( "MNG-1895 Dependency was not added to resolution", artifact ); - assertEquals( "Check artifactScope", expectedScope, artifact.getScope() ); - assertEquals( "Check version", expectedVersion, artifact.getVersion() ); + assertNotNull( artifact, "MNG-1895 Dependency was not added to resolution" ); + assertEquals( expectedScope, artifact.getScope(), "Check artifactScope" ); + assertEquals( expectedVersion, artifact.getVersion(), "Check version" ); ArtifactSpec d = createArtifactSpec( "d", "1.0" ); res = collect( createSet( new Object[] { a.artifact, b.artifact, d.artifact } ), filter ); artifact = getArtifact( "d", res.getArtifacts() ); - assertNotNull( "MNG-1895 Dependency was not added to resolution", artifact ); - assertEquals( "Check artifactScope", d.artifact.getScope(), artifact.getScope() ); - assertEquals( "Check version", "1.0", artifact.getVersion() ); + assertNotNull( artifact, "MNG-1895 Dependency was not added to resolution" ); + assertEquals( d.artifact.getScope(), artifact.getScope(), "Check artifactScope" ); + assertEquals( "1.0", artifact.getVersion(), "Check version" ); } - public void disabledtestOptionalNotTransitiveButVersionIsInfluential() + @Test + @Disabled + public void testOptionalNotTransitiveButVersionIsInfluential() throws ArtifactResolutionException, InvalidVersionSpecificationException { ArtifactSpec a = createArtifactSpec( "a", "1.0" ); @@ -668,12 +678,12 @@ public class DefaultArtifactCollectorTest ArtifactSpec c = createArtifactSpec( "c", "3.0" ); ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact, b.artifact } ) ); - assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, b.artifact, c.artifact, d.artifact, - e.artifact } ), res.getArtifacts() ); + assertEquals( createSet( new Object[] { a.artifact, b.artifact, c.artifact, d.artifact, e.artifact } ), res.getArtifacts(), "Check artifact list" ); Artifact artifact = getArtifact( "c", res.getArtifacts() ); - assertEquals( "Check version", "3.0", artifact.getVersion() ); + assertEquals( "3.0", artifact.getVersion(), "Check version" ); } + @Test public void testTestScopeNotTransitive() throws ArtifactResolutionException, InvalidVersionSpecificationException { @@ -682,9 +692,10 @@ public class DefaultArtifactCollectorTest b.addDependency( "c", "3.0", Artifact.SCOPE_TEST ); ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact, b.artifact } ) ); - assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, b.artifact } ), res.getArtifacts() ); + assertEquals( createSet( new Object[] { a.artifact, b.artifact } ), res.getArtifacts(), "Check artifact list" ); } + @Test public void testSnapshotNotIncluded() throws ArtifactResolutionException, InvalidVersionSpecificationException { @@ -703,6 +714,8 @@ public class DefaultArtifactCollectorTest */ } + @Test + @Disabled("that one does not work") public void testOverConstrainedVersionException() throws ArtifactResolutionException, InvalidVersionSpecificationException { @@ -715,15 +728,11 @@ public class DefaultArtifactCollectorTest ArtifactSpec c = createArtifactSpec( "c", "3.2.1-v3235e" ); - try - { - ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact } ) ); - } - catch ( OverConstrainedVersionException e ) - { - assertTrue( "Versions unordered", e.getMessage().contains( "[3.2.1-v3235e, 3.3.0-v3346]" ) ); - assertTrue( "DependencyTrail unresolved", e.getMessage().contains( "Path to dependency:" ) ); - } + OverConstrainedVersionException e = assertThrows( + OverConstrainedVersionException.class, + () -> collect( createSet( new Object[] { a.artifact } ) ) ); + assertTrue( e.getMessage().contains( "[3.2.1-v3235e, 3.3.0-v3346]" ), "Versions unordered" ); + assertTrue( e.getMessage().contains( "Path to dependency:" ), "DependencyTrail unresolved" ); } private Artifact getArtifact( String id, Set artifacts ) diff --git a/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/AbstractConflictResolverTest.java b/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/AbstractConflictResolverTest.java index 54ae26a1f6..fbb2531a7b 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/AbstractConflictResolverTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/AbstractConflictResolverTest.java @@ -19,20 +19,22 @@ package org.apache.maven.repository.legacy.resolver.conflict; * under the License. */ +import java.util.Collections; + import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.ResolutionNode; import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; import org.apache.maven.artifact.versioning.VersionRange; -import org.apache.maven.repository.legacy.resolver.conflict.ConflictResolver; -import org.codehaus.plexus.ContainerConfiguration; -import org.codehaus.plexus.DefaultPlexusContainer; -import org.codehaus.plexus.PlexusConstants; -import org.codehaus.plexus.PlexusTestCase; +import org.apache.maven.test.PlexusTestCase; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import javax.inject.Inject; -import java.util.Collections; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * Provides a basis for testing conflict resolvers. @@ -71,25 +73,17 @@ public abstract class AbstractConflictResolverTest // TestCase methods ------------------------------------------------------- + /* + * @see junit.framework.TestCase#setUp() + */ + @BeforeEach @Override - protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration ) - { - super.customizeContainerConfiguration( containerConfiguration ); - containerConfiguration.setAutoWiring( true ); - containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); - } - - @Override - protected void setUp() + public void setUp() throws Exception { super.setUp(); - ((DefaultPlexusContainer)getContainer()) - .addPlexusInjector( Collections.emptyList(), - binder -> binder.requestInjection( this ) ); - - conflictResolver = (ConflictResolver) lookup( ConflictResolver.ROLE, roleHint ); + conflictResolver = lookup( ConflictResolver.ROLE, roleHint ); a1 = createArtifact( "a", "1.0" ); a2 = createArtifact( "a", "2.0" ); @@ -99,7 +93,9 @@ public abstract class AbstractConflictResolverTest /* * @see org.codehaus.plexus.PlexusTestCase#tearDown() */ - protected void tearDown() throws Exception + @AfterEach + @Override + public void tearDown() throws Exception { a1 = null; a2 = null; @@ -121,8 +117,8 @@ public abstract class AbstractConflictResolverTest { ResolutionNode resolvedNode = getConflictResolver().resolveConflict( actualNode1, actualNode2 ); - assertNotNull( "Expected resolvable", resolvedNode ); - assertEquals( "Resolution node", expectedNode, resolvedNode ); + assertNotNull( resolvedNode, "Expected resolvable" ); + assertEquals( expectedNode, resolvedNode, "Resolution node" ); } protected Artifact createArtifact( String id, String version ) throws InvalidVersionSpecificationException diff --git a/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/FarthestConflictResolverTest.java b/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/FarthestConflictResolverTest.java index 363c7a2481..7b46ee342d 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/FarthestConflictResolverTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/FarthestConflictResolverTest.java @@ -20,6 +20,7 @@ package org.apache.maven.repository.legacy.resolver.conflict; */ import org.apache.maven.artifact.resolver.ResolutionNode; +import org.junit.jupiter.api.Test; /** * Tests FarthestConflictResolver. @@ -47,6 +48,7 @@ public class FarthestConflictResolverTest * b:1.0 -> a:2.0 * */ + @Test public void testDepth() { ResolutionNode a1n = createResolutionNode( a1); @@ -63,6 +65,7 @@ public class FarthestConflictResolverTest * a:1.0 * */ + @Test public void testDepthReversed() { ResolutionNode b1n = createResolutionNode( b1 ); @@ -79,6 +82,7 @@ public class FarthestConflictResolverTest * a:2.0 * */ + @Test public void testEqual() { ResolutionNode a1n = createResolutionNode( a1 ); @@ -94,6 +98,7 @@ public class FarthestConflictResolverTest * a:1.0 * */ + @Test public void testEqualReversed() { ResolutionNode a2n = createResolutionNode( a2); diff --git a/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/NearestConflictResolverTest.java b/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/NearestConflictResolverTest.java index 23683d56df..34026bc289 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/NearestConflictResolverTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/NearestConflictResolverTest.java @@ -20,6 +20,7 @@ package org.apache.maven.repository.legacy.resolver.conflict; */ import org.apache.maven.artifact.resolver.ResolutionNode; +import org.junit.jupiter.api.Test; /** * Tests NearestConflictResolver. @@ -47,6 +48,7 @@ public class NearestConflictResolverTest * b:1.0 -> a:2.0 * */ + @Test public void testDepth() { ResolutionNode a1n = createResolutionNode( a1); @@ -63,6 +65,7 @@ public class NearestConflictResolverTest * a:1.0 * */ + @Test public void testDepthReversed() { ResolutionNode b1n = createResolutionNode( b1 ); @@ -79,6 +82,7 @@ public class NearestConflictResolverTest * a:2.0 * */ + @Test public void testEqual() { ResolutionNode a1n = createResolutionNode( a1 ); @@ -94,6 +98,7 @@ public class NearestConflictResolverTest * a:1.0 * */ + @Test public void testEqualReversed() { ResolutionNode a2n = createResolutionNode( a2); diff --git a/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/NewestConflictResolverTest.java b/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/NewestConflictResolverTest.java index 4cfffc67e1..874644a9c0 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/NewestConflictResolverTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/NewestConflictResolverTest.java @@ -20,6 +20,7 @@ package org.apache.maven.repository.legacy.resolver.conflict; */ import org.apache.maven.artifact.resolver.ResolutionNode; +import org.junit.jupiter.api.Test; /** * Tests NewestConflictResolver. @@ -47,6 +48,7 @@ public class NewestConflictResolverTest * b:1.0 -> a:2.0 * */ + @Test public void testDepth() { ResolutionNode a1n = createResolutionNode( a1 ); @@ -63,6 +65,7 @@ public class NewestConflictResolverTest * a:1.0 * */ + @Test public void testDepthReversed() { ResolutionNode b1n = createResolutionNode( b1 ); @@ -79,6 +82,7 @@ public class NewestConflictResolverTest * a:2.0 * */ + @Test public void testEqual() { ResolutionNode a1n = createResolutionNode( a1 ); @@ -94,6 +98,7 @@ public class NewestConflictResolverTest * a:1.0 * */ + @Test public void testEqualReversed() { ResolutionNode a2n = createResolutionNode( a2 ); diff --git a/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/OldestConflictResolverTest.java b/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/OldestConflictResolverTest.java index 8744de2b05..76335f26af 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/OldestConflictResolverTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/OldestConflictResolverTest.java @@ -20,6 +20,7 @@ package org.apache.maven.repository.legacy.resolver.conflict; */ import org.apache.maven.artifact.resolver.ResolutionNode; +import org.junit.jupiter.api.Test; /** * Tests OldestConflictResolver. @@ -47,6 +48,7 @@ public class OldestConflictResolverTest * b:1.0 -> a:2.0 * */ + @Test public void testDepth() { ResolutionNode a1n = createResolutionNode( a1 ); @@ -64,6 +66,7 @@ public class OldestConflictResolverTest * a:1.0 * */ + @Test public void testDepthReversed() { ResolutionNode b1n = createResolutionNode( b1 ); @@ -80,6 +83,7 @@ public class OldestConflictResolverTest * a:2.0 * */ + @Test public void testEqual() { ResolutionNode a1n = createResolutionNode( a1 ); @@ -95,6 +99,7 @@ public class OldestConflictResolverTest * a:1.0 * */ + @Test public void testEqualReversed() { ResolutionNode a2n = createResolutionNode( a2); diff --git a/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultClasspathTransformationTest.java b/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultClasspathTransformationTest.java index 339ce24c3e..ebe0fd50aa 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultClasspathTransformationTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultClasspathTransformationTest.java @@ -15,14 +15,15 @@ package org.apache.maven.repository.metadata; * the License. */ +import javax.inject.Inject; + import org.apache.maven.artifact.ArtifactScopeEnum; -import org.apache.maven.repository.metadata.ArtifactMetadata; -import org.apache.maven.repository.metadata.ClasspathContainer; -import org.apache.maven.repository.metadata.ClasspathTransformation; -import org.apache.maven.repository.metadata.MetadataGraph; -import org.apache.maven.repository.metadata.MetadataGraphEdge; -import org.apache.maven.repository.metadata.MetadataGraphVertex; -import org.codehaus.plexus.PlexusTestCase; +import org.apache.maven.test.PlexusTestCase; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.BeforeEach; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * @@ -33,6 +34,7 @@ import org.codehaus.plexus.PlexusTestCase; public class DefaultClasspathTransformationTest extends PlexusTestCase { + @Inject ClasspathTransformation transform; MetadataGraph graph; @@ -42,11 +44,11 @@ extends PlexusTestCase MetadataGraphVertex v3; MetadataGraphVertex v4; //------------------------------------------------------------------------------------------ + @BeforeEach @Override - protected void setUp() throws Exception + public void setUp() throws Exception { super.setUp(); - transform = (ClasspathTransformation) lookup( ClasspathTransformation.ROLE, "default" ); graph = new MetadataGraph( 4, 3 ); /* @@ -74,6 +76,7 @@ extends PlexusTestCase graph.addEdge(v3, v4, new MetadataGraphEdge( "1.2", true, ArtifactScopeEnum.test, null, 2, 2 ) ); } //------------------------------------------------------------------------------------------ + @Test public void testCompileClasspathTransform() throws Exception { @@ -81,11 +84,12 @@ extends PlexusTestCase res = transform.transform( graph, ArtifactScopeEnum.compile, false ); - assertNotNull("null classpath container after compile transform", res ); - assertNotNull("null classpath after compile transform", res.getClasspath() ); - assertEquals("compile classpath should have 3 entries", 3, res.getClasspath().size() ); + assertNotNull( res, "null classpath container after compile transform" ); + assertNotNull( res.getClasspath(), "null classpath after compile transform" ); + assertEquals( 3, res.getClasspath().size(), "compile classpath should have 3 entries" ); } //------------------------------------------------------------------------------------------ + @Test public void testRuntimeClasspathTransform() throws Exception { @@ -93,14 +97,15 @@ extends PlexusTestCase res = transform.transform( graph, ArtifactScopeEnum.runtime, false ); - assertNotNull("null classpath container after runtime transform", res ); - assertNotNull("null classpath after runtime transform", res.getClasspath() ); - assertEquals("runtime classpath should have 4 entries", 4, res.getClasspath().size() ); + assertNotNull( res, "null classpath container after runtime transform" ); + assertNotNull( res.getClasspath(), "null classpath after runtime transform" ); + assertEquals( 4, res.getClasspath().size(), "runtime classpath should have 4 entries" ); ArtifactMetadata md = res.getClasspath().get(3); - assertEquals("runtime artifact version should be 1.1", "1.1", md.getVersion() ); + assertEquals("1.1", md.getVersion(), "runtime artifact version should be 1.1" ); } //------------------------------------------------------------------------------------------ + @Test public void testTestClasspathTransform() throws Exception { @@ -108,12 +113,12 @@ extends PlexusTestCase res = transform.transform( graph, ArtifactScopeEnum.test, false ); - assertNotNull("null classpath container after runtime transform", res ); - assertNotNull("null classpath after runtime transform", res.getClasspath() ); - assertEquals("runtime classpath should have 4 entries", 4, res.getClasspath().size() ); + assertNotNull( res, "null classpath container after test transform" ); + assertNotNull( res.getClasspath(), "null classpath after test transform" ); + assertEquals( 4, res.getClasspath().size(), "test classpath should have 4 entries" ); ArtifactMetadata md = res.getClasspath().get(3); - assertEquals("test artifact version should be 1.2", "1.2", md.getVersion() ); + assertEquals("1.2", md.getVersion(), "test artifact version should be 1.2" ); } //------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------ diff --git a/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolutionPolicyTest.java b/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolutionPolicyTest.java index 472f018b2a..ea4352e504 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolutionPolicyTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolutionPolicyTest.java @@ -15,10 +15,10 @@ package org.apache.maven.repository.metadata; * the License. */ -import org.apache.maven.repository.metadata.GraphConflictResolutionPolicy; -import org.apache.maven.repository.metadata.MetadataGraphEdge; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @@ -27,33 +27,32 @@ import junit.framework.TestCase; */ public class DefaultGraphConflictResolutionPolicyTest - extends TestCase { GraphConflictResolutionPolicy policy; MetadataGraphEdge e1; MetadataGraphEdge e2; MetadataGraphEdge e3; //------------------------------------------------------------------------------------------ - @Override - protected void setUp() throws Exception - { - super.setUp(); - policy = new DefaultGraphConflictResolutionPolicy(); - e1 = new MetadataGraphEdge( "1.1", true, null, null, 2, 1 ); - e2 = new MetadataGraphEdge( "1.2", true, null, null, 3, 2 ); - e3 = new MetadataGraphEdge( "1.2", true, null, null, 2, 3 ); - } + @BeforeEach + public void setUp() throws Exception + { + policy = new DefaultGraphConflictResolutionPolicy(); + e1 = new MetadataGraphEdge( "1.1", true, null, null, 2, 1 ); + e2 = new MetadataGraphEdge( "1.2", true, null, null, 3, 2 ); + e3 = new MetadataGraphEdge( "1.2", true, null, null, 2, 3 ); + } //------------------------------------------------------------------------------------------ + @Test public void testDefaultPolicy() throws Exception { MetadataGraphEdge res; res = policy.apply( e1, e2 ); - assertEquals( "Wrong depth edge selected", "1.1", res.getVersion() ); + assertEquals( "1.1", res.getVersion(), "Wrong depth edge selected" ); res = policy.apply( e1, e3 ); - assertEquals( "Wrong version edge selected", "1.2", res.getVersion() ); + assertEquals( "1.2", res.getVersion(), "Wrong version edge selected" ); } //------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------ diff --git a/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolverTest.java b/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolverTest.java index ccd25b43bc..a41464a1c3 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolverTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolverTest.java @@ -15,14 +15,15 @@ package org.apache.maven.repository.metadata; * the License. */ +import javax.inject.Inject; + import org.apache.maven.artifact.ArtifactScopeEnum; -import org.apache.maven.repository.metadata.ArtifactMetadata; -import org.apache.maven.repository.metadata.GraphConflictResolver; -import org.apache.maven.repository.metadata.MetadataGraph; -import org.apache.maven.repository.metadata.MetadataGraphEdge; -import org.apache.maven.repository.metadata.MetadataGraphVertex; -import org.codehaus.plexus.PlexusTestCase; -import org.codehaus.plexus.logging.Logger; +import org.apache.maven.test.PlexusTestCase; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * @@ -33,8 +34,7 @@ import org.codehaus.plexus.logging.Logger; public class DefaultGraphConflictResolverTest extends PlexusTestCase { - Logger log; - + @Inject GraphConflictResolver resolver; MetadataGraph graph; @@ -44,11 +44,11 @@ extends PlexusTestCase MetadataGraphVertex v3; MetadataGraphVertex v4; //------------------------------------------------------------------------------------------ + @BeforeEach @Override - protected void setUp() throws Exception + public void setUp() throws Exception { super.setUp(); - resolver = (GraphConflictResolver) lookup( GraphConflictResolver.ROLE, "default" ); /* * v2 @@ -76,6 +76,7 @@ extends PlexusTestCase graph.addEdge(v3, v4, new MetadataGraphEdge( "1.2", true, ArtifactScopeEnum.provided, null, 2, 2 ) ); } //------------------------------------------------------------------------------------------ + @Test public void testCompileResolution() throws Exception { @@ -83,24 +84,25 @@ extends PlexusTestCase res = resolver.resolveConflicts( graph, ArtifactScopeEnum.compile ); - assertNotNull("null graph after resolver", res ); - assertNotNull("no vertices in the resulting graph after resolver", res.getVertices() ); + assertNotNull( res, "null graph after resolver" ); + assertNotNull( res.getVertices(), "no vertices in the resulting graph after resolver" ); - assertNotNull("no edges in the resulting graph after resolver", res.getExcidentEdges(v1) ); + assertNotNull( res.getExcidentEdges(v1), "no edges in the resulting graph after resolver" ); - assertEquals( "wrong # of vertices in the resulting graph after resolver", 4, res.getVertices().size() ); - assertEquals( "wrong # of excident edges in the resulting graph entry after resolver", 2, res.getExcidentEdges(v1).size() ); + assertEquals( 4, res.getVertices().size(), "wrong # of vertices in the resulting graph after resolver" ); + assertEquals( 2, res.getExcidentEdges(v1).size(), "wrong # of excident edges in the resulting graph entry after resolver" ); - assertEquals( "wrong # of v2 incident edges in the resulting graph after resolver", 1, res.getIncidentEdges(v2).size() ); - assertEquals( "wrong edge v1-v2 in the resulting graph after resolver", "1.2", res.getIncidentEdges(v2).get(0).getVersion() ); + assertEquals( 1, res.getIncidentEdges(v2).size(), "wrong # of v2 incident edges in the resulting graph after resolver" ); + assertEquals( "1.2", res.getIncidentEdges(v2).get(0).getVersion(), "wrong edge v1-v2 in the resulting graph after resolver" ); - assertEquals( "wrong # of edges v1-v3 in the resulting graph after resolver", 1, res.getIncidentEdges(v3).size() ); - assertEquals( "wrong edge v1-v3 in the resulting graph after resolver", "1.1", res.getIncidentEdges(v3).get(0).getVersion() ); + assertEquals( 1, res.getIncidentEdges(v3).size(), "wrong # of edges v1-v3 in the resulting graph after resolver" ); + assertEquals( "1.1", res.getIncidentEdges(v3).get(0).getVersion(), "wrong edge v1-v3 in the resulting graph after resolver" ); - assertEquals( "wrong # of edges v3-v4 in the resulting graph after resolver", 1, res.getIncidentEdges(v4).size() ); - assertEquals( "wrong edge v3-v4 in the resulting graph after resolver", "1.2", res.getIncidentEdges(v4).get(0).getVersion() ); + assertEquals( 1, res.getIncidentEdges(v4).size(), "wrong # of edges v3-v4 in the resulting graph after resolver" ); + assertEquals( "1.2", res.getIncidentEdges(v4).get(0).getVersion(), "wrong edge v3-v4 in the resulting graph after resolver" ); } //------------------------------------------------------------------------------------------ + @Test public void testRuntimeResolution() throws Exception { @@ -108,23 +110,24 @@ extends PlexusTestCase res = resolver.resolveConflicts( graph, ArtifactScopeEnum.runtime ); - assertNotNull("null graph after resolver", res ); - assertNotNull("no vertices in the resulting graph after resolver", res.getVertices() ); - assertNotNull("no edges in the resulting graph after resolver", res.getExcidentEdges(v1) ); + assertNotNull( res, "null graph after resolver" ); + assertNotNull( res.getVertices(), "no vertices in the resulting graph after resolver" ); + assertNotNull( res.getExcidentEdges(v1), "no edges in the resulting graph after resolver" ); - assertEquals( "wrong # of vertices in the resulting graph after resolver", 4, res.getVertices().size() ); - assertEquals( "wrong # of excident edges in the resulting graph entry after resolver", 2, res.getExcidentEdges(v1).size() ); + assertEquals( 4, res.getVertices().size(), "wrong # of vertices in the resulting graph after resolver" ); + assertEquals( 2, res.getExcidentEdges(v1).size(), "wrong # of excident edges in the resulting graph entry after resolver" ); - assertEquals( "wrong # of v2 incident edges in the resulting graph after resolver", 1, res.getIncidentEdges(v2).size() ); - assertEquals( "wrong edge v1-v2 in the resulting graph after resolver", "1.2", res.getIncidentEdges(v2).get(0).getVersion() ); + assertEquals( 1, res.getIncidentEdges(v2).size(), "wrong # of v2 incident edges in the resulting graph after resolver" ); + assertEquals( "1.2", res.getIncidentEdges(v2).get(0).getVersion(), "wrong edge v1-v2 in the resulting graph after resolver" ); - assertEquals( "wrong # of edges v1-v3 in the resulting graph after resolver", 1, res.getIncidentEdges(v3).size() ); - assertEquals( "wrong edge v1-v3 in the resulting graph after resolver", "1.1", res.getIncidentEdges(v3).get(0).getVersion() ); + assertEquals( 1, res.getIncidentEdges(v3).size(), "wrong # of edges v1-v3 in the resulting graph after resolver" ); + assertEquals( "1.1", res.getIncidentEdges(v3).get(0).getVersion(), "wrong edge v1-v3 in the resulting graph after resolver" ); - assertEquals( "wrong # of edges v3-v4 in the resulting graph after resolver", 1, res.getIncidentEdges(v4).size() ); - assertEquals( "wrong edge v3-v4 in the resulting graph after resolver", "1.1", res.getIncidentEdges(v4).get(0).getVersion() ); + assertEquals( 1, res.getIncidentEdges(v4).size(), "wrong # of edges v3-v4 in the resulting graph after resolver" ); + assertEquals( "1.1", res.getIncidentEdges(v4).get(0).getVersion(), "wrong edge v3-v4 in the resulting graph after resolver" ); } //------------------------------------------------------------------------------------------ + @Test public void testTestResolution() throws Exception { @@ -132,21 +135,21 @@ extends PlexusTestCase res = resolver.resolveConflicts( graph, ArtifactScopeEnum.test ); - assertNotNull("null graph after resolver", res ); - assertNotNull("no vertices in the resulting graph after resolver", res.getVertices() ); - assertNotNull("no edges in the resulting graph after resolver", res.getExcidentEdges(v1) ); + assertNotNull( res, "null graph after resolver" ); + assertNotNull( res.getVertices(), "no vertices in the resulting graph after resolver" ); + assertNotNull( res.getExcidentEdges(v1), "no edges in the resulting graph after resolver" ); - assertEquals( "wrong # of vertices in the resulting graph after resolver", 4, res.getVertices().size() ); - assertEquals( "wrong # of excident edges in the resulting graph entry after resolver", 2, res.getExcidentEdges(v1).size() ); + assertEquals( 4, res.getVertices().size(), "wrong # of vertices in the resulting graph after resolver" ); + assertEquals( 2, res.getExcidentEdges(v1).size(), "wrong # of excident edges in the resulting graph entry after resolver" ); - assertEquals( "wrong # of v2 incident edges in the resulting graph after resolver", 1, res.getIncidentEdges(v2).size() ); - assertEquals( "wrong edge v1-v2 in the resulting graph after resolver", "1.2", res.getIncidentEdges(v2).get(0).getVersion() ); + assertEquals( 1, res.getIncidentEdges(v2).size(), "wrong # of v2 incident edges in the resulting graph after resolver" ); + assertEquals( "1.2", res.getIncidentEdges(v2).get(0).getVersion(), "wrong edge v1-v2 in the resulting graph after resolver" ); - assertEquals( "wrong # of edges v1-v3 in the resulting graph after resolver", 1, res.getIncidentEdges(v3).size() ); - assertEquals( "wrong edge v1-v3 in the resulting graph after resolver", "1.1", res.getIncidentEdges(v3).get(0).getVersion() ); + assertEquals( 1, res.getIncidentEdges(v3).size(), "wrong # of edges v1-v3 in the resulting graph after resolver" ); + assertEquals( "1.1", res.getIncidentEdges(v3).get(0).getVersion(), "wrong edge v1-v3 in the resulting graph after resolver" ); - assertEquals( "wrong # of edges v3-v4 in the resulting graph after resolver", 1, res.getIncidentEdges(v4).size() ); - assertEquals( "wrong edge v3-v4 in the resulting graph after resolver", "1.2", res.getIncidentEdges(v4).get(0).getVersion() ); + assertEquals( 1, res.getIncidentEdges(v4).size(), "wrong # of edges v3-v4 in the resulting graph after resolver" ); + assertEquals( "1.2", res.getIncidentEdges(v4).get(0).getVersion(), "wrong edge v3-v4 in the resulting graph after resolver" ); } //------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------ diff --git a/maven-compat/src/test/java/org/apache/maven/repository/metadata/TestMetadataSource.java b/maven-compat/src/test/java/org/apache/maven/repository/metadata/TestMetadataSource.java index fbb9035830..efec2e6ea7 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/metadata/TestMetadataSource.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/metadata/TestMetadataSource.java @@ -19,6 +19,10 @@ package org.apache.maven.repository.metadata; * under the License. */ +import java.util.HashSet; +import java.util.List; +import java.util.Set; + import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.repository.ArtifactRepository; @@ -31,9 +35,6 @@ import org.apache.maven.repository.legacy.metadata.ResolutionGroup; import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; -import java.util.HashSet; -import java.util.List; -import java.util.Set; @Named @Singleton diff --git a/maven-core/pom.xml b/maven-core/pom.xml index 661ae9bf12..4316ff7ed4 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -156,6 +156,11 @@ under the License. xmlunit-assertj test + + org.apache.maven + maven-test-support + test + diff --git a/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java b/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java index de0f99beef..3b5b7a6bd4 100644 --- a/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java +++ b/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java @@ -22,7 +22,6 @@ package org.apache.maven; import java.io.File; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Properties; @@ -45,14 +44,14 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.project.ProjectBuildingRequest; import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.internal.MavenRepositorySystemUtils; +import org.apache.maven.test.PlexusTestCase; import org.codehaus.plexus.ContainerConfiguration; -import org.codehaus.plexus.DefaultPlexusContainer; import org.codehaus.plexus.PlexusConstants; -import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.util.FileUtils; import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; import org.eclipse.aether.repository.LocalRepository; +import org.junit.jupiter.api.BeforeEach; import javax.inject.Inject; @@ -65,22 +64,6 @@ public abstract class AbstractCoreMavenComponentTestCase @Inject protected org.apache.maven.project.ProjectBuilder projectBuilder; - @Override - protected void setUp() throws Exception - { - super.setUp(); - getContainer(); - } - - @Override - protected synchronized void setupContainer() - { - super.setupContainer(); - - ( (DefaultPlexusContainer) getContainer() ).addPlexusInjector( Collections.emptyList(), - binder -> binder.requestInjection( this ) ); - } - abstract protected String getProjectsDirectory(); protected File getProject( String name ) diff --git a/maven-core/src/test/java/org/apache/maven/DefaultMavenTest.java b/maven-core/src/test/java/org/apache/maven/DefaultMavenTest.java index c63acbc146..3a85ea4ad6 100644 --- a/maven-core/src/test/java/org/apache/maven/DefaultMavenTest.java +++ b/maven-core/src/test/java/org/apache/maven/DefaultMavenTest.java @@ -1,5 +1,3 @@ -package org.apache.maven; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,12 @@ package org.apache.maven; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven; + +import java.io.File; +import java.nio.file.Files; + +import javax.inject.Inject; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DefaultArtifact; @@ -25,13 +29,10 @@ import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenExecutionResult; import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectHelper; - -import java.io.File; -import java.nio.file.Files; - -import javax.inject.Inject; +import org.junit.jupiter.api.Test; import static java.util.Arrays.asList; +import static org.junit.jupiter.api.Assertions.assertEquals; public class DefaultMavenTest extends AbstractCoreMavenComponentTestCase @@ -40,6 +41,14 @@ public class DefaultMavenTest @Inject private Maven maven; + @Override + protected String getProjectsDirectory() + { + return "src/test/projects/default-maven"; + } + + + @Test public void testThatErrorDuringProjectDependencyGraphCreationAreStored() throws Exception { @@ -50,13 +59,7 @@ public class DefaultMavenTest assertEquals( ProjectCycleException.class, result.getExceptions().get( 0 ).getClass() ); } - @Override - protected String getProjectsDirectory() - { - return "src/test/projects/default-maven"; - } - - + @Test public void testMavenProjectNoDuplicateArtifacts() throws Exception { diff --git a/maven-core/src/test/java/org/apache/maven/MavenLifecycleParticipantTest.java b/maven-core/src/test/java/org/apache/maven/MavenLifecycleParticipantTest.java index 7d02856640..13ff67a1d6 100644 --- a/maven-core/src/test/java/org/apache/maven/MavenLifecycleParticipantTest.java +++ b/maven-core/src/test/java/org/apache/maven/MavenLifecycleParticipantTest.java @@ -29,6 +29,10 @@ import org.apache.maven.model.Dependency; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.component.repository.ComponentDescriptor; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; public class MavenLifecycleParticipantTest extends AbstractCoreMavenComponentTestCase @@ -109,6 +113,7 @@ public class MavenLifecycleParticipantTest return "src/test/projects/lifecycle-listener"; } + @Test public void testDependencyInjection() throws Exception { @@ -126,7 +131,7 @@ public class MavenLifecycleParticipantTest request.setGoals( Arrays.asList( "validate" ) ); MavenExecutionResult result = maven.execute( request ); - assertFalse( result.getExceptions().toString(), result.hasExceptions() ); + assertFalse( result.hasExceptions(), result.getExceptions().toString() ); MavenProject project = result.getProject(); @@ -138,6 +143,7 @@ public class MavenLifecycleParticipantTest assertEquals( INJECTED_ARTIFACT_ID, artifacts.get( 0 ).getArtifactId() ); } + @Test public void testReactorDependencyInjection() throws Exception { @@ -161,7 +167,7 @@ public class MavenLifecycleParticipantTest request.setGoals( Arrays.asList( "validate" ) ); MavenExecutionResult result = maven.execute( request ); - assertFalse( result.getExceptions().toString(), result.hasExceptions() ); + assertFalse( result.hasExceptions(), result.getExceptions().toString() ); List order = new ArrayList<>(); for ( MavenProject project : result.getTopologicallySortedProjects() ) diff --git a/maven-core/src/test/java/org/apache/maven/MavenTest.java b/maven-core/src/test/java/org/apache/maven/MavenTest.java index 711199a9de..991e61d0a7 100644 --- a/maven-core/src/test/java/org/apache/maven/MavenTest.java +++ b/maven-core/src/test/java/org/apache/maven/MavenTest.java @@ -17,14 +17,9 @@ package org.apache.maven; import org.apache.maven.exception.ExceptionHandler; -import org.apache.maven.exception.ExceptionSummary; -import org.apache.maven.execution.MavenExecutionRequest; -import org.apache.maven.execution.MavenExecutionResult; -import org.codehaus.plexus.DefaultPlexusContainer; +import org.junit.jupiter.api.Test; import javax.inject.Inject; -import java.io.File; -import java.util.Collections; public class MavenTest extends AbstractCoreMavenComponentTestCase @@ -35,20 +30,12 @@ public class MavenTest @Inject private ExceptionHandler exceptionHandler; - @Override - protected synchronized void setupContainer() - { - super.setupContainer(); - - ( (DefaultPlexusContainer) getContainer() ).addPlexusInjector( Collections.emptyList(), - binder -> binder.requestInjection( this ) ); - } - protected String getProjectsDirectory() { return "src/test/projects/lifecycle-executor"; } + @Test public void testLifecycleExecutionUsingADefaultLifecyclePhase() throws Exception { diff --git a/maven-core/src/test/java/org/apache/maven/ProjectDependenciesResolverTest.java b/maven-core/src/test/java/org/apache/maven/ProjectDependenciesResolverTest.java index d3b2eaa5b6..777bae5a8b 100644 --- a/maven-core/src/test/java/org/apache/maven/ProjectDependenciesResolverTest.java +++ b/maven-core/src/test/java/org/apache/maven/ProjectDependenciesResolverTest.java @@ -15,9 +15,6 @@ package org.apache.maven; * the License. */ -import static org.hamcrest.Matchers.endsWith; -import static org.junit.Assert.assertThat; - import java.io.File; import java.util.Collections; import java.util.List; @@ -29,6 +26,11 @@ import org.apache.maven.execution.MavenSession; import org.apache.maven.project.MavenProject; import javax.inject.Inject; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.Matchers.endsWith; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.hamcrest.MatcherAssert.assertThat; public class ProjectDependenciesResolverTest extends AbstractCoreMavenComponentTestCase @@ -42,6 +44,7 @@ public class ProjectDependenciesResolverTest } /* + @Test public void testExclusionsInDependencies() throws Exception { @@ -65,6 +68,7 @@ public class ProjectDependenciesResolverTest } */ + @Test public void testSystemScopeDependencies() throws Exception { @@ -79,6 +83,7 @@ public class ProjectDependenciesResolverTest assertEquals( 1, artifactDependencies.size() ); } + @Test public void testSystemScopeDependencyIsPresentInTheCompileClasspathElements() throws Exception { diff --git a/maven-core/src/test/java/org/apache/maven/artifact/handler/ArtifactHandlerTest.java b/maven-core/src/test/java/org/apache/maven/artifact/handler/ArtifactHandlerTest.java index 2803d8d80a..6dba994a39 100644 --- a/maven-core/src/test/java/org/apache/maven/artifact/handler/ArtifactHandlerTest.java +++ b/maven-core/src/test/java/org/apache/maven/artifact/handler/ArtifactHandlerTest.java @@ -22,12 +22,16 @@ package org.apache.maven.artifact.handler; import java.io.File; import java.util.List; -import org.codehaus.plexus.PlexusTestCase; +import org.apache.maven.test.PlexusTestCase; import org.codehaus.plexus.util.FileUtils; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class ArtifactHandlerTest extends PlexusTestCase { + @Test public void testAptConsistency() throws Exception { @@ -47,7 +51,7 @@ public class ArtifactHandlerTest int i = 0; for ( String col : cols ) { - assertEquals( "Wrong column header", expected[i++], col.trim() ); + assertEquals( expected[i++], col.trim(), "Wrong column header" ); } } else if ( line.startsWith( "|" ) ) @@ -63,12 +67,12 @@ public class ArtifactHandlerTest String includesDependencies = trimApt( cols[7] ); ArtifactHandler handler = lookup( ArtifactHandler.class, type ); - assertEquals( type + " extension", handler.getExtension(), extension ); - assertEquals( type + " packaging", handler.getPackaging(), packaging ); - assertEquals( type + " classifier", handler.getClassifier(), classifier ); - assertEquals( type + " language", handler.getLanguage(), language ); - assertEquals( type + " addedToClasspath", handler.isAddedToClasspath() ? "true" : null, addedToClasspath ); - assertEquals( type + " includesDependencies", handler.isIncludesDependencies() ? "true" : null, includesDependencies ); + assertEquals( handler.getExtension(), extension, type + " extension" ); + assertEquals( handler.getPackaging(), packaging, type + " packaging" ); + assertEquals( handler.getClassifier(), classifier, type + " classifier" ); + assertEquals( handler.getLanguage(), language, type + " language" ); + assertEquals( handler.isAddedToClasspath() ? "true" : null, addedToClasspath, type + " addedToClasspath" ); + assertEquals( handler.isIncludesDependencies() ? "true" : null, includesDependencies, type + " includesDependencies" ); } } } diff --git a/maven-core/src/test/java/org/apache/maven/artifact/resolver/filter/ExclusionArtifactFilterTest.java b/maven-core/src/test/java/org/apache/maven/artifact/resolver/filter/ExclusionArtifactFilterTest.java index c504c96bb9..76b1654644 100644 --- a/maven-core/src/test/java/org/apache/maven/artifact/resolver/filter/ExclusionArtifactFilterTest.java +++ b/maven-core/src/test/java/org/apache/maven/artifact/resolver/filter/ExclusionArtifactFilterTest.java @@ -21,14 +21,14 @@ package org.apache.maven.artifact.resolver.filter; import org.apache.maven.artifact.Artifact; import org.apache.maven.model.Exclusion; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.BeforeEach; import java.util.Arrays; import java.util.Collections; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -36,7 +36,7 @@ public class ExclusionArtifactFilterTest { private Artifact artifact; - @Before + @BeforeEach public void setup() { artifact = mock( Artifact.class ); diff --git a/maven-core/src/test/java/org/apache/maven/configuration/DefaultBeanConfiguratorTest.java b/maven-core/src/test/java/org/apache/maven/configuration/DefaultBeanConfiguratorTest.java index a0588a2c9e..3dd3eff7f5 100644 --- a/maven-core/src/test/java/org/apache/maven/configuration/DefaultBeanConfiguratorTest.java +++ b/maven-core/src/test/java/org/apache/maven/configuration/DefaultBeanConfiguratorTest.java @@ -27,34 +27,32 @@ import org.apache.maven.configuration.internal.DefaultBeanConfigurator; import org.codehaus.plexus.util.xml.Xpp3Dom; import org.codehaus.plexus.util.xml.Xpp3DomBuilder; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Benjamin Bentmann */ public class DefaultBeanConfiguratorTest - extends TestCase { private BeanConfigurator configurator; - @Override - protected void setUp() + @BeforeEach + public void setUp() throws Exception { - super.setUp(); - configurator = new DefaultBeanConfigurator(); } - @Override - protected void tearDown() + @AfterEach + public void tearDown() throws Exception { configurator = null; - - super.tearDown(); } private Xpp3Dom toConfig( String xml ) @@ -69,6 +67,7 @@ public class DefaultBeanConfiguratorTest } } + @Test public void testMinimal() throws BeanConfigurationException { @@ -84,6 +83,7 @@ public class DefaultBeanConfiguratorTest assertEquals( new File( "test" ), bean.file ); } + @Test public void testPreAndPostProcessing() throws BeanConfigurationException { @@ -111,6 +111,7 @@ public class DefaultBeanConfiguratorTest assertEquals( new File( "base/test" ).getAbsoluteFile(), bean.file ); } + @Test public void testChildConfigurationElement() throws BeanConfigurationException { diff --git a/maven-core/src/test/java/org/apache/maven/exception/DefaultExceptionHandlerTest.java b/maven-core/src/test/java/org/apache/maven/exception/DefaultExceptionHandlerTest.java index 9fe6d4f30f..48cdb2fba1 100644 --- a/maven-core/src/test/java/org/apache/maven/exception/DefaultExceptionHandlerTest.java +++ b/maven-core/src/test/java/org/apache/maven/exception/DefaultExceptionHandlerTest.java @@ -30,9 +30,9 @@ import org.apache.maven.plugin.PluginContainerException; import org.apache.maven.plugin.PluginExecutionException; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Barrie Treloar diff --git a/maven-core/src/test/java/org/apache/maven/execution/DefaultBuildResumptionAnalyzerTest.java b/maven-core/src/test/java/org/apache/maven/execution/DefaultBuildResumptionAnalyzerTest.java index 6e037763e2..df4941c434 100644 --- a/maven-core/src/test/java/org/apache/maven/execution/DefaultBuildResumptionAnalyzerTest.java +++ b/maven-core/src/test/java/org/apache/maven/execution/DefaultBuildResumptionAnalyzerTest.java @@ -22,8 +22,8 @@ package org.apache.maven.execution; import org.apache.maven.lifecycle.LifecycleExecutionException; import org.apache.maven.model.Dependency; import org.apache.maven.project.MavenProject; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.Optional; @@ -40,7 +40,7 @@ public class DefaultBuildResumptionAnalyzerTest private MavenExecutionResult executionResult; - @Before + @BeforeEach public void before() { executionResult = new DefaultMavenExecutionResult(); } diff --git a/maven-core/src/test/java/org/apache/maven/execution/DefaultBuildResumptionDataRepositoryTest.java b/maven-core/src/test/java/org/apache/maven/execution/DefaultBuildResumptionDataRepositoryTest.java index 697c74f9a0..e1e1fa41ac 100644 --- a/maven-core/src/test/java/org/apache/maven/execution/DefaultBuildResumptionDataRepositoryTest.java +++ b/maven-core/src/test/java/org/apache/maven/execution/DefaultBuildResumptionDataRepositoryTest.java @@ -21,9 +21,7 @@ package org.apache.maven.execution; import org.apache.maven.model.Build; import org.apache.maven.project.MavenProject; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; @@ -34,7 +32,6 @@ import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.is; -@RunWith( MockitoJUnitRunner.class ) public class DefaultBuildResumptionDataRepositoryTest { private final DefaultBuildResumptionDataRepository repository = new DefaultBuildResumptionDataRepository(); diff --git a/maven-core/src/test/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulatorTest.java b/maven-core/src/test/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulatorTest.java index bcc5895b7b..e57e79133f 100644 --- a/maven-core/src/test/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulatorTest.java +++ b/maven-core/src/test/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulatorTest.java @@ -8,7 +8,10 @@ import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.settings.Profile; import org.apache.maven.settings.Repository; import org.apache.maven.settings.Settings; -import org.eclipse.sisu.launch.InjectedTestCase; +import org.apache.maven.test.PlexusTestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -30,11 +33,12 @@ import org.eclipse.sisu.launch.InjectedTestCase; */ public class DefaultMavenExecutionRequestPopulatorTest - extends InjectedTestCase + extends PlexusTestCase { @Inject MavenExecutionRequestPopulator testee; + @Test public void testPluginRepositoryInjection() throws Exception { diff --git a/maven-core/src/test/java/org/apache/maven/execution/DefaultMavenExecutionTest.java b/maven-core/src/test/java/org/apache/maven/execution/DefaultMavenExecutionTest.java index 237362e451..9a363eeeaf 100644 --- a/maven-core/src/test/java/org/apache/maven/execution/DefaultMavenExecutionTest.java +++ b/maven-core/src/test/java/org/apache/maven/execution/DefaultMavenExecutionTest.java @@ -20,14 +20,14 @@ package org.apache.maven.execution; */ import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.hamcrest.MatcherAssert.assertThat; import java.util.List; import org.apache.maven.project.MavenProject; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Benjamin Bentmann diff --git a/maven-core/src/test/java/org/apache/maven/execution/scope/internal/MojoExecutionScopeTest.java b/maven-core/src/test/java/org/apache/maven/execution/scope/internal/MojoExecutionScopeTest.java index c7db866bff..0dda0501b0 100644 --- a/maven-core/src/test/java/org/apache/maven/execution/scope/internal/MojoExecutionScopeTest.java +++ b/maven-core/src/test/java/org/apache/maven/execution/scope/internal/MojoExecutionScopeTest.java @@ -16,17 +16,19 @@ package org.apache.maven.execution.scope.internal; import java.util.concurrent.atomic.AtomicInteger; +import com.google.inject.Key; import org.apache.maven.execution.MojoExecutionEvent; import org.apache.maven.execution.scope.WeakMojoExecutionListener; import org.apache.maven.plugin.MojoExecutionException; +import org.junit.jupiter.api.Test; -import junit.framework.TestCase; - -import com.google.inject.Key; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; public class MojoExecutionScopeTest - extends TestCase { + @Test public void testNestedEnter() throws Exception { @@ -48,16 +50,10 @@ public class MojoExecutionScopeTest scope.exit(); - try - { - scope.exit(); - fail(); - } - catch ( IllegalStateException expected ) - { - } + assertThrows( IllegalStateException.class, () -> scope.exit() ); } + @Test public void testMultiKeyInstance() throws Exception { diff --git a/maven-core/src/test/java/org/apache/maven/graph/DefaultGraphBuilderTest.java b/maven-core/src/test/java/org/apache/maven/graph/DefaultGraphBuilderTest.java index 6a8320bae1..d2f29e2dee 100644 --- a/maven-core/src/test/java/org/apache/maven/graph/DefaultGraphBuilderTest.java +++ b/maven-core/src/test/java/org/apache/maven/graph/DefaultGraphBuilderTest.java @@ -37,12 +37,12 @@ import org.apache.maven.project.collector.MultiModuleCollectionStrategy; import org.apache.maven.project.collector.PomlessCollectionStrategy; import org.apache.maven.project.collector.ProjectsSelector; import org.apache.maven.project.collector.RequestPomCollectionStrategy; +import org.apache.maven.test.Parameter; +import org.apache.maven.test.Parameterized; +import org.apache.maven.test.Parameters; +import org.apache.maven.test.Test; import org.codehaus.plexus.util.StringUtils; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.BeforeEach; import java.io.File; import java.util.ArrayList; @@ -56,15 +56,15 @@ import static java.util.Arrays.asList; import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; import static java.util.function.Function.identity; -import static junit.framework.TestCase.assertEquals; import static org.apache.maven.execution.MavenExecutionRequest.REACTOR_MAKE_DOWNSTREAM; import static org.apache.maven.execution.MavenExecutionRequest.REACTOR_MAKE_UPSTREAM; import static org.apache.maven.graph.DefaultGraphBuilderTest.ScenarioBuilder.scenario; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -@RunWith( Parameterized.class ) +@Parameterized public class DefaultGraphBuilderTest { /* @@ -104,13 +104,20 @@ public class DefaultGraphBuilderTest private Map artifactIdProjectMap; // Parameters for the test - private final String parameterDescription; - private final List parameterSelectedProjects; - private final List parameterExcludedProjects; - private final String parameterResumeFrom; - private final String parameterMakeBehavior; - private final List parameterExpectedResult; - private final File parameterRequestedPom; + @Parameter( 0 ) + private String parameterDescription; + @Parameter( 1 ) + private List parameterSelectedProjects; + @Parameter( 2 ) + private List parameterExcludedProjects; + @Parameter( 3 ) + private String parameterResumeFrom; + @Parameter( 4 ) + private String parameterMakeBehavior; + @Parameter( 5 ) + private List parameterExpectedResult; + @Parameter( 6 ) + private File parameterRequestedPom; @Parameters(name = "{index}. {0}") public static Collection parameters() @@ -191,17 +198,6 @@ public class DefaultGraphBuilderTest ); } - public DefaultGraphBuilderTest( String description, List selectedProjects, List excludedProjects, String resumedFrom, String makeBehavior, List expectedReactorProjects, File requestedPom ) - { - this.parameterDescription = description; - this.parameterSelectedProjects = selectedProjects; - this.parameterExcludedProjects = excludedProjects; - this.parameterResumeFrom = resumedFrom; - this.parameterMakeBehavior = makeBehavior; - this.parameterExpectedResult = expectedReactorProjects; - this.parameterRequestedPom = requestedPom; - } - @Test public void testGetReactorProjects() { @@ -226,10 +222,10 @@ public class DefaultGraphBuilderTest List expectedReactorProjects = parameterExpectedResult.stream() .map( artifactIdProjectMap::get ) .collect( Collectors.toList()); - assertEquals( parameterDescription, expectedReactorProjects, actualReactorProjects ); + assertEquals( expectedReactorProjects, actualReactorProjects, parameterDescription ); } - @Before + @BeforeEach public void before() throws Exception { graphBuilder = new DefaultGraphBuilder( diff --git a/maven-core/src/test/java/org/apache/maven/graph/DefaultProjectDependencyGraphTest.java b/maven-core/src/test/java/org/apache/maven/graph/DefaultProjectDependencyGraphTest.java index 6ce201d41d..94737fb514 100644 --- a/maven-core/src/test/java/org/apache/maven/graph/DefaultProjectDependencyGraphTest.java +++ b/maven-core/src/test/java/org/apache/maven/graph/DefaultProjectDependencyGraphTest.java @@ -14,21 +14,22 @@ */ package org.apache.maven.graph; -import junit.framework.TestCase; +import java.util.Arrays; +import java.util.List; + import org.apache.maven.execution.ProjectDependencyGraph; import org.apache.maven.model.Dependency; import org.apache.maven.project.DuplicateProjectException; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.dag.CycleDetectedException; +import org.junit.jupiter.api.Test; -import java.util.Arrays; -import java.util.List; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Kristian Rosenvold */ public class DefaultProjectDependencyGraphTest - extends TestCase { private final MavenProject aProject = createA(); @@ -45,6 +46,7 @@ public class DefaultProjectDependencyGraphTest private final MavenProject transitiveOnly = createProject( Arrays.asList( toDependency( depender3 ) ), "depender5" ); + @Test public void testGetSortedProjects() throws DuplicateProjectException, CycleDetectedException { @@ -54,6 +56,7 @@ public class DefaultProjectDependencyGraphTest assertEquals( depender1, sortedProjects.get( 1 ) ); } + @Test public void testVerifyExpectedParentStructure() throws CycleDetectedException, DuplicateProjectException { @@ -66,6 +69,7 @@ public class DefaultProjectDependencyGraphTest assertEquals( depender3, sortedProjects.get( 3 ) ); } + @Test public void testVerifyThatDownstreamProjectsComeInSortedOrder() throws CycleDetectedException, DuplicateProjectException { @@ -76,6 +80,7 @@ public class DefaultProjectDependencyGraphTest assertEquals( depender3, downstreamProjects.get( 2 ) ); } + @Test public void testTransitivesInOrder() throws CycleDetectedException, DuplicateProjectException { @@ -89,6 +94,7 @@ public class DefaultProjectDependencyGraphTest assertEquals( depender2, downstreamProjects.get( 3 ) ); } + @Test public void testNonTransitivesInOrder() throws CycleDetectedException, DuplicateProjectException { @@ -102,6 +108,7 @@ public class DefaultProjectDependencyGraphTest assertEquals( depender2, downstreamProjects.get( 3 ) ); } + @Test public void testWithTransitiveOnly() throws CycleDetectedException, DuplicateProjectException { @@ -115,6 +122,7 @@ public class DefaultProjectDependencyGraphTest assertEquals( depender2, downstreamProjects.get( 3 ) ); } + @Test public void testWithMissingTransitiveOnly() throws CycleDetectedException, DuplicateProjectException { @@ -127,6 +135,7 @@ public class DefaultProjectDependencyGraphTest assertEquals( depender2, downstreamProjects.get( 2 ) ); } + @Test public void testGetUpstreamProjects() throws CycleDetectedException, DuplicateProjectException { diff --git a/maven-core/src/test/java/org/apache/maven/internal/aether/ConsumerModelSourceTransformerTest.java b/maven-core/src/test/java/org/apache/maven/internal/aether/ConsumerModelSourceTransformerTest.java index 0f1f634f4e..50506239fb 100644 --- a/maven-core/src/test/java/org/apache/maven/internal/aether/ConsumerModelSourceTransformerTest.java +++ b/maven-core/src/test/java/org/apache/maven/internal/aether/ConsumerModelSourceTransformerTest.java @@ -26,7 +26,7 @@ import java.nio.file.Paths; import org.apache.maven.model.Model; import org.apache.maven.model.building.TransformerContext; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xmlunit.assertj.XmlAssert; public class ConsumerModelSourceTransformerTest diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/DefaultLifecyclesTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/DefaultLifecyclesTest.java index 28ffeda669..2378ddd2af 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/DefaultLifecyclesTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/DefaultLifecyclesTest.java @@ -15,25 +15,22 @@ package org.apache.maven.lifecycle; * the License. */ -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.arrayWithSize; -import static org.hamcrest.Matchers.hasSize; - import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; -import org.codehaus.plexus.ContainerConfiguration; -import org.codehaus.plexus.DefaultPlexusContainer; -import org.codehaus.plexus.PlexusConstants; -import org.codehaus.plexus.PlexusTestCase; - import javax.inject.Inject; -import java.util.Collections; -import java.util.List; + +import org.apache.maven.test.PlexusTestCase; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.arrayWithSize; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.is; /** * @author Kristian Rosenvold @@ -45,30 +42,7 @@ public class DefaultLifecyclesTest @Inject private DefaultLifecycles defaultLifeCycles; - @Override - protected void customizeContainerConfiguration( ContainerConfiguration configuration ) - { - super.customizeContainerConfiguration( configuration ); - configuration.setAutoWiring( true ); - configuration.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); - } - - @Override - protected void setUp() throws Exception - { - super.setUp(); - getContainer(); - } - - @Override - protected synchronized void setupContainer() - { - super.setupContainer(); - - ( (DefaultPlexusContainer) getContainer() ).addPlexusInjector( Collections.emptyList(), - binder -> binder.requestInjection( this ) ); - } - + @Test public void testDefaultLifecycles() { final List lifecycles = defaultLifeCycles.getLifeCycles(); @@ -76,6 +50,7 @@ public class DefaultLifecyclesTest assertThat( DefaultLifecycles.STANDARD_LIFECYCLES, arrayWithSize( 4 ) ); } + @Test public void testDefaultLifecycle() { final Lifecycle lifecycle = getLifeCycleById( "default" ); @@ -83,6 +58,7 @@ public class DefaultLifecyclesTest assertThat( lifecycle.getPhases(), hasSize( 23 ) ); } + @Test public void testCleanLifecycle() { final Lifecycle lifecycle = getLifeCycleById( "clean" ); @@ -90,6 +66,7 @@ public class DefaultLifecyclesTest assertThat( lifecycle.getPhases(), hasSize( 3 ) ); } + @Test public void testSiteLifecycle() { final Lifecycle lifecycle = getLifeCycleById( "site" ); @@ -97,6 +74,7 @@ public class DefaultLifecyclesTest assertThat( lifecycle.getPhases(), hasSize( 4 ) ); } + @Test public void testWrapperLifecycle() { final Lifecycle lifecycle = getLifeCycleById( "wrapper" ); @@ -104,6 +82,7 @@ public class DefaultLifecyclesTest assertThat( lifecycle.getPhases(), hasSize( 1 ) ); } + @Test public void testCustomLifecycle() { List myLifecycles = new ArrayList<>(); diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorSubModulesTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorSubModulesTest.java index dbf242e5e1..84c16ff80e 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorSubModulesTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorSubModulesTest.java @@ -25,6 +25,11 @@ import org.apache.maven.lifecycle.internal.LifecycleTaskSegmentCalculator; import org.apache.maven.lifecycle.internal.MojoExecutor; import javax.inject.Inject; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * Just asserts that it's able to create those components. Handy when CDI container gets a nervous breakdown. @@ -64,6 +69,7 @@ public class LifecycleExecutorSubModulesTest return "src/test/projects/lifecycle-executor"; } + @Test public void testCreation() throws Exception { diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java index d4a7e9b5b0..448ffda3ca 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java @@ -15,9 +15,6 @@ package org.apache.maven.lifecycle; * the License. */ -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.hasSize; - import java.io.File; import java.util.ArrayList; import java.util.Arrays; @@ -45,6 +42,16 @@ import org.apache.maven.plugin.MojoNotFoundException; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasSize; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import javax.inject.Inject; @@ -72,6 +79,7 @@ public class LifecycleExecutorTest // Tests which exercise the lifecycle executor when it is dealing with default lifecycle phases. // ----------------------------------------------------------------------------------------------- + @Test public void testCalculationOfBuildPlanWithIndividualTaskWherePluginIsSpecifiedInThePom() throws Exception { @@ -92,6 +100,7 @@ public class LifecycleExecutorTest assertEquals( "0.1", mojoExecution.getMojoDescriptor().getPluginDescriptor().getVersion() ); } + @Test public void testCalculationOfBuildPlanWithIndividualTaskOfTheCleanLifecycle() throws Exception { @@ -111,6 +120,7 @@ public class LifecycleExecutorTest assertEquals( "0.1", mojoExecution.getMojoDescriptor().getPluginDescriptor().getVersion() ); } + @Test public void testCalculationOfBuildPlanWithIndividualTaskOfTheCleanCleanGoal() throws Exception { @@ -233,6 +243,7 @@ public class LifecycleExecutorTest "configuration/models[1]/model" ) ); } + @Test public void testLifecycleQueryingUsingADefaultLifecyclePhase() throws Exception { @@ -263,6 +274,7 @@ public class LifecycleExecutorTest assertEquals( "jar:jar", executionPlan.get( 7 ).getMojoDescriptor().getFullGoalName() ); } + @Test public void testLifecyclePluginsRetrievalForDefaultLifecycle() throws Exception { @@ -272,6 +284,7 @@ public class LifecycleExecutorTest assertThat( plugins.toString(), plugins, hasSize( 9 ) ); } + @Test public void testPluginConfigurationCreation() throws Exception { @@ -301,33 +314,27 @@ public class LifecycleExecutorTest mergedSegment.getTasks() ); } + @Test public void testInvalidGoalName() throws Exception { File pom = getProject( "project-basic" ); MavenSession session = createMavenSession( pom ); - try - { - getExecutions( calculateExecutionPlan( session, "resources:" ) ); - fail( "expected a MojoNotFoundException" ); - } - catch ( MojoNotFoundException e ) - { - assertEquals( "", e.getGoal() ); - } + MojoNotFoundException e = assertThrows( + MojoNotFoundException.class, + () -> getExecutions( calculateExecutionPlan( session, "resources:" ) ), + "expected a MojoNotFoundException" ); + assertEquals( "", e.getGoal() ); - try - { - getExecutions( calculateExecutionPlan( session, "org.apache.maven.plugins:maven-resources-plugin:0.1:resources:toomany" ) ); - fail( "expected a MojoNotFoundException" ); - } - catch ( MojoNotFoundException e ) - { - assertEquals( "resources:toomany", e.getGoal() ); - } + e = assertThrows( + MojoNotFoundException.class, + () -> getExecutions( calculateExecutionPlan( session, "org.apache.maven.plugins:maven-resources-plugin:0.1:resources:toomany" ) ), + "expected a MojoNotFoundException" ); + assertEquals( "resources:toomany", e.getGoal() ); } + @Test public void testPluginPrefixRetrieval() throws Exception { @@ -340,6 +347,7 @@ public class LifecycleExecutorTest // Prefixes + @Test public void testFindingPluginPrefixforCleanClean() throws Exception { @@ -349,6 +357,7 @@ public class LifecycleExecutorTest assertNotNull( plugin ); } + @Test public void testSetupMojoExecution() throws Exception { @@ -362,7 +371,7 @@ public class LifecycleExecutorTest Arrays.asList( (Object) task ), false ); MojoExecution execution = executionPlan.getMojoExecutions().get(0); - assertEquals(execution.toString(), "maven-it-plugin", execution.getArtifactId()); + assertEquals( "maven-it-plugin", execution.getArtifactId(), execution.toString() ); assertNull(execution.getConfiguration()); lifeCycleExecutionPlanCalculator.setupMojoExecution( session, session.getCurrentProject(), execution, @@ -371,6 +380,7 @@ public class LifecycleExecutorTest assertEquals("1.0", execution.getConfiguration().getChild( "version" ).getAttribute( "default-value" )); } + @Test public void testExecutionListeners() throws Exception { diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/MavenExecutionPlanTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/MavenExecutionPlanTest.java index ffd9f0dae9..e077dc9986 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/MavenExecutionPlanTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/MavenExecutionPlanTest.java @@ -15,21 +15,24 @@ package org.apache.maven.lifecycle; -import junit.framework.TestCase; +import java.util.Set; import org.apache.maven.lifecycle.internal.ExecutionPlanItem; import org.apache.maven.lifecycle.internal.stub.LifecycleExecutionPlanCalculatorStub; import org.apache.maven.model.Plugin; +import org.junit.jupiter.api.Test; -import java.util.Set; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; /** * @author Kristian Rosenvold */ public class MavenExecutionPlanTest - extends TestCase { + @Test public void testFindLastInPhase() throws Exception { @@ -41,6 +44,7 @@ public class MavenExecutionPlanTest assertNotNull( expected ); } + @Test public void testThreadSafeMojos() throws Exception { @@ -52,6 +56,7 @@ public class MavenExecutionPlanTest } + @Test public void testFindLastWhenFirst() throws Exception { @@ -62,6 +67,7 @@ public class MavenExecutionPlanTest assertNull( beerPhase ); } + @Test public void testFindLastInPhaseMisc() throws Exception { diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/BuildListCalculatorTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/BuildListCalculatorTest.java index a0039832af..6a73160c16 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/BuildListCalculatorTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/BuildListCalculatorTest.java @@ -15,17 +15,20 @@ package org.apache.maven.lifecycle.internal; * the License. */ -import junit.framework.TestCase; +import java.util.List; + import org.apache.maven.execution.MavenSession; import org.apache.maven.lifecycle.internal.stub.LifecycleTaskSegmentCalculatorStub; import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub; +import org.junit.jupiter.api.Test; -import java.util.List; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class BuildListCalculatorTest - extends TestCase { + @Test public void testCalculateProjectBuilds() throws Exception { @@ -35,8 +38,8 @@ public class BuildListCalculatorTest List taskSegments = lifecycleTaskSegmentCalculator.calculateTaskSegments( session ); final ProjectBuildList buildList = buildListCalculator.calculateProjectBuilds( session, taskSegments ); final ProjectBuildList segments = buildList.getByTaskSegment( taskSegments.get( 0 ) ); - assertEquals( "Stub data contains 3 segments", 3, taskSegments.size() ); - assertEquals( "Stub data contains 6 items", 6, segments.size() ); + assertEquals( 3, taskSegments.size(), "Stub data contains 3 segments" ); + assertEquals( 6, segments.size(), "Stub data contains 6 items" ); final ProjectSegment build = segments.get( 0 ); assertNotNull( build ); } diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/BuilderCommonTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/BuilderCommonTest.java index b1af3aa520..fe0776e90a 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/BuilderCommonTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/BuilderCommonTest.java @@ -15,9 +15,7 @@ package org.apache.maven.lifecycle.internal; * the License. */ -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; +import java.util.HashSet; import org.apache.maven.execution.MavenSession; import org.apache.maven.lifecycle.MavenExecutionPlan; @@ -25,10 +23,11 @@ import org.apache.maven.lifecycle.internal.builder.BuilderCommon; import org.apache.maven.lifecycle.internal.stub.LifecycleExecutionPlanCalculatorStub; import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub; import org.codehaus.plexus.logging.Logger; -import org.junit.Test; +import org.junit.jupiter.api.Test; - -import java.util.HashSet; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; /** * @author Kristian Rosenvold @@ -78,16 +77,19 @@ public class BuilderCommonTest + "you should define versions in pluginManagement section of your pom.xml or parent"); } + @Test public void testHandleBuildError() throws Exception { } + @Test public void testAttachToThread() throws Exception { } + @Test public void testGetKey() throws Exception { diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ConcurrencyDependencyGraphTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ConcurrencyDependencyGraphTest.java index 6118bbe638..c2971f1c50 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ConcurrencyDependencyGraphTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ConcurrencyDependencyGraphTest.java @@ -15,6 +15,8 @@ package org.apache.maven.lifecycle.internal; * the License. */ +import java.util.List; + import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.ProjectDependencyGraph; import org.apache.maven.lifecycle.LifecycleNotFoundException; @@ -29,17 +31,23 @@ import org.apache.maven.plugin.PluginResolutionException; import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException; import org.apache.maven.plugin.version.PluginVersionResolutionException; import org.apache.maven.project.MavenProject; +import org.junit.jupiter.api.Test; -import java.util.List; - -import static org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub.*; +import static org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub.A; +import static org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub.B; +import static org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub.C; +import static org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub.X; +import static org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub.Y; +import static org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub.Z; +import static org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub.getProjectBuildList; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Kristian Rosenvold */ public class ConcurrencyDependencyGraphTest - extends junit.framework.TestCase { + @Test public void testConcurrencyGraphPrimaryVersion() throws InvalidPluginDescriptorException, PluginVersionResolutionException, PluginDescriptorParsingException, NoPluginFoundForPrefixException, MojoNotFoundException, PluginNotFoundException, PluginResolutionException, @@ -70,6 +78,7 @@ public class ConcurrencyDependencyGraphTest assertEquals( Z, cDescendants.get( 1 ) ); } + @Test public void testConcurrencyGraphDifferentCompletionOrder() throws InvalidPluginDescriptorException, PluginVersionResolutionException, PluginDescriptorParsingException, NoPluginFoundForPrefixException, MojoNotFoundException, PluginNotFoundException, PluginResolutionException, diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleDependencyResolverTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleDependencyResolverTest.java index de02428675..000dd883ff 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleDependencyResolverTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleDependencyResolverTest.java @@ -32,6 +32,10 @@ import org.apache.maven.execution.MavenSession; import org.apache.maven.project.MavenProject; import javax.inject.Inject; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class LifecycleDependencyResolverTest extends AbstractCoreMavenComponentTestCase { @@ -44,6 +48,7 @@ public class LifecycleDependencyResolverTest extends AbstractCoreMavenComponentT return null; } + @Test public void testCachedReactorProjectDependencies() throws Exception { MavenSession session = createMavenSession( new File( "src/test/projects/lifecycle-dependency-resolver/pom.xml" ), new Properties(), true ); diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleExecutionPlanCalculatorTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleExecutionPlanCalculatorTest.java index 0e1c3c7304..28d552afec 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleExecutionPlanCalculatorTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleExecutionPlanCalculatorTest.java @@ -23,6 +23,9 @@ import org.apache.maven.lifecycle.internal.stub.DefaultLifecyclesStub; import org.apache.maven.lifecycle.internal.stub.PluginPrefixResolverStub; import org.apache.maven.lifecycle.internal.stub.PluginVersionResolverStub; import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Kristian Rosenvold @@ -31,6 +34,7 @@ public class LifecycleExecutionPlanCalculatorTest extends AbstractCoreMavenComponentTestCase { + @Test public void testCalculateExecutionPlanWithGoalTasks() throws Exception { diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleTaskSegmentCalculatorImplTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleTaskSegmentCalculatorImplTest.java index 5db316f875..e5a44d645e 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleTaskSegmentCalculatorImplTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleTaskSegmentCalculatorImplTest.java @@ -19,19 +19,22 @@ package org.apache.maven.lifecycle.internal; * under the License. */ -import junit.framework.TestCase; +import java.util.List; + import org.apache.maven.execution.MavenSession; import org.apache.maven.lifecycle.internal.stub.LifecycleTaskSegmentCalculatorStub; import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub; +import org.junit.jupiter.api.Test; -import java.util.List; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * @author Kristian Rosenvold */ public class LifecycleTaskSegmentCalculatorImplTest - extends TestCase { + @Test public void testCalculateProjectBuilds() throws Exception { @@ -42,8 +45,8 @@ public class LifecycleTaskSegmentCalculatorImplTest final ProjectBuildList buildList = buildListCalculator.calculateProjectBuilds( session, taskSegments ); final ProjectBuildList segments = buildList.getByTaskSegment( taskSegments.get( 0 ) ); - assertEquals( "Stub data contains 3 segments", 3, taskSegments.size() ); - assertEquals( "Stub data contains 6 items", 6, segments.size() ); + assertEquals( 3, taskSegments.size(), "Stub data contains 3 segments" ); + assertEquals( 6, segments.size(), "Stub data contains 6 items" ); final ProjectSegment build = segments.get( 0 ); assertNotNull( build ); } diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/PhaseRecorderTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/PhaseRecorderTest.java index f3d6422c66..1d0211f225 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/PhaseRecorderTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/PhaseRecorderTest.java @@ -15,20 +15,23 @@ package org.apache.maven.lifecycle.internal; * the License. */ -import junit.framework.TestCase; +import java.util.List; import org.apache.maven.lifecycle.MavenExecutionPlan; import org.apache.maven.lifecycle.internal.stub.LifecycleExecutionPlanCalculatorStub; import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub; import org.apache.maven.plugin.MojoExecution; +import org.junit.jupiter.api.Test; -import java.util.List; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Kristian Rosenvold */ -public class PhaseRecorderTest extends TestCase +public class PhaseRecorderTest { + @Test public void testObserveExecution() throws Exception { PhaseRecorder phaseRecorder = new PhaseRecorder( ProjectDependencyGraphStub.A); MavenExecutionPlan plan = LifecycleExecutionPlanCalculatorStub.getProjectAExceutionPlan(); diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ProjectBuildListTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ProjectBuildListTest.java index 3e3f8922f9..106c311987 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ProjectBuildListTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ProjectBuildListTest.java @@ -17,12 +17,12 @@ package org.apache.maven.lifecycle.internal; import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.hamcrest.MatcherAssert.assertThat; import org.apache.maven.execution.MavenSession; import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Kristian Rosenvold diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/builder/multithreaded/ConcurrencyDependencyGraphTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/builder/multithreaded/ConcurrencyDependencyGraphTest.java index b909fb066b..acad888941 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/builder/multithreaded/ConcurrencyDependencyGraphTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/builder/multithreaded/ConcurrencyDependencyGraphTest.java @@ -14,17 +14,20 @@ package org.apache.maven.lifecycle.internal.builder.multithreaded; * the License. */ -import junit.framework.TestCase; +import java.util.List; +import java.util.Set; + import org.apache.maven.execution.ProjectDependencyGraph; import org.apache.maven.lifecycle.internal.ProjectBuildList; import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub; import org.apache.maven.project.MavenProject; +import org.junit.jupiter.api.Test; -import java.util.List; -import java.util.Set; +import static org.junit.jupiter.api.Assertions.assertEquals; -public class ConcurrencyDependencyGraphTest extends TestCase { +public class ConcurrencyDependencyGraphTest { + @Test public void testGraph() throws Exception { ProjectBuildList projectBuildList = ProjectDependencyGraphStub.getProjectBuildList( diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/builder/multithreaded/ThreadOutputMuxerTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/builder/multithreaded/ThreadOutputMuxerTest.java index 32ce9badfa..549e90b8b8 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/builder/multithreaded/ThreadOutputMuxerTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/builder/multithreaded/ThreadOutputMuxerTest.java @@ -15,23 +15,6 @@ package org.apache.maven.lifecycle.internal.builder.multithreaded; * the License. */ -import junit.framework.TestCase; - -import org.apache.maven.execution.MavenSession; -import org.apache.maven.lifecycle.LifecycleNotFoundException; -import org.apache.maven.lifecycle.LifecyclePhaseNotFoundException; -import org.apache.maven.lifecycle.internal.ProjectBuildList; -import org.apache.maven.lifecycle.internal.ProjectSegment; -import org.apache.maven.lifecycle.internal.builder.multithreaded.ThreadOutputMuxer; -import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub; -import org.apache.maven.plugin.InvalidPluginDescriptorException; -import org.apache.maven.plugin.MojoNotFoundException; -import org.apache.maven.plugin.PluginDescriptorParsingException; -import org.apache.maven.plugin.PluginNotFoundException; -import org.apache.maven.plugin.PluginResolutionException; -import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException; -import org.apache.maven.plugin.version.PluginVersionResolutionException; - import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.util.ArrayList; @@ -45,11 +28,27 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.lifecycle.LifecycleNotFoundException; +import org.apache.maven.lifecycle.LifecyclePhaseNotFoundException; +import org.apache.maven.lifecycle.internal.ProjectBuildList; +import org.apache.maven.lifecycle.internal.ProjectSegment; +import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub; +import org.apache.maven.plugin.InvalidPluginDescriptorException; +import org.apache.maven.plugin.MojoNotFoundException; +import org.apache.maven.plugin.PluginDescriptorParsingException; +import org.apache.maven.plugin.PluginNotFoundException; +import org.apache.maven.plugin.PluginResolutionException; +import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException; +import org.apache.maven.plugin.version.PluginVersionResolutionException; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + /** * @author Kristian Rosenvold */ public class ThreadOutputMuxerTest - extends TestCase { final String paid = "Paid"; @@ -58,6 +57,7 @@ public class ThreadOutputMuxerTest final String full = "Full"; + @Test public void testSingleThreaded() throws Exception { @@ -86,6 +86,7 @@ public class ThreadOutputMuxerTest assertEquals( ( paid + in + full ).length(), byteArrayOutputStream.size() ); } + @Test public void testMultiThreaded() throws Exception { @@ -124,7 +125,7 @@ public class ThreadOutputMuxerTest threadOutputMuxer.close(); final byte[] bytes = byteArrayOutputStream.toByteArray(); String result = new String( bytes ); - assertEquals( result, expectedLength, bytes.length ); + assertEquals( expectedLength, bytes.length, result ); } diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/ProjectDependencyGraphStubTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/ProjectDependencyGraphStubTest.java index 8c60572343..cd2d327a13 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/ProjectDependencyGraphStubTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/ProjectDependencyGraphStubTest.java @@ -15,11 +15,13 @@ package org.apache.maven.lifecycle.internal.stub; -import junit.framework.TestCase; -import org.apache.maven.project.MavenProject; - import java.util.List; +import org.apache.maven.project.MavenProject; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests the stub. Yeah, I know. @@ -28,30 +30,34 @@ import java.util.List; */ public class ProjectDependencyGraphStubTest - extends TestCase { + ProjectDependencyGraphStub stub = new ProjectDependencyGraphStub(); + + @Test public void testADependencies() { - ProjectDependencyGraphStub stub = new ProjectDependencyGraphStub(); final List mavenProjects = stub.getUpstreamProjects( ProjectDependencyGraphStub.A, false ); assertEquals( 0, mavenProjects.size() ); } - public void testBDepenencies( ProjectDependencyGraphStub stub ) + @Test + public void testBDepenencies() { final List bProjects = stub.getUpstreamProjects( ProjectDependencyGraphStub.B, false ); assertEquals( 1, bProjects.size() ); assertTrue( bProjects.contains( ProjectDependencyGraphStub.A ) ); } - public void testCDepenencies( ProjectDependencyGraphStub stub ) + @Test + public void testCDepenencies() { final List cProjects = stub.getUpstreamProjects( ProjectDependencyGraphStub.C, false ); assertEquals( 1, cProjects.size() ); - assertTrue( cProjects.contains( ProjectDependencyGraphStub.C ) ); + assertTrue( cProjects.contains( ProjectDependencyGraphStub.A ) ); } - public void testXDepenencies( ProjectDependencyGraphStub stub ) + @Test + public void testXDepenencies() { final List cProjects = stub.getUpstreamProjects( ProjectDependencyGraphStub.X, false ); assertEquals( 2, cProjects.size() ); diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/mapping/LifecyclePhaseTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/mapping/LifecyclePhaseTest.java index f60eace0a8..677915f92d 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/mapping/LifecyclePhaseTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/mapping/LifecyclePhaseTest.java @@ -15,13 +15,13 @@ package org.apache.maven.lifecycle.mapping; * the License. */ -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import java.util.Arrays; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author atanasenko diff --git a/maven-core/src/test/java/org/apache/maven/plugin/PluginManagerTest.java b/maven-core/src/test/java/org/apache/maven/plugin/PluginManagerTest.java index b4b3b3ab04..954e221473 100644 --- a/maven-core/src/test/java/org/apache/maven/plugin/PluginManagerTest.java +++ b/maven-core/src/test/java/org/apache/maven/plugin/PluginManagerTest.java @@ -32,6 +32,13 @@ import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.repository.ComponentDescriptor; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; import javax.inject.Inject; @@ -41,12 +48,12 @@ public class PluginManagerTest @Inject private DefaultBuildPluginManager pluginManager; - protected String getProjectsDirectory() { return "src/test/projects/plugin-manager"; } + @Test public void testPluginLoading() throws Exception { @@ -61,6 +68,7 @@ public class PluginManagerTest assertNotNull( pluginDescriptor ); } + @Test public void testMojoDescriptorRetrieval() throws Exception { @@ -97,6 +105,7 @@ public class PluginManagerTest // only deal in concrete terms -- all version finding mumbo jumbo is a customization to base functionality // the plugin manager provides. + @Test public void testRemoteResourcesPlugin() throws Exception { @@ -150,6 +159,7 @@ public class PluginManagerTest */ } + @Test public void testMojoConfigurationIsMergedCorrectly() throws Exception { @@ -160,6 +170,7 @@ public class PluginManagerTest * is in the Antlr plugin which comes bundled with a version of Antlr but the user often times needs * to use a specific version. We need to make sure the version that they specify takes precedence. */ + @Test public void testMojoWhereInternallyStatedDependencyIsOverriddenByProject() throws Exception { @@ -169,6 +180,7 @@ public class PluginManagerTest * The case where you have a plugin in the current build that you want to be used on projects in * the current build. */ + @Test public void testMojoThatIsPresentInTheCurrentBuild() throws Exception { @@ -178,6 +190,7 @@ public class PluginManagerTest * This is the case where the Mojo wants to execute on every project and then do something at the end * with the results of each project. */ + @Test public void testAggregatorMojo() throws Exception { @@ -187,6 +200,7 @@ public class PluginManagerTest * This is the case where a Mojo needs the lifecycle run to a certain phase before it can do * anything useful. */ + @Test public void testMojoThatRequiresExecutionToAGivenPhaseBeforeExecutingItself() throws Exception { @@ -198,6 +212,7 @@ public class PluginManagerTest // test a build where projects use different versions of the same plugin + @Test public void testThatPluginDependencyThatHasSystemScopeIsResolved() throws Exception { @@ -241,6 +256,7 @@ public class PluginManagerTest assertEquals( version, pd.getVersion() ); } + @Test public void testPluginRealmCache() throws Exception { @@ -285,6 +301,7 @@ public class PluginManagerTest } } + @Test public void testBuildExtensionsPluginLoading() throws Exception { diff --git a/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExceptionTest.java b/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExceptionTest.java index c13d1930a1..d2702938ee 100644 --- a/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExceptionTest.java +++ b/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExceptionTest.java @@ -24,8 +24,9 @@ import java.util.Collections; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.Parameter; import org.apache.maven.plugin.descriptor.PluginDescriptor; +import org.junit.jupiter.api.Test; -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * MNG-3131 @@ -34,11 +35,11 @@ import junit.framework.TestCase; * */ public class PluginParameterExceptionTest - extends TestCase { private final String LS = System.lineSeparator(); + @Test public void testMissingRequiredStringArrayTypeParameter() { MojoDescriptor mojoDescriptor = new MojoDescriptor(); @@ -69,6 +70,7 @@ public class PluginParameterExceptionTest "." + LS, exception.buildDiagnosticMessage() ); } + @Test public void testMissingRequiredCollectionTypeParameter() { MojoDescriptor mojoDescriptor = new MojoDescriptor(); @@ -99,6 +101,7 @@ public class PluginParameterExceptionTest "." + LS, exception.buildDiagnosticMessage() ); } + @Test public void testMissingRequiredMapTypeParameter() { MojoDescriptor mojoDescriptor = new MojoDescriptor(); @@ -129,6 +132,7 @@ public class PluginParameterExceptionTest "." + LS, exception.buildDiagnosticMessage() ); } + @Test public void testMissingRequiredPropertiesTypeParameter() { MojoDescriptor mojoDescriptor = new MojoDescriptor(); diff --git a/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java b/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java index e579d691e2..9c0da4fa4f 100644 --- a/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java +++ b/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java @@ -46,6 +46,14 @@ import org.codehaus.plexus.MutablePlexusContainer; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; import org.codehaus.plexus.util.dag.CycleDetectedException; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; import javax.inject.Inject; @@ -60,14 +68,7 @@ public class PluginParameterExpressionEvaluatorTest @Inject private RepositorySystem factory; - @Override - protected void tearDown() - throws Exception - { - factory = null; - super.tearDown(); - } - + @Test public void testPluginDescriptorExpressionReference() throws Exception { @@ -79,11 +80,12 @@ public class PluginParameterExpressionEvaluatorTest System.out.println( "Result: " + result ); - assertSame( "${plugin} expression does not return plugin descriptor.", - exec.getMojoDescriptor().getPluginDescriptor(), - result ); + assertSame( exec.getMojoDescriptor().getPluginDescriptor(), + result, + "${plugin} expression does not return plugin descriptor." ); } + @Test public void testPluginArtifactsExpressionReference() throws Exception { @@ -106,9 +108,10 @@ public class PluginParameterExpressionEvaluatorTest assertNotNull( depResults ); assertEquals( 1, depResults.size() ); - assertSame( "dependency artifact is wrong.", depArtifact, depResults.get( 0 ) ); + assertSame( depArtifact, depResults.get( 0 ), "dependency artifact is wrong." ); } + @Test public void testPluginArtifactMapExpressionReference() throws Exception { @@ -131,11 +134,12 @@ public class PluginParameterExpressionEvaluatorTest assertNotNull( depResults ); assertEquals( 1, depResults.size() ); - assertSame( "dependency artifact is wrong.", - depArtifact, - depResults.get( ArtifactUtils.versionlessKey( depArtifact ) ) ); + assertSame( depArtifact, + depResults.get( ArtifactUtils.versionlessKey( depArtifact ) ), + "dependency artifact is wrong." ); } + @Test public void testPluginArtifactIdExpressionReference() throws Exception { @@ -147,11 +151,12 @@ public class PluginParameterExpressionEvaluatorTest System.out.println( "Result: " + result ); - assertSame( "${plugin.artifactId} expression does not return plugin descriptor's artifactId.", - exec.getMojoDescriptor().getPluginDescriptor().getArtifactId(), - result ); + assertSame( exec.getMojoDescriptor().getPluginDescriptor().getArtifactId(), + result, + "${plugin.artifactId} expression does not return plugin descriptor's artifactId." ); } + @Test public void testValueExtractionWithAPomValueContainingAPath() throws Exception { @@ -174,6 +179,7 @@ public class PluginParameterExpressionEvaluatorTest assertEquals( expected, actual ); } + @Test public void testEscapedVariablePassthrough() throws Exception { @@ -191,6 +197,7 @@ public class PluginParameterExpressionEvaluatorTest assertEquals( var, value ); } + @Test public void testEscapedVariablePassthroughInLargerExpression() throws Exception { @@ -209,6 +216,7 @@ public class PluginParameterExpressionEvaluatorTest assertEquals( "${var} with version: 1", value ); } + @Test public void testMultipleSubExpressionsInLargerExpression() throws Exception { @@ -227,6 +235,7 @@ public class PluginParameterExpressionEvaluatorTest assertEquals( "test with version: 1", value ); } + @Test public void testMissingPOMPropertyRefInLargerExpression() throws Exception { @@ -241,6 +250,7 @@ public class PluginParameterExpressionEvaluatorTest assertEquals( expr, value ); } + @Test public void testPOMPropertyExtractionWithMissingProject_WithDotNotation() throws Exception { @@ -262,6 +272,7 @@ public class PluginParameterExpressionEvaluatorTest assertEquals( checkValue, value ); } + @Test public void testBasedirExtractionWithMissingProject() throws Exception { @@ -272,6 +283,7 @@ public class PluginParameterExpressionEvaluatorTest assertEquals( System.getProperty( "user.dir" ), value ); } + @Test public void testValueExtractionFromSystemPropertiesWithMissingProject() throws Exception { @@ -291,6 +303,7 @@ public class PluginParameterExpressionEvaluatorTest assertEquals( "value", value ); } + @Test public void testValueExtractionFromSystemPropertiesWithMissingProject_WithDotNotation() throws Exception { @@ -323,6 +336,7 @@ public class PluginParameterExpressionEvaluatorTest return new MavenSession( container, request, new DefaultMavenExecutionResult(), Collections.emptyList() ); } + @Test public void testLocalRepositoryExtraction() throws Exception { @@ -333,6 +347,7 @@ public class PluginParameterExpressionEvaluatorTest assertEquals( "local", ( (ArtifactRepository) value ).getId() ); } + @Test public void testTwoExpressions() throws Exception { @@ -351,6 +366,7 @@ public class PluginParameterExpressionEvaluatorTest assertEquals( "expected-directory" + File.separatorChar + "expected-finalName", value ); } + @Test public void testShouldExtractPluginArtifacts() throws Exception { diff --git a/maven-core/src/test/java/org/apache/maven/plugin/internal/DefaultLegacySupportTest.java b/maven-core/src/test/java/org/apache/maven/plugin/internal/DefaultLegacySupportTest.java index 25aa176cc6..4cf01cf87d 100644 --- a/maven-core/src/test/java/org/apache/maven/plugin/internal/DefaultLegacySupportTest.java +++ b/maven-core/src/test/java/org/apache/maven/plugin/internal/DefaultLegacySupportTest.java @@ -18,20 +18,23 @@ package org.apache.maven.plugin.internal; * under the License. */ -import junit.framework.TestCase; +import java.util.concurrent.CountDownLatch; + import org.apache.maven.execution.DefaultMavenExecutionRequest; import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenSession; +import org.junit.jupiter.api.Test; -import java.util.concurrent.CountDownLatch; +import static org.junit.jupiter.api.Assertions.assertNull; /** * @author Kristian Rosenvold */ -public class DefaultLegacySupportTest extends TestCase { +public class DefaultLegacySupportTest { final CountDownLatch latch = new CountDownLatch(1); final DefaultLegacySupport defaultLegacySupport = new DefaultLegacySupport(); + @Test public void testSetSession() throws Exception { MavenExecutionRequest mavenExecutionRequest = new DefaultMavenExecutionRequest(); diff --git a/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java b/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java index 1456ead89f..8b0cec08fa 100644 --- a/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java +++ b/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java @@ -21,18 +21,16 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.util.Arrays; -import java.util.Collections; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.model.building.ModelBuildingException; import org.apache.maven.model.building.ModelProblem; import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.internal.MavenRepositorySystemUtils; -import org.codehaus.plexus.ContainerConfiguration; -import org.codehaus.plexus.DefaultPlexusContainer; -import org.codehaus.plexus.PlexusConstants; -import org.codehaus.plexus.PlexusTestCase; +import org.apache.maven.test.PlexusTestCase; import org.eclipse.aether.DefaultRepositorySystemSession; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import javax.inject.Inject; @@ -47,24 +45,8 @@ public abstract class AbstractMavenProjectTestCase @Inject protected RepositorySystem repositorySystem; - @Override - protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration ) - { - super.customizeContainerConfiguration( containerConfiguration ); - containerConfiguration.setAutoWiring( true ); - containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); - } - - @Override - protected synchronized void setupContainer() - { - super.setupContainer(); - - ( (DefaultPlexusContainer) getContainer() ).addPlexusInjector( Collections.emptyList(), - binder -> binder.requestInjection( this ) ); - } - - protected void setUp() + @BeforeEach + public void setUp() throws Exception { super.setUp(); @@ -80,15 +62,6 @@ public abstract class AbstractMavenProjectTestCase } } - @Override - protected void tearDown() - throws Exception - { - projectBuilder = null; - - super.tearDown(); - } - protected ProjectBuilder getProjectBuilder() { return projectBuilder; diff --git a/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java b/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java index 1bb66ab1c9..d73b4887db 100644 --- a/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java @@ -18,8 +18,6 @@ package org.apache.maven.project; * specific language governing permissions and limitations * under the License. */ -import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertThat; import java.io.File; import java.util.ArrayList; @@ -27,8 +25,19 @@ import java.util.List; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.codehaus.plexus.util.FileUtils; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; public class DefaultMavenProjectBuilderTest extends AbstractMavenProjectTestCase @@ -39,6 +48,7 @@ public class DefaultMavenProjectBuilderTest private File localRepoDir; @Override + @BeforeEach public void setUp() throws Exception { @@ -53,6 +63,7 @@ public class DefaultMavenProjectBuilderTest } @Override + @AfterEach public void tearDown() throws Exception { @@ -91,6 +102,7 @@ public class DefaultMavenProjectBuilderTest * Check that we can build ok from the middle pom of a (parent,child,grandchild) hierarchy * @throws Exception */ + @Test public void testBuildFromMiddlePom() throws Exception { File f1 = getTestFile( "src/test/resources/projects/grandchild-check/child/pom.xml"); @@ -103,6 +115,7 @@ public class DefaultMavenProjectBuilderTest getProject( f2 ); } + @Test public void testDuplicatePluginDefinitionsMerged() throws Exception { @@ -114,22 +127,20 @@ public class DefaultMavenProjectBuilderTest assertEquals( "first", project.getBuildPlugins().get( 0 ).getExecutions().get( 0 ).getId() ); } + @Test public void testFutureModelVersion() throws Exception { File f1 = getTestFile( "src/test/resources/projects/future-model-version-pom.xml" ); - try - { - getProject( f1 ); - fail( "Expected to fail for future versions" ); - } - catch ( ProjectBuildingException e ) - { - assertContains( "Building this project requires a newer version of Maven", e.getMessage() ); - } + ProjectBuildingException e = assertThrows( + ProjectBuildingException.class, + () -> getProject( f1 ), + "Expected to fail for future versions" ); + assertContains( "Building this project requires a newer version of Maven", e.getMessage() ); } + @Test public void testPastModelVersion() throws Exception { @@ -137,31 +148,24 @@ public class DefaultMavenProjectBuilderTest // update the resource if we stop supporting modelVersion 4.0.0 File f1 = getTestFile( "src/test/resources/projects/past-model-version-pom.xml" ); - try - { - getProject( f1 ); - fail( "Expected to fail for past versions" ); - } - catch ( ProjectBuildingException e ) - { - assertContains( "Building this project requires an older version of Maven", e.getMessage() ); - } + ProjectBuildingException e = assertThrows( + ProjectBuildingException.class, + () -> getProject( f1 ), + "Expected to fail for past versions" ); + assertContains( "Building this project requires an older version of Maven", e.getMessage() ); } + @Test public void testFutureSchemaModelVersion() throws Exception { File f1 = getTestFile( "src/test/resources/projects/future-schema-model-version-pom.xml" ); - try - { - getProject( f1 ); - fail( "Expected to fail for future versions" ); - } - catch ( ProjectBuildingException e ) - { - assertContains( "Building this project requires a newer version of Maven", e.getMessage() ); - } + ProjectBuildingException e = assertThrows( + ProjectBuildingException.class, + () -> getProject( f1 ), + "Expected to fail for future versions" ); + assertContains( "Building this project requires a newer version of Maven", e.getMessage() ); } private void assertContains( String expected, String actual ) @@ -174,6 +178,7 @@ public class DefaultMavenProjectBuilderTest } } + @Test public void testBuildStubModelForMissingRemotePom() throws Exception { @@ -211,31 +216,28 @@ public class DefaultMavenProjectBuilderTest } } + @Test public void testPartialResultUponBadDependencyDeclaration() throws Exception { File pomFile = getTestFile( "src/test/resources/projects/bad-dependency.xml" ); - try - { - ProjectBuildingRequest request = newBuildingRequest(); - request.setProcessPlugins( false ); - request.setResolveDependencies( true ); - projectBuilder.build( pomFile, request ); - fail( "Project building did not fail despite invalid POM" ); - } - catch ( ProjectBuildingException e ) - { - List results = e.getResults(); - assertNotNull( results ); - assertEquals( 1, results.size() ); - ProjectBuildingResult result = results.get( 0 ); - assertNotNull( result ); - assertNotNull( result.getProject() ); - assertEquals( 1, result.getProblems().size() ); - assertEquals( 1, result.getProject().getArtifacts().size() ); - assertNotNull( result.getDependencyResolutionResult() ); - } + ProjectBuildingRequest request = newBuildingRequest(); + request.setProcessPlugins( false ); + request.setResolveDependencies( true ); + ProjectBuildingException e = assertThrows( + ProjectBuildingException.class, + () -> projectBuilder.build( pomFile, request ), + "Project building did not fail despite invalid POM" ); + List results = e.getResults(); + assertNotNull( results ); + assertEquals( 1, results.size() ); + ProjectBuildingResult result = results.get( 0 ); + assertNotNull( result ); + assertNotNull( result.getProject() ); + assertEquals( 1, result.getProblems().size() ); + assertEquals( 1, result.getProject().getArtifacts().size() ); + assertNotNull( result.getDependencyResolutionResult() ); } /** @@ -243,6 +245,7 @@ public class DefaultMavenProjectBuilderTest * * @throws Exception */ + @Test public void testBuildValidParentVersionRangeLocally() throws Exception { File f1 = getTestFile( "src/test/resources/projects/parent-version-range-local-valid/child/pom.xml" ); @@ -262,21 +265,18 @@ public class DefaultMavenProjectBuilderTest * * @throws Exception */ + @Test public void testBuildParentVersionRangeLocallyWithoutChildVersion() throws Exception { File f1 = getTestFile( "src/test/resources/projects/parent-version-range-local-child-without-version/child/pom.xml" ); - try - { - getProject( f1 ); - fail( "Expected 'ProjectBuildingException' not thrown." ); - } - catch ( final ProjectBuildingException e ) - { - assertNotNull( e.getMessage() ); - assertThat( e.getMessage(), containsString( "Version must be a constant" ) ); - } + ProjectBuildingException e = assertThrows( + ProjectBuildingException.class, + () -> getProject( f1 ), + "Expected 'ProjectBuildingException' not thrown." ); + assertNotNull( e.getMessage() ); + assertThat( e.getMessage(), containsString( "Version must be a constant" ) ); } /** @@ -284,22 +284,19 @@ public class DefaultMavenProjectBuilderTest * * @throws Exception */ + @Test public void testBuildParentVersionRangeLocallyWithChildVersionExpression() throws Exception { File f1 = getTestFile( "src/test/resources/projects/parent-version-range-local-child-version-expression/child/pom.xml" ); - try - { - getProject( f1 ); - fail( "Expected 'ProjectBuildingException' not thrown." ); - } - catch ( final ProjectBuildingException e ) - { - assertNotNull( e.getMessage() ); - assertThat( e.getMessage(), containsString( "Version must be a constant" ) ); - } + ProjectBuildingException e = assertThrows( + ProjectBuildingException.class, + () -> getProject( f1 ), + "Expected 'ProjectBuildingException' not thrown." ); + assertNotNull( e.getMessage() ); + assertThat( e.getMessage(), containsString( "Version must be a constant" ) ); } /** @@ -307,6 +304,7 @@ public class DefaultMavenProjectBuilderTest * * @throws Exception */ + @Test public void testBuildParentVersionRangeExternally() throws Exception { File f1 = getTestFile( "src/test/resources/projects/parent-version-range-external-valid/pom.xml" ); @@ -326,22 +324,19 @@ public class DefaultMavenProjectBuilderTest * * @throws Exception */ + @Test public void testBuildParentVersionRangeExternallyWithoutChildVersion() throws Exception { File f1 = getTestFile( "src/test/resources/projects/parent-version-range-external-child-without-version/pom.xml" ); - try - { - this.getProjectFromRemoteRepository( f1 ); - fail( "Expected 'ProjectBuildingException' not thrown." ); - } - catch ( final ProjectBuildingException e ) - { - assertNotNull( e.getMessage() ); - assertThat( e.getMessage(), containsString( "Version must be a constant" ) ); - } + ProjectBuildingException e = assertThrows( + ProjectBuildingException.class, + () -> getProjectFromRemoteRepository( f1 ), + "Expected 'ProjectBuildingException' not thrown." ); + assertNotNull( e.getMessage() ); + assertThat( e.getMessage(), containsString( "Version must be a constant" ) ); } /** @@ -349,22 +344,19 @@ public class DefaultMavenProjectBuilderTest * * @throws Exception */ + @Test public void testBuildParentVersionRangeExternallyWithChildVersionExpression() throws Exception { File f1 = getTestFile( "src/test/resources/projects/parent-version-range-external-child-version-expression/pom.xml" ); - try - { - this.getProjectFromRemoteRepository( f1 ); - fail( "Expected 'ProjectBuildingException' not thrown." ); - } - catch ( final ProjectBuildingException e ) - { - assertNotNull( e.getMessage() ); - assertThat( e.getMessage(), containsString( "Version must be a constant" ) ); - } + ProjectBuildingException e = assertThrows( + ProjectBuildingException.class, + () -> getProjectFromRemoteRepository( f1 ), + "Expected 'ProjectBuildingException' not thrown." ); + assertNotNull( e.getMessage() ); + assertThat( e.getMessage(), containsString( "Version must be a constant" ) ); } } diff --git a/maven-core/src/test/java/org/apache/maven/project/ExtensionDescriptorBuilderTest.java b/maven-core/src/test/java/org/apache/maven/project/ExtensionDescriptorBuilderTest.java index 5ac8f611cf..150eb6a949 100644 --- a/maven-core/src/test/java/org/apache/maven/project/ExtensionDescriptorBuilderTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/ExtensionDescriptorBuilderTest.java @@ -19,16 +19,20 @@ package org.apache.maven.project; * under the License. */ -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - import java.io.ByteArrayInputStream; import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.Arrays; -import junit.framework.TestCase; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.hamcrest.MatcherAssert.assertThat; /** * Tests {@link ExtensionDescriptorBuilder}. @@ -36,27 +40,22 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class ExtensionDescriptorBuilderTest - extends TestCase { private ExtensionDescriptorBuilder builder; - @Override - protected void setUp() + @BeforeEach + public void setUp() throws Exception { - super.setUp(); - builder = new ExtensionDescriptorBuilder(); } - @Override - protected void tearDown() + @AfterEach + public void tearDown() throws Exception { builder = null; - - super.tearDown(); } private InputStream toStream( String xml ) @@ -64,6 +63,7 @@ public class ExtensionDescriptorBuilderTest return new ByteArrayInputStream( xml.getBytes( StandardCharsets.UTF_8 ) ); } + @Test public void testEmptyDescriptor() throws Exception { @@ -78,6 +78,7 @@ public class ExtensionDescriptorBuilderTest assertThat( ed.getExportedArtifacts(), is( empty() ) ); } + @Test public void testCompleteDescriptor() throws Exception { diff --git a/maven-core/src/test/java/org/apache/maven/project/MavenProjectTest.java b/maven-core/src/test/java/org/apache/maven/project/MavenProjectTest.java index 6b4258b3fd..d2cba20a41 100644 --- a/maven-core/src/test/java/org/apache/maven/project/MavenProjectTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/MavenProjectTest.java @@ -28,11 +28,19 @@ import org.apache.maven.model.DependencyManagement; import org.apache.maven.model.Model; import org.apache.maven.model.Parent; import org.apache.maven.model.Profile; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertTrue; public class MavenProjectTest extends AbstractMavenProjectTestCase { + @Test public void testShouldInterpretChildPathAdjustmentBasedOnModulePaths() throws IOException { @@ -59,6 +67,7 @@ public class MavenProjectTest assertEquals( "..", adjustment ); } + @Test public void testIdentityProtoInheritance() { Parent parent = new Parent(); @@ -74,14 +83,15 @@ public class MavenProjectTest MavenProject project = new MavenProject( model ); - assertEquals( "groupId proto-inheritance failed.", "test-group", project.getGroupId() ); - assertEquals( "artifactId is masked.", "real-artifact", project.getArtifactId() ); - assertEquals( "version proto-inheritance failed.", "1000", project.getVersion() ); + assertEquals( "test-group", project.getGroupId(), "groupId proto-inheritance failed." ); + assertEquals( "real-artifact", project.getArtifactId(), "artifactId is masked." ); + assertEquals( "1000", project.getVersion(), "version proto-inheritance failed." ); // draw the NPE. project.getId(); } + @Test public void testEmptyConstructor() { MavenProject project = new MavenProject(); @@ -90,6 +100,7 @@ public class MavenProjectTest + MavenProject.EMPTY_PROJECT_VERSION, project.getId() ); } + @Test public void testClone() throws Exception { @@ -99,34 +110,35 @@ public class MavenProjectTest MavenProject clonedProject = projectToClone.clone(); assertEquals( "maven-core", clonedProject.getArtifactId() ); Map clonedMap = clonedProject.getManagedVersionMap(); - assertNotNull( "ManagedVersionMap not copied", clonedMap ); - assertTrue( "ManagedVersionMap is not empty", clonedMap.isEmpty() ); + assertNotNull( clonedMap, "ManagedVersionMap not copied" ); + assertTrue( clonedMap.isEmpty(), "ManagedVersionMap is not empty" ); } + @Test public void testCloneWithDependencyManagement() throws Exception { File f = getFileForClasspathResource( "dependencyManagement-pom.xml" ); MavenProject projectToClone = getProjectWithDependencies( f ); DependencyManagement dep = projectToClone.getDependencyManagement(); - assertNotNull( "No dependencyManagement", dep ); + assertNotNull( dep, "No dependencyManagement" ); List list = dep.getDependencies(); - assertNotNull( "No dependencies", list ); - assertTrue( "Empty dependency list", !list.isEmpty() ); + assertNotNull( list, "No dependencies" ); + assertTrue( !list.isEmpty(), "Empty dependency list" ); Map map = projectToClone.getManagedVersionMap(); - assertNotNull( "No ManagedVersionMap", map ); - assertTrue( "ManagedVersionMap is empty", !map.isEmpty() ); + assertNotNull( map, "No ManagedVersionMap" ); + assertTrue( !map.isEmpty(), "ManagedVersionMap is empty" ); MavenProject clonedProject = projectToClone.clone(); assertEquals( "maven-core", clonedProject.getArtifactId() ); Map clonedMap = clonedProject.getManagedVersionMap(); - assertNotNull( "ManagedVersionMap not copied", clonedMap ); - assertTrue( "ManagedVersionMap is empty", !clonedMap.isEmpty() ); - assertTrue( "ManagedVersionMap does not contain test key", - clonedMap.containsKey( "maven-test:maven-test-b:jar" ) ); + assertNotNull( clonedMap, "ManagedVersionMap not copied" ); + assertTrue( !clonedMap.isEmpty(), "ManagedVersionMap is empty" ); + assertTrue( clonedMap.containsKey( "maven-test:maven-test-b:jar" ), "ManagedVersionMap does not contain test key" ); } + @Test public void testGetModulePathAdjustment() throws IOException { @@ -146,6 +158,7 @@ public class MavenProjectTest assertEquals( "..", pathAdjustment ); } + @Test public void testCloneWithDistributionManagement() throws Exception { @@ -154,9 +167,10 @@ public class MavenProjectTest MavenProject projectToClone = getProject( f ); MavenProject clonedProject = projectToClone.clone(); - assertNotNull( "clonedProject - distributionManagement", clonedProject.getDistributionManagementArtifactRepository() ); + assertNotNull( clonedProject.getDistributionManagementArtifactRepository(), "clonedProject - distributionManagement" ); } + @Test public void testCloneWithActiveProfile() throws Exception { @@ -165,18 +179,19 @@ public class MavenProjectTest MavenProject projectToClone = getProject( f ); List activeProfilesOrig = projectToClone.getActiveProfiles(); - assertEquals( "Expecting 1 active profile", 1, activeProfilesOrig.size() ); + assertEquals( 1, activeProfilesOrig.size(), "Expecting 1 active profile" ); MavenProject clonedProject = projectToClone.clone(); List activeProfilesClone = clonedProject.getActiveProfiles(); - assertEquals( "Expecting 1 active profile", 1, activeProfilesClone.size() ); + assertEquals( 1, activeProfilesClone.size(), "Expecting 1 active profile" ); - assertNotSame( "The list of active profiles should have been cloned too but is same", activeProfilesOrig, - activeProfilesClone ); + assertNotSame( activeProfilesOrig, activeProfilesClone, + "The list of active profiles should have been cloned too but is same" ); } + @Test public void testCloneWithBaseDir() throws Exception { @@ -184,10 +199,11 @@ public class MavenProjectTest MavenProject projectToClone = getProject( f ); projectToClone.setPomFile( new File( new File( f.getParentFile(), "target" ), "flattened.xml" ) ); MavenProject clonedProject = projectToClone.clone(); - assertEquals( "POM file is preserved across clone", projectToClone.getFile(), clonedProject.getFile() ); - assertEquals( "Base directory is preserved across clone", projectToClone.getBasedir(), clonedProject.getBasedir() ); + assertEquals( projectToClone.getFile(), clonedProject.getFile(), "POM file is preserved across clone" ); + assertEquals( projectToClone.getBasedir(), clonedProject.getBasedir(), "Base directory is preserved across clone" ); } + @Test public void testUndefinedOutputDirectory() throws Exception { @@ -198,6 +214,7 @@ public class MavenProjectTest assertNoNulls( p.getTestClasspathElements() ); } + @Test public void testAddDotFile() { MavenProject project = new MavenProject(); diff --git a/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java b/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java index e953dbc8e2..6a53907e10 100644 --- a/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java @@ -22,11 +22,13 @@ package org.apache.maven.project; import java.io.File; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Properties; +import javax.inject.Inject; + +import org.apache.maven.test.PlexusTestCase; import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; import org.apache.maven.model.Plugin; import org.apache.maven.model.PluginExecution; @@ -34,19 +36,23 @@ import org.apache.maven.model.building.ModelBuildingRequest; import org.apache.maven.project.harness.PomTestWrapper; import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.internal.MavenRepositorySystemUtils; -import org.codehaus.plexus.ContainerConfiguration; -import org.codehaus.plexus.DefaultPlexusContainer; -import org.codehaus.plexus.PlexusConstants; -import org.codehaus.plexus.PlexusTestCase; import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; import org.eclipse.aether.repository.LocalRepository; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import javax.inject.Inject; - -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.endsWith; +import static org.hamcrest.Matchers.lessThan; +import static org.hamcrest.Matchers.startsWith; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; public class PomConstructionTest extends PlexusTestCase @@ -65,33 +71,17 @@ public class PomConstructionTest private File testDirectory; - @Override - protected synchronized void setupContainer() - { - super.setupContainer(); - - ( (DefaultPlexusContainer) getContainer() ).addPlexusInjector( Collections.emptyList(), - binder -> binder.requestInjection( this ) ); - } - - @Override - protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration ) - { - super.customizeContainerConfiguration( containerConfiguration ); - containerConfiguration.setAutoWiring( true ); - containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); - } - - protected void setUp() + @BeforeEach + public void setUp() throws Exception { - getContainer(); + super.setUp(); testDirectory = new File( getBasedir(), BASE_POM_DIR ); new File( getBasedir(), BASE_MIXIN_DIR ); } - @Override - protected void tearDown() + @AfterEach + public void tearDown() throws Exception { projectBuilder = null; @@ -104,7 +94,7 @@ public class PomConstructionTest * * @throws Exception */ - + @Test public void testEmptyUrl() throws Exception { @@ -117,6 +107,7 @@ public class PomConstructionTest * @throws Exception */ /* MNG-786*/ + @Test public void testProfileModules() throws Exception { @@ -134,6 +125,7 @@ public class PomConstructionTest * * @throws Exception */ + @Test public void testParentInheritance() throws Exception { @@ -141,6 +133,7 @@ public class PomConstructionTest } /*MNG-3995*/ + @Test public void testExecutionConfigurationJoin() throws Exception { @@ -149,6 +142,7 @@ public class PomConstructionTest } /*MNG-3803*/ + @Test public void testPluginConfigProperties() throws Exception { @@ -157,6 +151,7 @@ public class PomConstructionTest } /*MNG-3900*/ + @Test public void testProfilePropertiesInterpolation() throws Exception { @@ -188,6 +183,7 @@ public class PomConstructionTest } /*MNG- 4010*/ + @Test public void testDuplicateExclusionsDependency() throws Exception { @@ -197,6 +193,7 @@ public class PomConstructionTest } /*MNG- 4008*/ + @Test public void testMultipleFilters() throws Exception { @@ -220,6 +217,7 @@ public class PomConstructionTest } } + @Test public void testValidationErrorUponNonUniqueDependencyManagementKey() throws Exception { @@ -234,6 +232,7 @@ public class PomConstructionTest } } + @Test public void testValidationErrorUponNonUniqueDependencyKeyInProfile() throws Exception { @@ -248,6 +247,7 @@ public class PomConstructionTest } } + @Test public void testValidationErrorUponNonUniqueDependencyManagementKeyInProfile() throws Exception { @@ -262,7 +262,7 @@ public class PomConstructionTest } } */ - + @Test public void testDuplicateDependenciesCauseLastDeclarationToBePickedInLenientMode() throws Exception { @@ -272,6 +272,7 @@ public class PomConstructionTest } /* MNG-3567*/ + @Test public void testParentInterpolation() throws Exception { @@ -295,6 +296,7 @@ public class PomConstructionTest */ /* MNG-3567*/ + @Test public void testPluginManagementInherited() throws Exception { @@ -303,6 +305,7 @@ public class PomConstructionTest } /* MNG-2174*/ + @Test public void testPluginManagementDependencies() throws Exception { @@ -313,6 +316,7 @@ public class PomConstructionTest /* MNG-3877*/ + @Test public void testReportingInterpolation() throws Exception { @@ -323,6 +327,7 @@ public class PomConstructionTest } + @Test public void testPluginOrder() throws Exception { @@ -331,6 +336,7 @@ public class PomConstructionTest assertEquals( "maven-surefire-plugin", pom.getValue( "build/plugins[2]/artifactId" ) ); } + @Test public void testErroneousJoiningOfDifferentPluginsWithEqualDependencies() throws Exception { @@ -342,6 +348,7 @@ public class PomConstructionTest } /** MNG-3821 */ + @Test public void testErroneousJoiningOfDifferentPluginsWithEqualExecutionIds() throws Exception { @@ -357,6 +364,7 @@ public class PomConstructionTest } /** MNG-3998 */ + @Test public void testExecutionConfiguration() throws Exception { @@ -375,8 +383,7 @@ public class PomConstructionTest PomTestWrapper pom = buildPom( "plugin-config-duplicate/dup" ); } */ - - + @Test public void testSingleConfigurationInheritance() throws Exception { @@ -389,6 +396,7 @@ public class PomConstructionTest pom.getValue( "build/plugins[1]/executions[1]/configuration[1]/rules[1]/requireJavaVersion[1]/version" ) ); } + @Test public void testConfigWithPluginManagement() throws Exception { @@ -399,6 +407,7 @@ public class PomConstructionTest } /** MNG-3965 */ + @Test public void testExecutionConfigurationSubcollections() throws Exception { @@ -407,6 +416,7 @@ public class PomConstructionTest } /** MNG-3985 */ + @Test public void testMultipleRepositories() throws Exception { @@ -415,6 +425,7 @@ public class PomConstructionTest } /** MNG-3965 */ + @Test public void testMultipleExecutionIds() throws Exception { @@ -423,12 +434,14 @@ public class PomConstructionTest } /** MNG-3997 */ + @Test public void testConsecutiveEmptyElements() throws Exception { buildPom( "consecutive_empty_elements" ); } + @Test public void testOrderOfGoalsFromPluginExecutionWithoutPluginManagement() throws Exception { @@ -442,6 +455,7 @@ public class PomConstructionTest } /* MNG-3886*/ + @Test public void testOrderOfGoalsFromPluginExecutionWithPluginManagement() throws Exception { @@ -454,6 +468,7 @@ public class PomConstructionTest assertEquals( "e", pom.getValue( "build/plugins[1]/executions[1]/goals[5]" ) ); } + @Test public void testOrderOfPluginExecutionsWithoutPluginManagement() throws Exception { @@ -467,6 +482,7 @@ public class PomConstructionTest } /* MNG-3887 */ + @Test public void testOrderOfPluginExecutionsWithPluginManagement() throws Exception { @@ -479,6 +495,7 @@ public class PomConstructionTest assertEquals( "e", pom.getValue( "build/plugins[1]/executions[5]/id" ) ); } + @Test public void testMergeOfPluginExecutionsWhenChildInheritsPluginVersion() throws Exception { @@ -487,6 +504,7 @@ public class PomConstructionTest } /* MNG-3943*/ + @Test public void testMergeOfPluginExecutionsWhenChildAndParentUseDifferentPluginVersions() throws Exception { @@ -495,6 +513,7 @@ public class PomConstructionTest } + @Test public void testInterpolationWithXmlMarkup() throws Exception { @@ -503,6 +522,7 @@ public class PomConstructionTest } /* MNG-3925 */ + @Test public void testOrderOfMergedPluginExecutionsWithoutPluginManagement() throws Exception { @@ -515,6 +535,7 @@ public class PomConstructionTest assertEquals( "child-2", pom.getValue( "build/plugins[1]/executions[5]/goals[1]" ) ); } + @Test public void testOrderOfMergedPluginExecutionsWithPluginManagement() throws Exception { @@ -528,6 +549,7 @@ public class PomConstructionTest } /* MNG-3984*/ + @Test public void testDifferentContainersWithSameId() throws Exception { @@ -537,6 +559,7 @@ public class PomConstructionTest } /* MNG-3937*/ + @Test public void testOrderOfMergedPluginExecutionGoalsWithoutPluginManagement() throws Exception { @@ -550,6 +573,7 @@ public class PomConstructionTest assertEquals( "parent-a", pom.getValue( "build/plugins[1]/executions[1]/goals[5]" ) ); } + @Test public void testOrderOfMergedPluginExecutionGoalsWithPluginManagement() throws Exception { @@ -563,6 +587,7 @@ public class PomConstructionTest } /*MNG-3938*/ + @Test public void testOverridingOfInheritedPluginExecutionsWithoutPluginManagement() throws Exception { @@ -573,6 +598,7 @@ public class PomConstructionTest } /* MNG-3938 */ + @Test public void testOverridingOfInheritedPluginExecutionsWithPluginManagement() throws Exception { @@ -584,6 +610,7 @@ public class PomConstructionTest /* MNG-3906*/ + @Test public void testOrderOfMergedPluginDependenciesWithoutPluginManagement() throws Exception { @@ -603,6 +630,7 @@ public class PomConstructionTest assertEquals( "1", pom.getValue( "build/plugins[1]/dependencies[5]/version" ) ); } + @Test public void testOrderOfMergedPluginDependenciesWithPluginManagement() throws Exception { @@ -620,6 +648,7 @@ public class PomConstructionTest assertEquals( "1", pom.getValue( "build/plugins[1]/dependencies[5]/version" ) ); } + @Test public void testInterpolationOfNestedBuildDirectories() throws Exception { @@ -632,6 +661,7 @@ public class PomConstructionTest new File( (String) pom.getValue( "properties/dir2" ) ) ); } + @Test public void testAppendArtifactIdOfChildToInheritedUrls() throws Exception { @@ -651,6 +681,7 @@ public class PomConstructionTest } /* MNG-3846*/ + @Test public void testAppendArtifactIdOfParentAndChildToInheritedUrls() throws Exception { @@ -669,7 +700,7 @@ public class PomConstructionTest assertEquals( "https://parent.url/download", pom.getValue( "distributionManagement/downloadUrl" ) ); } //*/ - + @Test public void testNonInheritedElementsInSubtreesOverriddenByChild() throws Exception { @@ -692,6 +723,7 @@ public class PomConstructionTest assertEquals( null, pom.getValue( "distributionManagement/site/name" ) ); } + @Test public void testXmlTextCoalescing() throws Exception { @@ -702,6 +734,7 @@ public class PomConstructionTest pom.getValue( "properties/prop2" ).toString().trim().replaceAll( "[\n\r]", "" ).length() ); } + @Test public void testFullInterpolationOfNestedExpressions() throws Exception { @@ -713,6 +746,7 @@ public class PomConstructionTest } } + @Test public void testInterpolationOfLegacyExpressionsThatDontIncludeTheProjectPrefix() throws Exception { @@ -747,6 +781,7 @@ public class PomConstructionTest assertThat( pom.getValue( "properties/projectSiteOut" ).toString(), endsWith( "doc" ) ); } + @Test public void testInterpolationWithBasedirAlignedDirectories() throws Exception { @@ -768,6 +803,7 @@ public class PomConstructionTest } /* MNG-3944*/ + @Test public void testInterpolationOfBasedirInPomWithUnusualName() throws Exception { @@ -777,6 +813,7 @@ public class PomConstructionTest } /* MNG-3979 */ + @Test public void testJoiningOfContainersWhenChildHasEmptyElements() throws Exception { @@ -784,6 +821,7 @@ public class PomConstructionTest assertNotNull( pom ); } + @Test public void testOrderOfPluginConfigurationElementsWithoutPluginManagement() throws Exception { @@ -795,6 +833,7 @@ public class PomConstructionTest } /* MNG-3827*/ + @Test public void testOrderOfPluginConfigurationElementsWithPluginManagement() throws Exception { @@ -805,6 +844,7 @@ public class PomConstructionTest assertEquals( "four", pom.getValue( "build/plugins[1]/configuration/stringParams/stringParam[4]" ) ); } + @Test public void testOrderOfPluginExecutionConfigurationElementsWithoutPluginManagement() throws Exception { @@ -819,6 +859,7 @@ public class PomConstructionTest } /* MNG-3864*/ + @Test public void testOrderOfPluginExecutionConfigurationElementsWithPluginManagement() throws Exception { @@ -833,6 +874,7 @@ public class PomConstructionTest } /* MNG-3836*/ + @Test public void testMergeOfInheritedPluginConfiguration() throws Exception { @@ -852,6 +894,7 @@ public class PomConstructionTest } /* MNG-2591 */ + @Test public void testAppendOfInheritedPluginConfigurationWithNoProfile() throws Exception { @@ -859,6 +902,7 @@ public class PomConstructionTest } /* MNG-2591*/ + @Test public void testAppendOfInheritedPluginConfigurationWithActiveProfile() throws Exception { @@ -891,6 +935,7 @@ public class PomConstructionTest } /* MNG-4000 */ + @Test public void testMultiplePluginExecutionsWithAndWithoutIdsWithoutPluginManagement() throws Exception { @@ -900,6 +945,7 @@ public class PomConstructionTest assertEquals( "log-string", pom.getValue( "build/plugins[1]/executions[2]/goals[1]" ) ); } + @Test public void testMultiplePluginExecutionsWithAndWithoutIdsWithPluginManagement() throws Exception { @@ -909,6 +955,7 @@ public class PomConstructionTest assertEquals( "log-string", pom.getValue( "build/plugins[1]/executions[2]/goals[1]" ) ); } + @Test public void testDependencyOrderWithoutPluginManagement() throws Exception { @@ -920,6 +967,7 @@ public class PomConstructionTest assertEquals( "d", pom.getValue( "dependencies[4]/artifactId" ) ); } + @Test public void testDependencyOrderWithPluginManagement() throws Exception { @@ -931,6 +979,7 @@ public class PomConstructionTest assertEquals( "d", pom.getValue( "dependencies[4]/artifactId" ) ); } + @Test public void testBuildDirectoriesUsePlatformSpecificFileSeparator() throws Exception { @@ -947,6 +996,7 @@ public class PomConstructionTest } /* MNG-4008 */ + @Test public void testMergedFilterOrder() throws Exception { @@ -963,6 +1013,7 @@ public class PomConstructionTest } /** MNG-4027*/ + @Test public void testProfileInjectedDependencies() throws Exception { @@ -975,6 +1026,7 @@ public class PomConstructionTest } /** IT-0021*/ + @Test public void testProfileDependenciesMultipleProfiles() throws Exception { @@ -982,6 +1034,7 @@ public class PomConstructionTest assertEquals(2, ( (List) pom.getValue( "dependencies" ) ).size() ); } + @Test public void testDependencyInheritance() throws Exception { @@ -991,6 +1044,7 @@ public class PomConstructionTest } /** MNG-4034 */ + @Test public void testManagedProfileDependency() throws Exception { @@ -1005,6 +1059,7 @@ public class PomConstructionTest } /** MNG-4040 */ + @Test public void testProfileModuleInheritance() throws Exception { @@ -1013,6 +1068,7 @@ public class PomConstructionTest } /** MNG-3621 */ + @Test public void testUncPath() throws Exception { @@ -1021,6 +1077,7 @@ public class PomConstructionTest } /** MNG-2006 */ + @Test public void testUrlAppendWithChildPathAdjustment() throws Exception { @@ -1033,6 +1090,7 @@ public class PomConstructionTest } /** MNG-0479 */ + @Test public void testRepoInheritance() throws Exception { @@ -1041,6 +1099,7 @@ public class PomConstructionTest assertEquals( "it0043", pom.getValue( "repositories[1]/name" ) ); } + @Test public void testEmptyScm() throws Exception { @@ -1048,6 +1107,7 @@ public class PomConstructionTest assertNull( pom.getValue( "scm" ) ); } + @Test public void testPluginConfigurationUsingAttributesWithoutPluginManagement() throws Exception { @@ -1060,6 +1120,7 @@ public class PomConstructionTest } /** MNG-4053*/ + @Test public void testPluginConfigurationUsingAttributesWithPluginManagement() throws Exception { @@ -1071,6 +1132,7 @@ public class PomConstructionTest assertEquals( null, pom.getValue( "build/plugins[1]/configuration/domParam/copy/fileset/@overwrite" ) ); } + @Test public void testPluginConfigurationUsingAttributesWithPluginManagementAndProfile() throws Exception { @@ -1082,6 +1144,7 @@ public class PomConstructionTest assertEquals( null, pom.getValue( "build/plugins[1]/configuration/domParam/copy/fileset/@overwrite" ) ); } + @Test public void testPomEncoding() throws Exception { @@ -1092,6 +1155,7 @@ public class PomConstructionTest } /* MNG-4070 */ + @Test public void testXmlWhitespaceHandling() throws Exception { @@ -1100,6 +1164,7 @@ public class PomConstructionTest } /* MNG-3760*/ + @Test public void testInterpolationOfBaseUri() throws Exception { @@ -1108,6 +1173,7 @@ public class PomConstructionTest } /* MNG-6386 */ + @Test public void testInterpolationOfRfc3986BaseUri() throws Exception { @@ -1118,6 +1184,7 @@ public class PomConstructionTest } /* MNG-3811*/ + @Test public void testReportingPluginConfig() throws Exception { @@ -1130,6 +1197,7 @@ public class PomConstructionTest assertEquals( "true", pom.getValue( "reporting/plugins[1]/configuration/booleanParam" ) ); } + @Test public void testPropertiesNoDuplication() throws Exception { @@ -1138,6 +1206,7 @@ public class PomConstructionTest assertEquals( "child", pom.getValue( "properties/pomProfile" ) ); } + @Test public void testPomInheritance() throws Exception { @@ -1146,6 +1215,7 @@ public class PomConstructionTest assertEquals( "jar", pom.getValue( "packaging" ) ); } + @Test public void testCompleteModelWithoutParent() throws Exception { @@ -1154,6 +1224,7 @@ public class PomConstructionTest testCompleteModel( pom ); } + @Test public void testCompleteModelWithParent() throws Exception { @@ -1369,7 +1440,7 @@ public class PomConstructionTest } /* MNG-2309*/ - + @Test public void testProfileInjectionOrder() throws Exception { @@ -1378,6 +1449,7 @@ public class PomConstructionTest assertEquals( "e", pom.getValue( "properties[1]/pomProperty" ) ); } + @Test public void testPropertiesInheritance() throws Exception { @@ -1388,6 +1460,7 @@ public class PomConstructionTest } /* MNG-4102*/ + @Test public void testInheritedPropertiesInterpolatedWithValuesFromChildWithoutProfiles() throws Exception { @@ -1398,6 +1471,7 @@ public class PomConstructionTest } /* MNG-4102 */ + @Test public void testInheritedPropertiesInterpolatedWithValuesFromChildWithActiveProfiles() throws Exception { @@ -1411,6 +1485,7 @@ public class PomConstructionTest } /* MNG-3545 */ + @Test public void testProfileDefaultActivation() throws Exception { @@ -1421,6 +1496,7 @@ public class PomConstructionTest } /* MNG-1995 */ + @Test public void testBooleanInterpolation() throws Exception { @@ -1431,6 +1507,7 @@ public class PomConstructionTest /* MNG-3899 */ + @Test public void testBuildExtensionInheritance() throws Exception { @@ -1443,6 +1520,7 @@ public class PomConstructionTest } /*MNG-1957*/ + @Test public void testJdkActivation() throws Exception { @@ -1457,6 +1535,7 @@ public class PomConstructionTest } /* MNG-2174 */ + @Test public void testProfilePluginMngDependencies() throws Exception { @@ -1465,6 +1544,7 @@ public class PomConstructionTest } /** MNG-4116 */ + @Test public void testPercentEncodedUrlsMustNotBeDecoded() throws Exception { @@ -1483,6 +1563,7 @@ public class PomConstructionTest pom.getValue( "distributionManagement/site/url" ) ); } + @Test public void testPluginManagementInheritance() throws Exception { @@ -1491,6 +1572,7 @@ public class PomConstructionTest pom.getValue( "build/pluginManagement/plugins[@artifactId='maven-compiler-plugin']/version" ) ); } + @Test public void testProfilePlugins() throws Exception { @@ -1499,6 +1581,7 @@ public class PomConstructionTest assertEquals( "maven-assembly2-plugin", pom.getValue( "build/plugins[2]/artifactId" ) ); } + @Test public void testPluginInheritanceSimple() throws Exception { @@ -1506,6 +1589,7 @@ public class PomConstructionTest assertEquals( 2, ( (List) pom.getValue( "build/plugins" ) ).size() ); } + @Test public void testPluginManagementDuplicate() throws Exception { @@ -1513,6 +1597,7 @@ public class PomConstructionTest assertEquals( 8, ( (List) pom.getValue( "build/pluginManagement/plugins" ) ).size() ); } + @Test public void testDistributionManagement() throws Exception { @@ -1520,6 +1605,7 @@ public class PomConstructionTest assertEquals( "legacy", pom.getValue( "distributionManagement/repository/layout" ) ); } + @Test public void testDependencyScopeInheritance() throws Exception { @@ -1528,6 +1614,7 @@ public class PomConstructionTest assertEquals( "compile", scope ); } + @Test public void testDependencyScope() throws Exception { @@ -1541,6 +1628,7 @@ public class PomConstructionTest buildPom( "dependency-management-with-interpolation/sub" ); } + @Test public void testInterpolationWithSystemProperty() throws Exception { @@ -1551,6 +1639,7 @@ public class PomConstructionTest } /* MNG-4129 */ + @Test public void testPluginExecutionInheritanceWhenChildDoesNotDeclarePlugin() throws Exception { @@ -1562,6 +1651,7 @@ public class PomConstructionTest assertEquals( "inherited-execution", executions.get( 0 ).getId() ); } + @Test public void testPluginExecutionInheritanceWhenChildDoesDeclarePluginAsWell() throws Exception { @@ -1574,66 +1664,51 @@ public class PomConstructionTest } /* MNG-4193 */ + @Test public void testValidationErrorUponNonUniqueArtifactRepositoryId() throws Exception { - try - { - buildPom( "unique-repo-id/artifact-repo" ); - fail( "Non-unique repository ids did not cause validation error" ); - } - catch ( ProjectBuildingException e ) - { - // expected - } + assertThrows( + ProjectBuildingException.class, + () -> buildPom( "unique-repo-id/artifact-repo" ), + "Non-unique repository ids did not cause validation error" ); } /* MNG-4193 */ + @Test public void testValidationErrorUponNonUniquePluginRepositoryId() throws Exception { - try - { - buildPom( "unique-repo-id/plugin-repo" ); - fail( "Non-unique repository ids did not cause validation error" ); - } - catch ( ProjectBuildingException e ) - { - // expected - } + assertThrows( + ProjectBuildingException.class, + () -> buildPom( "unique-repo-id/plugin-repo" ), + "Non-unique repository ids did not cause validation error" ); } /* MNG-4193 */ + @Test public void testValidationErrorUponNonUniqueArtifactRepositoryIdInProfile() throws Exception { - try - { - buildPom( "unique-repo-id/artifact-repo-in-profile" ); - fail( "Non-unique repository ids did not cause validation error" ); - } - catch ( ProjectBuildingException e ) - { - // expected - } + assertThrows( + ProjectBuildingException.class, + () -> buildPom( "unique-repo-id/artifact-repo-in-profile" ), + "Non-unique repository ids did not cause validation error" ); } /* MNG-4193 */ + @Test public void testValidationErrorUponNonUniquePluginRepositoryIdInProfile() throws Exception { - try - { - buildPom( "unique-repo-id/plugin-repo-in-profile" ); - fail( "Non-unique repository ids did not cause validation error" ); - } - catch ( ProjectBuildingException e ) - { - // expected - } + assertThrows( + ProjectBuildingException.class, + () -> buildPom( "unique-repo-id/plugin-repo-in-profile" ), + "Non-unique repository ids did not cause validation error" ); } /** MNG-3843 */ + @Test public void testPrerequisitesAreNotInherited() throws Exception { @@ -1641,6 +1716,7 @@ public class PomConstructionTest assertSame( null, pom.getValue( "prerequisites" ) ); } + @Test public void testLicensesAreInheritedButNotAggregated() throws Exception { @@ -1650,6 +1726,7 @@ public class PomConstructionTest assertEquals( "https://child.url/license", pom.getValue( "licenses[1]/url" ) ); } + @Test public void testDevelopersAreInheritedButNotAggregated() throws Exception { @@ -1658,6 +1735,7 @@ public class PomConstructionTest assertEquals( "child-developer", pom.getValue( "developers[1]/name" ) ); } + @Test public void testContributorsAreInheritedButNotAggregated() throws Exception { @@ -1666,6 +1744,7 @@ public class PomConstructionTest assertEquals( "child-contributor", pom.getValue( "contributors[1]/name" ) ); } + @Test public void testMailingListsAreInheritedButNotAggregated() throws Exception { @@ -1674,6 +1753,7 @@ public class PomConstructionTest assertEquals( "child-mailing-list", pom.getValue( "mailingLists[1]/name" ) ); } + @Test public void testPluginInheritanceOrder() throws Exception { @@ -1688,6 +1768,7 @@ public class PomConstructionTest assertEquals( "maven-it-plugin-configuration", pom.getValue( "reporting/plugins[3]/artifactId" ) ); } + @Test public void testCliPropsDominateProjectPropsDuringInterpolation() throws Exception { @@ -1698,21 +1779,18 @@ public class PomConstructionTest assertEquals( "PASSED", pom.getValue( "properties/interpolatedProperty" ) ); } + @Test public void testParentPomPackagingMustBePom() throws Exception { - try - { - buildPom( "parent-pom-packaging/sub" ); - fail( "Wrong packaging of parent POM was not rejected" ); - } - catch ( ProjectBuildingException e ) - { - // expected - } + assertThrows( + ProjectBuildingException.class, + () -> buildPom( "parent-pom-packaging/sub" ), + "Wrong packaging of parent POM was not rejected" ); } /** MNG-522, MNG-3018 */ + @Test public void testManagedPluginConfigurationAppliesToImplicitPluginsIntroducedByPackaging() throws Exception { @@ -1723,6 +1801,7 @@ public class PomConstructionTest pom.getValue( "build/plugins[@artifactId='maven-it-plugin-log-file']/configuration/logFile" ) ); } + @Test public void testDefaultPluginsExecutionContributedByPackagingExecuteBeforeUserDefinedExecutions() throws Exception { @@ -1738,6 +1817,7 @@ public class PomConstructionTest assertEquals( "test-2", executions.get( 3 ).getId() ); } + @Test public void testPluginDeclarationsRetainPomOrderAfterInjectionOfDefaultPlugins() throws Exception { @@ -1760,10 +1840,11 @@ public class PomConstructionTest customPlugin = i; } } - assertEquals( plugins.toString(), customPlugin, resourcesPlugin - 1 ); + assertEquals( customPlugin, resourcesPlugin - 1, plugins.toString() ); } /** MNG-4415 */ + @Test public void testPluginOrderAfterMergingWithInheritedPlugins() throws Exception { @@ -1793,6 +1874,7 @@ public class PomConstructionTest } /** MNG-4416 */ + @Test public void testPluginOrderAfterMergingWithInjectedPlugins() throws Exception { @@ -1821,18 +1903,14 @@ public class PomConstructionTest assertEquals( actual, expected ); } + @Test public void testProjectArtifactIdIsNotInheritedButMandatory() throws Exception { - try - { - buildPom( "artifact-id-inheritance/child" ); - fail( "Missing artifactId did not cause validation error" ); - } - catch ( ProjectBuildingException e ) - { - // expected - } + assertThrows( + ProjectBuildingException.class, + () -> buildPom( "artifact-id-inheritance/child" ), + "Missing artifactId did not cause validation error" ); } private void assertPathSuffixEquals( String expected, Object actual ) diff --git a/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java b/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java index 74c19a8edf..506a84470b 100644 --- a/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java @@ -19,14 +19,6 @@ package org.apache.maven.project; * under the License. */ -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.hasKey; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThrows; - import java.io.File; import java.nio.file.Files; import java.nio.file.Path; @@ -42,6 +34,18 @@ import org.apache.maven.model.building.FileModelSource; import org.apache.maven.model.building.ModelBuildingRequest; import org.apache.maven.model.building.ModelSource; import org.apache.maven.shared.utils.io.FileUtils; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.hasKey; +import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; public class ProjectBuilderTest @@ -53,6 +57,7 @@ public class ProjectBuilderTest return "src/test/projects/project-builder"; } + @Test public void testSystemScopeDependencyIsPresentInTheCompileClasspathElements() throws Exception { @@ -70,6 +75,7 @@ public class ProjectBuilderTest project.getCompileClasspathElements(); } + @Test public void testBuildFromModelSource() throws Exception { @@ -84,6 +90,7 @@ public class ProjectBuilderTest assertNotNull( result.getProject().getParentFile() ); } + @Test public void testVersionlessManagedDependency() throws Exception { @@ -99,6 +106,7 @@ public class ProjectBuilderTest + "@ line 9, column 17" ) ); } + @Test public void testResolveDependencies() throws Exception { @@ -120,6 +128,7 @@ public class ProjectBuilderTest assertEquals( 1, mavenProject.getArtifacts().size() ); } + @Test public void testDontResolveDependencies() throws Exception { @@ -139,6 +148,7 @@ public class ProjectBuilderTest assertEquals( 0, mavenProject.getArtifacts().size() ); } + @Test public void testReadModifiedPoms() throws Exception { String initialValue = System.setProperty( DefaultProjectBuilder.DISABLE_GLOBAL_MODEL_CACHE_SYSTEM_PROPERTY, Boolean.toString( true ) ); // TODO a similar test should be created to test the dependency management (basically all usages @@ -179,6 +189,7 @@ public class ProjectBuilderTest } } + @Test public void testReadErroneousMavenProjectContainsReference() throws Exception { @@ -212,6 +223,7 @@ public class ProjectBuilderTest assertEquals( pomFile, project2.getFile() ); } + @Test public void testReadInvalidPom() throws Exception { @@ -237,6 +249,7 @@ public class ProjectBuilderTest assertThat( pex.getMessage(), containsString( "expected START_TAG or END_TAG not TEXT" ) ); } + @Test public void testReadParentAndChildWithRegularVersionSetParentFile() throws Exception { @@ -297,6 +310,7 @@ public class ProjectBuilderTest } } + @Test public void testBuildProperties() throws Exception { @@ -314,6 +328,7 @@ public class ProjectBuilderTest assertEquals( 1, project.getResources().size() ); } + @Test public void testPropertyInPluginManagementGroupId() throws Exception { diff --git a/maven-core/src/test/java/org/apache/maven/project/ProjectModelResolverTest.java b/maven-core/src/test/java/org/apache/maven/project/ProjectModelResolverTest.java index fb1c642382..4c1dcf4427 100644 --- a/maven-core/src/test/java/org/apache/maven/project/ProjectModelResolverTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/ProjectModelResolverTest.java @@ -19,9 +19,6 @@ package org.apache.maven.project; * under the License. */ -import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.assertThat; - import java.io.File; import java.util.Collections; import java.util.List; @@ -36,6 +33,13 @@ import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.impl.RemoteRepositoryManager; import org.eclipse.aether.repository.RemoteRepository; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.Matchers.startsWith; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * Test cases for the project {@code ModelResolver} implementation. @@ -54,6 +58,7 @@ public class ProjectModelResolverTest extends AbstractMavenProjectTestCase super(); } + @Test public void testResolveParentThrowsUnresolvableModelExceptionWhenNotFound() throws Exception { final Parent parent = new Parent(); @@ -61,18 +66,15 @@ public class ProjectModelResolverTest extends AbstractMavenProjectTestCase parent.setArtifactId( "apache" ); parent.setVersion( "0" ); - try - { - this.newModelResolver().resolveModel( parent ); - fail( "Expected 'UnresolvableModelException' not thrown." ); - } - catch ( final UnresolvableModelException e ) - { - assertNotNull( e.getMessage() ); - assertThat( e.getMessage(), startsWith( "Could not find artifact org.apache:apache:pom:0 in central" ) ); - } + UnresolvableModelException e = assertThrows( + UnresolvableModelException.class, + () -> newModelResolver().resolveModel( parent ), + "Expected 'UnresolvableModelException' not thrown." ); + assertNotNull( e.getMessage() ); + assertThat( e.getMessage(), startsWith( "Could not find artifact org.apache:apache:pom:0 in central" ) ); } + @Test public void testResolveParentThrowsUnresolvableModelExceptionWhenNoMatchingVersionFound() throws Exception { final Parent parent = new Parent(); @@ -80,19 +82,15 @@ public class ProjectModelResolverTest extends AbstractMavenProjectTestCase parent.setArtifactId( "apache" ); parent.setVersion( "[2.0,2.1)" ); - try - { - this.newModelResolver().resolveModel( parent ); - fail( "Expected 'UnresolvableModelException' not thrown." ); - } - catch ( final UnresolvableModelException e ) - { - assertEquals( "No versions matched the requested parent version range '[2.0,2.1)'", - e.getMessage() ); - - } + UnresolvableModelException e = assertThrows( + UnresolvableModelException.class, + () -> newModelResolver().resolveModel( parent ), + "Expected 'UnresolvableModelException' not thrown." ); + assertEquals( "No versions matched the requested parent version range '[2.0,2.1)'", + e.getMessage() ); } + @Test public void testResolveParentThrowsUnresolvableModelExceptionWhenUsingRangesWithoutUpperBound() throws Exception { final Parent parent = new Parent(); @@ -100,19 +98,15 @@ public class ProjectModelResolverTest extends AbstractMavenProjectTestCase parent.setArtifactId( "apache" ); parent.setVersion( "[1,)" ); - try - { - this.newModelResolver().resolveModel( parent ); - fail( "Expected 'UnresolvableModelException' not thrown." ); - } - catch ( final UnresolvableModelException e ) - { - assertEquals( "The requested parent version range '[1,)' does not specify an upper bound", - e.getMessage() ); - - } + UnresolvableModelException e = assertThrows( + UnresolvableModelException.class, + () -> newModelResolver().resolveModel( parent ), + "Expected 'UnresolvableModelException' not thrown." ); + assertEquals( "The requested parent version range '[1,)' does not specify an upper bound", + e.getMessage() ); } + @Test public void testResolveParentSuccessfullyResolvesExistingParentWithoutRange() throws Exception { final Parent parent = new Parent(); @@ -124,6 +118,7 @@ public class ProjectModelResolverTest extends AbstractMavenProjectTestCase assertEquals( "1", parent.getVersion() ); } + @Test public void testResolveParentSuccessfullyResolvesExistingParentUsingHighestVersion() throws Exception { final Parent parent = new Parent(); @@ -135,6 +130,7 @@ public class ProjectModelResolverTest extends AbstractMavenProjectTestCase assertEquals( "1", parent.getVersion() ); } + @Test public void testResolveDependencyThrowsUnresolvableModelExceptionWhenNotFound() throws Exception { final Dependency dependency = new Dependency(); @@ -142,18 +138,15 @@ public class ProjectModelResolverTest extends AbstractMavenProjectTestCase dependency.setArtifactId( "apache" ); dependency.setVersion( "0" ); - try - { - this.newModelResolver().resolveModel( dependency ); - fail( "Expected 'UnresolvableModelException' not thrown." ); - } - catch ( final UnresolvableModelException e ) - { - assertNotNull( e.getMessage() ); - assertThat( e.getMessage(), startsWith( "Could not find artifact org.apache:apache:pom:0 in central" ) ); - } + UnresolvableModelException e = assertThrows( + UnresolvableModelException.class, + () -> newModelResolver().resolveModel( dependency ), + "Expected 'UnresolvableModelException' not thrown." ); + assertNotNull( e.getMessage() ); + assertThat( e.getMessage(), startsWith( "Could not find artifact org.apache:apache:pom:0 in central" ) ); } + @Test public void testResolveDependencyThrowsUnresolvableModelExceptionWhenNoMatchingVersionFound() throws Exception { final Dependency dependency = new Dependency(); @@ -161,19 +154,15 @@ public class ProjectModelResolverTest extends AbstractMavenProjectTestCase dependency.setArtifactId( "apache" ); dependency.setVersion( "[2.0,2.1)" ); - try - { - this.newModelResolver().resolveModel( dependency ); - fail( "Expected 'UnresolvableModelException' not thrown." ); - } - catch ( final UnresolvableModelException e ) - { - assertEquals( "No versions matched the requested dependency version range '[2.0,2.1)'", - e.getMessage() ); - - } + UnresolvableModelException e = assertThrows( + UnresolvableModelException.class, + () -> newModelResolver().resolveModel( dependency ), + "Expected 'UnresolvableModelException' not thrown." ); + assertEquals( "No versions matched the requested dependency version range '[2.0,2.1)'", + e.getMessage() ); } + @Test public void testResolveDependencyThrowsUnresolvableModelExceptionWhenUsingRangesWithoutUpperBound() throws Exception { final Dependency dependency = new Dependency(); @@ -181,19 +170,15 @@ public class ProjectModelResolverTest extends AbstractMavenProjectTestCase dependency.setArtifactId( "apache" ); dependency.setVersion( "[1,)" ); - try - { - this.newModelResolver().resolveModel( dependency ); - fail( "Expected 'UnresolvableModelException' not thrown." ); - } - catch ( final UnresolvableModelException e ) - { - assertEquals( "The requested dependency version range '[1,)' does not specify an upper bound", - e.getMessage() ); - - } + UnresolvableModelException e = assertThrows( + UnresolvableModelException.class, + () -> newModelResolver().resolveModel( dependency ), + "Expected 'UnresolvableModelException' not thrown." ); + assertEquals( "The requested dependency version range '[1,)' does not specify an upper bound", + e.getMessage() ); } + @Test public void testResolveDependencySuccessfullyResolvesExistingDependencyWithoutRange() throws Exception { final Dependency dependency = new Dependency(); @@ -205,6 +190,7 @@ public class ProjectModelResolverTest extends AbstractMavenProjectTestCase assertEquals( "1", dependency.getVersion() ); } + @Test public void testResolveDependencySuccessfullyResolvesExistingDependencyUsingHighestVersion() throws Exception { final Dependency dependency = new Dependency(); diff --git a/maven-core/src/test/java/org/apache/maven/project/ProjectSorterTest.java b/maven-core/src/test/java/org/apache/maven/project/ProjectSorterTest.java index 1ca124f130..ec15951059 100644 --- a/maven-core/src/test/java/org/apache/maven/project/ProjectSorterTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/ProjectSorterTest.java @@ -20,8 +20,9 @@ package org.apache.maven.project; */ import static org.hamcrest.Matchers.hasItem; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.ArrayList; import java.util.Collections; @@ -34,9 +35,7 @@ import org.apache.maven.model.Model; import org.apache.maven.model.Parent; import org.apache.maven.model.Plugin; import org.apache.maven.model.PluginManagement; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; /** * Test sorting projects by dependencies. @@ -45,9 +44,6 @@ import org.junit.rules.ExpectedException; */ public class ProjectSorterTest { - @Rule - public ExpectedException expectedException = ExpectedException.none(); - private Parent createParent( MavenProject project ) { return createParent( project.getGroupId(), project.getArtifactId(), project.getVersion() ); @@ -210,10 +206,10 @@ public class ProjectSorterTest MavenProject project2 = createProject( "groupId", "artifactId", "1.0" ); projects.add( project2 ); - expectedException.expect( DuplicateProjectException.class ); - expectedException.reportMissingExceptionWithMessage( "Duplicate projects should fail" ); - - new ProjectSorter( projects ).getSortedProjects(); + assertThrows( + DuplicateProjectException.class, + () -> new ProjectSorter( projects ).getSortedProjects(), + "Duplicate projects should fail" ); } @Test diff --git a/maven-core/src/test/java/org/apache/maven/project/artifact/DefaultMavenMetadataCacheTest.java b/maven-core/src/test/java/org/apache/maven/project/artifact/DefaultMavenMetadataCacheTest.java index c039934692..2d5c1baa7f 100644 --- a/maven-core/src/test/java/org/apache/maven/project/artifact/DefaultMavenMetadataCacheTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/artifact/DefaultMavenMetadataCacheTest.java @@ -29,32 +29,35 @@ import org.apache.maven.project.artifact.DefaultMavenMetadataCache.CacheKey; import org.apache.maven.repository.DelegatingLocalArtifactRepository; import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.TestRepositorySystem; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.BeforeEach; -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; /** * @author Igor Fedorenko */ public class DefaultMavenMetadataCacheTest - extends TestCase { private RepositorySystem repositorySystem; - protected void setUp() + @BeforeEach + public void setUp() throws Exception { - super.setUp(); repositorySystem = new TestRepositorySystem( null, null ); } - @Override - protected void tearDown() + @AfterEach + public void tearDown() throws Exception { repositorySystem = null; - super.tearDown(); } + @Test public void testCacheKey() throws Exception { diff --git a/maven-core/src/test/java/org/apache/maven/project/artifact/DefaultProjectArtifactsCacheTest.java b/maven-core/src/test/java/org/apache/maven/project/artifact/DefaultProjectArtifactsCacheTest.java index cbe4b35865..16317ff62e 100644 --- a/maven-core/src/test/java/org/apache/maven/project/artifact/DefaultProjectArtifactsCacheTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/artifact/DefaultProjectArtifactsCacheTest.java @@ -19,29 +19,28 @@ package org.apache.maven.project.artifact; * under the License. */ -import static org.junit.Assert.assertArrayEquals; - import java.util.LinkedHashSet; import java.util.Set; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DefaultArtifact; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import junit.framework.TestCase; - -public class DefaultProjectArtifactsCacheTest extends TestCase +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +public class DefaultProjectArtifactsCacheTest { private ProjectArtifactsCache cache; - @Override - protected void setUp() + @BeforeEach + public void setUp() throws Exception { - super.setUp(); cache = new DefaultProjectArtifactsCache(); } + @Test public void testProjectDependencyOrder() throws Exception { ProjectArtifactsCache.Key project1 = new ProjectArtifactsCache.Key(){}; diff --git a/maven-core/src/test/java/org/apache/maven/project/artifact/MavenMetadataSourceTest.java b/maven-core/src/test/java/org/apache/maven/project/artifact/MavenMetadataSourceTest.java index beaa1493a5..a69af5e4ad 100644 --- a/maven-core/src/test/java/org/apache/maven/project/artifact/MavenMetadataSourceTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/artifact/MavenMetadataSourceTest.java @@ -19,45 +19,23 @@ package org.apache.maven.project.artifact; * under the License. */ +import org.apache.maven.test.PlexusTestCase; import org.apache.maven.repository.RepositorySystem; -import org.codehaus.plexus.DefaultPlexusContainer; -import org.codehaus.plexus.PlexusTestCase; -import org.junit.Ignore; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import javax.inject.Inject; -import java.util.Collections; -@Ignore +@Disabled public class MavenMetadataSourceTest extends PlexusTestCase { @Inject private RepositorySystem repositorySystem; - @Override - protected synchronized void setupContainer() - { - super.setupContainer(); - - ( (DefaultPlexusContainer) getContainer() ).addPlexusInjector( Collections.emptyList(), - binder -> binder.requestInjection( this ) ); - } - - @Override - protected void setUp() throws Exception - { - super.setUp(); - getContainer(); - } - - @Override - protected void tearDown() - throws Exception - { - repositorySystem = null; - super.tearDown(); - } - + @Test public void testShouldNotCarryExclusionsOverFromDependencyToDependency() throws Exception { @@ -132,18 +110,19 @@ public class MavenMetadataSourceTest Map artifactMap = project.getArtifactMap(); - assertNotNull( "artifact-map should not be null.", artifactMap ); + assertNotNull( artifactMap, "artifact-map should not be null." ); assertEquals( "artifact-map should contain 1 element.", 1, artifactMap.size() ); Artifact artifact = (Artifact) artifactMap.get( key ); - assertNotNull( "dependency artifact not found in map.", artifact ); + assertNotNull( artifact, "dependency artifact not found in map." ); assertEquals( "dependency artifact has wrong scope.", Artifact.SCOPE_COMPILE, artifact.getScope() ); //check for back-propagation of default scope. assertEquals( "default scope NOT back-propagated to dependency.", Artifact.SCOPE_COMPILE, dep.getScope() ); } + @Test public void testShouldUseInjectedTestScopeFromDependencyManagement() throws Exception { @@ -183,12 +162,12 @@ public class MavenMetadataSourceTest Map artifactMap = project.getArtifactMap(); - assertNotNull( "artifact-map should not be null.", artifactMap ); + assertNotNull( artifactMap, "artifact-map should not be null." ); assertEquals( "artifact-map should contain 1 element.", 1, artifactMap.size() ); Artifact artifact = (Artifact) artifactMap.get( key ); - assertNotNull( "dependency artifact not found in map.", artifact ); + assertNotNull( artifact, "dependency artifact not found in map." ); assertEquals( "dependency artifact has wrong scope.", Artifact.SCOPE_TEST, artifact.getScope() ); //check for back-propagation of default scope. diff --git a/maven-core/src/test/java/org/apache/maven/project/canonical/CanonicalProjectBuilderTest.java b/maven-core/src/test/java/org/apache/maven/project/canonical/CanonicalProjectBuilderTest.java index 8b6454da11..f966237c33 100644 --- a/maven-core/src/test/java/org/apache/maven/project/canonical/CanonicalProjectBuilderTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/canonical/CanonicalProjectBuilderTest.java @@ -27,6 +27,10 @@ import org.apache.maven.model.PluginExecution; import org.apache.maven.project.AbstractMavenProjectTestCase; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * @author Jason van Zyl @@ -34,6 +38,7 @@ import org.codehaus.plexus.util.xml.Xpp3Dom; public class CanonicalProjectBuilderTest extends AbstractMavenProjectTestCase { + @Test public void testProjectBuilder() throws Exception { diff --git a/maven-core/src/test/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformationTest.java b/maven-core/src/test/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformationTest.java index 9e5d6eaadb..46487377c1 100644 --- a/maven-core/src/test/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformationTest.java +++ b/maven-core/src/test/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformationTest.java @@ -21,12 +21,17 @@ package org.apache.maven.rtinfo.internal; import org.apache.maven.rtinfo.RuntimeInformation; import org.codehaus.plexus.ContainerConfiguration; -import org.codehaus.plexus.DefaultPlexusContainer; import org.codehaus.plexus.PlexusConstants; -import org.codehaus.plexus.PlexusTestCase; +import org.apache.maven.test.PlexusTestCase; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import javax.inject.Inject; -import java.util.Collections; public class DefaultRuntimeInformationTest extends PlexusTestCase @@ -43,21 +48,7 @@ public class DefaultRuntimeInformationTest configuration.setClassPathScanning(PlexusConstants.SCANNING_INDEX); } - @Override - protected void setUp() throws Exception - { - super.setUp(); - getContainer(); - } - @Override - protected synchronized void setupContainer() - { - super.setupContainer(); - - ( (DefaultPlexusContainer) getContainer() ).addPlexusInjector( Collections.emptyList(), - binder -> binder.requestInjection( this ) ); - } - + @Test public void testGetMavenVersion() { String mavenVersion = rtInfo.getMavenVersion(); @@ -65,6 +56,7 @@ public class DefaultRuntimeInformationTest assertTrue( mavenVersion.length() > 0 ); } + @Test public void testIsMavenVersion() { assertTrue( rtInfo.isMavenVersion( "2.0" ) ); @@ -73,35 +65,20 @@ public class DefaultRuntimeInformationTest assertTrue( rtInfo.isMavenVersion( "[2.0.11,2.1.0),[3.0,)" ) ); assertFalse( rtInfo.isMavenVersion( "[9.0,)" ) ); - try - { - rtInfo.isMavenVersion( "[3.0," ); - fail( "Bad version range wasn't rejected" ); - } - catch ( IllegalArgumentException e ) - { - assertTrue( true ); - } + assertThrows( + IllegalArgumentException.class, + () -> rtInfo.isMavenVersion( "[3.0," ), + "Bad version range wasn't rejected" ); - try - { - rtInfo.isMavenVersion( "" ); - fail( "Bad version range wasn't rejected" ); - } - catch ( IllegalArgumentException e ) - { - assertTrue( true ); - } + assertThrows( + IllegalArgumentException.class, + () -> rtInfo.isMavenVersion( "" ), + "Bad version range wasn't rejected" ); - try - { - rtInfo.isMavenVersion( null ); - fail( "Bad version range wasn't rejected" ); - } - catch ( NullPointerException e ) - { - assertTrue( true ); - } + assertThrows( + NullPointerException.class, + () -> rtInfo.isMavenVersion( null ), + "Bad version range wasn't rejected" ); } } diff --git a/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java b/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java index 4d66b0fe49..b9c9734d36 100644 --- a/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java +++ b/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java @@ -19,6 +19,10 @@ package org.apache.maven.settings; * under the License. */ +import java.io.File; +import java.io.IOException; +import java.io.Reader; + import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; import org.apache.maven.model.Profile; import org.apache.maven.project.DefaultProjectBuilder; @@ -28,21 +32,18 @@ import org.apache.maven.project.harness.PomTestWrapper; import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.internal.MavenRepositorySystemUtils; import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader; -import org.codehaus.plexus.ContainerConfiguration; -import org.codehaus.plexus.DefaultPlexusContainer; -import org.codehaus.plexus.PlexusConstants; -import org.codehaus.plexus.PlexusTestCase; +import org.apache.maven.test.PlexusTestCase; import org.codehaus.plexus.util.ReaderFactory; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; import org.eclipse.aether.repository.LocalRepository; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import javax.inject.Inject; -import java.io.File; -import java.io.IOException; -import java.io.Reader; -import java.util.Collections; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class PomConstructionWithSettingsTest extends PlexusTestCase @@ -59,39 +60,15 @@ public class PomConstructionWithSettingsTest private File testDirectory; - @Override - protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration ) - { - super.customizeContainerConfiguration( containerConfiguration ); - containerConfiguration.setAutoWiring( true ); - containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); - } - - @Override - protected synchronized void setupContainer() - { - super.setupContainer(); - - ( (DefaultPlexusContainer) getContainer() ).addPlexusInjector( Collections.emptyList(), - binder -> binder.requestInjection( this ) ); - } - - protected void setUp() + @BeforeEach + public void setUp() throws Exception { - getContainer(); + super.setUp(); testDirectory = new File( getBasedir(), BASE_POM_DIR ); } - @Override - protected void tearDown() - throws Exception - { - projectBuilder = null; - - super.tearDown(); - } - + @Test public void testSettingsNoPom() throws Exception { @@ -102,6 +79,7 @@ public class PomConstructionWithSettingsTest /** * MNG-4107 */ + @Test public void testPomAndSettingsInterpolation() throws Exception { @@ -115,6 +93,7 @@ public class PomConstructionWithSettingsTest /** * MNG-4107 */ + @Test public void testRepositories() throws Exception { diff --git a/maven-core/src/test/java/org/apache/maven/settings/SettingsUtilsTest.java b/maven-core/src/test/java/org/apache/maven/settings/SettingsUtilsTest.java index 78818c5750..6943c34238 100644 --- a/maven-core/src/test/java/org/apache/maven/settings/SettingsUtilsTest.java +++ b/maven-core/src/test/java/org/apache/maven/settings/SettingsUtilsTest.java @@ -19,17 +19,20 @@ package org.apache.maven.settings; * under the License. */ -import junit.framework.TestCase; - import java.util.ArrayList; import java.util.List; import java.util.Properties; import java.util.Random; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + public class SettingsUtilsTest - extends TestCase { + @Test public void testShouldAppendRecessivePluginGroupIds() { Settings dominant = new Settings(); @@ -50,6 +53,7 @@ public class SettingsUtilsTest assertEquals( "org.codehaus.plexus", pluginGroups.get( 2 ) ); } + @Test public void testRoundTripProfiles() { Random entropy = new Random(); diff --git a/maven-core/src/test/java/org/apache/maven/toolchain/DefaultToolchainManagerPrivateTest.java b/maven-core/src/test/java/org/apache/maven/toolchain/DefaultToolchainManagerPrivateTest.java index 896b59c327..523645f187 100644 --- a/maven-core/src/test/java/org/apache/maven/toolchain/DefaultToolchainManagerPrivateTest.java +++ b/maven-core/src/test/java/org/apache/maven/toolchain/DefaultToolchainManagerPrivateTest.java @@ -19,7 +19,7 @@ package org.apache.maven.toolchain; * under the License. */ -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -36,8 +36,8 @@ import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenSession; import org.apache.maven.toolchain.model.ToolchainModel; import org.codehaus.plexus.logging.Logger; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -57,7 +57,7 @@ public class DefaultToolchainManagerPrivateTest @Mock private ToolchainFactory toolchainFactory_rareType; - @Before + @BeforeEach public void setUp() { toolchainManager = new DefaultToolchainManagerPrivate(); diff --git a/maven-core/src/test/java/org/apache/maven/toolchain/DefaultToolchainManagerTest.java b/maven-core/src/test/java/org/apache/maven/toolchain/DefaultToolchainManagerTest.java index 84444c08ed..c5b808ffa8 100644 --- a/maven-core/src/test/java/org/apache/maven/toolchain/DefaultToolchainManagerTest.java +++ b/maven-core/src/test/java/org/apache/maven/toolchain/DefaultToolchainManagerTest.java @@ -19,7 +19,7 @@ package org.apache.maven.toolchain; * under the License. */ -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Matchers.isA; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -36,8 +36,8 @@ import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenSession; import org.apache.maven.toolchain.model.ToolchainModel; import org.codehaus.plexus.logging.Logger; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; import org.mockito.Mock; @@ -58,7 +58,7 @@ public class DefaultToolchainManagerTest @Mock private ToolchainFactory toolchainFactory_rareType; - @Before + @BeforeEach public void onSetup() throws Exception { toolchainManager = new DefaultToolchainManager(); diff --git a/maven-core/src/test/java/org/apache/maven/toolchain/DefaultToolchainTest.java b/maven-core/src/test/java/org/apache/maven/toolchain/DefaultToolchainTest.java index 3b75455851..a5d14b29f7 100644 --- a/maven-core/src/test/java/org/apache/maven/toolchain/DefaultToolchainTest.java +++ b/maven-core/src/test/java/org/apache/maven/toolchain/DefaultToolchainTest.java @@ -19,9 +19,9 @@ package org.apache.maven.toolchain; * under the License. */ -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.mockito.Mockito.verify; import java.io.InputStream; @@ -32,8 +32,8 @@ import org.apache.maven.toolchain.model.PersistedToolchains; import org.apache.maven.toolchain.model.ToolchainModel; import org.apache.maven.toolchain.model.io.xpp3.MavenToolchainsXpp3Reader; import org.codehaus.plexus.logging.Logger; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -44,7 +44,7 @@ public class DefaultToolchainTest private MavenToolchainsXpp3Reader reader = new MavenToolchainsXpp3Reader(); - @Before + @BeforeEach public void setUp() throws Exception { diff --git a/maven-core/src/test/java/org/apache/maven/toolchain/RequirementMatcherFactoryTest.java b/maven-core/src/test/java/org/apache/maven/toolchain/RequirementMatcherFactoryTest.java index c102b11f81..6c167b13ad 100644 --- a/maven-core/src/test/java/org/apache/maven/toolchain/RequirementMatcherFactoryTest.java +++ b/maven-core/src/test/java/org/apache/maven/toolchain/RequirementMatcherFactoryTest.java @@ -19,24 +19,23 @@ package org.apache.maven.toolchain; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * * @author mkleint */ public class RequirementMatcherFactoryTest - extends TestCase { - public RequirementMatcherFactoryTest( String testName ) - { - super( testName ); - } - /** * Test of createExactMatcher method, of class RequirementMatcherFactory. */ + @Test public void testCreateExactMatcher() { RequirementMatcher matcher; @@ -50,6 +49,7 @@ public class RequirementMatcherFactoryTest /** * Test of createVersionMatcher method, of class RequirementMatcherFactory. */ + @Test public void testCreateVersionMatcher() { RequirementMatcher matcher; diff --git a/maven-core/src/test/java/org/apache/maven/toolchain/building/DefaultToolchainsBuilderTest.java b/maven-core/src/test/java/org/apache/maven/toolchain/building/DefaultToolchainsBuilderTest.java index f04d24876b..94c15b80eb 100644 --- a/maven-core/src/test/java/org/apache/maven/toolchain/building/DefaultToolchainsBuilderTest.java +++ b/maven-core/src/test/java/org/apache/maven/toolchain/building/DefaultToolchainsBuilderTest.java @@ -27,8 +27,8 @@ import org.apache.maven.toolchain.model.PersistedToolchains; import org.apache.maven.toolchain.model.ToolchainModel; import org.codehaus.plexus.interpolation.os.OperatingSystemUtils; import org.codehaus.plexus.util.xml.Xpp3Dom; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.BeforeEach; import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; import org.mockito.MockitoAnnotations; @@ -39,8 +39,8 @@ import java.io.InputStream; import java.util.HashMap; import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; @@ -58,7 +58,7 @@ public class DefaultToolchainsBuilderTest @InjectMocks private DefaultToolchainsBuilder toolchainBuilder; - @Before + @BeforeEach public void onSetup() { MockitoAnnotations.initMocks( this ); diff --git a/maven-core/src/test/java/org/apache/maven/toolchain/building/ToolchainsBuildingExceptionTest.java b/maven-core/src/test/java/org/apache/maven/toolchain/building/ToolchainsBuildingExceptionTest.java index 0efda4d365..8189268b4d 100644 --- a/maven-core/src/test/java/org/apache/maven/toolchain/building/ToolchainsBuildingExceptionTest.java +++ b/maven-core/src/test/java/org/apache/maven/toolchain/building/ToolchainsBuildingExceptionTest.java @@ -19,14 +19,14 @@ package org.apache.maven.toolchain.building; * under the License. */ -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Collections; import org.apache.maven.building.Problem; import org.apache.maven.building.ProblemCollector; import org.apache.maven.building.ProblemCollectorFactory; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ToolchainsBuildingExceptionTest { diff --git a/maven-core/src/test/java/org/apache/maven/toolchain/merge/MavenToolchainMergerTest.java b/maven-core/src/test/java/org/apache/maven/toolchain/merge/MavenToolchainMergerTest.java index 5ad762a4e6..7bed9a909a 100644 --- a/maven-core/src/test/java/org/apache/maven/toolchain/merge/MavenToolchainMergerTest.java +++ b/maven-core/src/test/java/org/apache/maven/toolchain/merge/MavenToolchainMergerTest.java @@ -24,11 +24,11 @@ import org.apache.maven.toolchain.model.ToolchainModel; import org.apache.maven.toolchain.model.TrackableBase; import org.apache.maven.toolchain.model.io.xpp3.MavenToolchainsXpp3Reader; import org.codehaus.plexus.util.xml.Xpp3Dom; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.InputStream; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class MavenToolchainMergerTest { diff --git a/maven-embedder/src/test/java/org/apache/maven/cli/CLIManagerDocumentationTest.java b/maven-embedder/src/test/java/org/apache/maven/cli/CLIManagerDocumentationTest.java index 2c82a72e23..bc945fd3d9 100644 --- a/maven-embedder/src/test/java/org/apache/maven/cli/CLIManagerDocumentationTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/cli/CLIManagerDocumentationTest.java @@ -29,15 +29,13 @@ import java.util.List; import org.apache.commons.cli.Option; import org.codehaus.plexus.util.FileUtils; - -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; /** * Pseudo test to generate documentation fragment about supported CLI options. TODO such documentation generation code * should not be necessary as unit test but should be run during site generation (Velocity? Doxia macro?) */ public class CLIManagerDocumentationTest - extends TestCase { private final static String LS = System.lineSeparator(); @@ -98,6 +96,7 @@ public class CLIManagerDocumentationTest return sb.toString(); } + @Test public void testOptionsAsHtml() throws IOException { diff --git a/maven-embedder/src/test/java/org/apache/maven/cli/CLIManagerTest.java b/maven-embedder/src/test/java/org/apache/maven/cli/CLIManagerTest.java index dbb38798e1..a3aad6bbb5 100644 --- a/maven-embedder/src/test/java/org/apache/maven/cli/CLIManagerTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/cli/CLIManagerTest.java @@ -20,18 +20,18 @@ package org.apache.maven.cli; */ import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.apache.commons.cli.CommandLine; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class CLIManagerTest { private CLIManager cliManager; - @Before + @BeforeEach public void setup() { cliManager = new CLIManager(); diff --git a/maven-embedder/src/test/java/org/apache/maven/cli/CLIReportingUtilsTest.java b/maven-embedder/src/test/java/org/apache/maven/cli/CLIReportingUtilsTest.java index 65488c7c1e..ac0cb30943 100644 --- a/maven-embedder/src/test/java/org/apache/maven/cli/CLIReportingUtilsTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/cli/CLIReportingUtilsTest.java @@ -19,12 +19,14 @@ package org.apache.maven.cli; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class CLIReportingUtilsTest - extends TestCase { + @Test public void testFormatDuration() { assertEquals( "0.001 s", CLIReportingUtils.formatDuration( 1 ) ); diff --git a/maven-embedder/src/test/java/org/apache/maven/cli/CleanArgumentTest.java b/maven-embedder/src/test/java/org/apache/maven/cli/CleanArgumentTest.java index 7e2b489fe9..1624be1a28 100644 --- a/maven-embedder/src/test/java/org/apache/maven/cli/CleanArgumentTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/cli/CleanArgumentTest.java @@ -19,9 +19,9 @@ package org.apache.maven.cli; * under the License. */ -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Karl Heinz Marbaise diff --git a/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java b/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java index 491fb0b9ce..c7a41a5e2a 100644 --- a/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java @@ -26,11 +26,11 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.junit.Assume.assumeTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assumptions.assumeTrue; import static org.mockito.ArgumentMatchers.any; import static org.hamcrest.collection.IsIterableContainingInOrder.contains; import static org.mockito.Mockito.inOrder; @@ -55,30 +55,25 @@ import org.apache.maven.toolchain.building.ToolchainsBuildingRequest; import org.apache.maven.toolchain.building.ToolchainsBuildingResult; import org.codehaus.plexus.DefaultPlexusContainer; import org.codehaus.plexus.PlexusContainer; -import org.eclipse.sisu.plexus.PlexusBeanModule; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.InOrder; -import com.google.inject.Binder; -import com.google.inject.Module; - public class MavenCliTest { private MavenCli cli; private String origBasedir; - @Before + @BeforeEach public void setUp() { cli = new MavenCli(); origBasedir = System.getProperty( MavenCli.MULTIMODULE_PROJECT_DIRECTORY ); } - @After + @AfterEach public void tearDown() throws Exception { @@ -149,15 +144,10 @@ public class MavenCliTest // -TC2.2 assertEquals( (int) ( cores * 2.2 ), cli.calculateDegreeOfConcurrencyWithCoreMultiplier( "2.2C" ) ); - try - { - cli.calculateDegreeOfConcurrencyWithCoreMultiplier( "CXXX" ); - fail( "Should have failed with a NumberFormatException" ); - } - catch ( NumberFormatException e ) - { - // carry on - } + assertThrows( + NumberFormatException.class, + () -> cli.calculateDegreeOfConcurrencyWithCoreMultiplier( "CXXX" ), + "Should have failed with a NumberFormatException" ); } @Test @@ -189,15 +179,7 @@ public class MavenCliTest CliRequest request = new CliRequest( new String[0], null ); cli.initialize( request ); - try - { - cli.cli( request ); - fail(); - } - catch ( ParseException expected ) - { - - } + assertThrows( ParseException.class, () -> cli.cli( request ) ); } /** @@ -321,7 +303,7 @@ public class MavenCliTest public void testStyleColors() throws Exception { - assumeTrue( "ANSI not supported", MessageUtils.isColorEnabled() ); + assumeTrue( MessageUtils.isColorEnabled(), "ANSI not supported" ); CliRequest request; MessageUtils.setColorEnabled( true ); @@ -359,19 +341,14 @@ public class MavenCliTest cli.logging( request ); assertTrue( MessageUtils.isColorEnabled() ); - try - { - MessageUtils.setColorEnabled( false ); - request = new CliRequest( new String[] { "-Dstyle.color=maybe", "-B", "-l", "target/temp/mvn.log" }, null ); - cli.cli( request ); - cli.properties( request ); - cli.logging( request ); - fail( "maybe is not a valid option" ); - } - catch ( IllegalArgumentException e ) - { - // noop - } + MessageUtils.setColorEnabled( false ); + CliRequest maybeColorRequest = new CliRequest( new String[] { "-Dstyle.color=maybe", "-B", "-l", "target/temp/mvn.log" }, null ); + cli.cli( maybeColorRequest ); + cli.properties( maybeColorRequest ); + assertThrows( + IllegalArgumentException.class, + () -> cli.logging( maybeColorRequest ), + "maybe is not a valid option" ); } /** diff --git a/maven-embedder/src/test/java/org/apache/maven/cli/event/ExecutionEventLoggerTest.java b/maven-embedder/src/test/java/org/apache/maven/cli/event/ExecutionEventLoggerTest.java index 3abb872f60..d374b249de 100644 --- a/maven-embedder/src/test/java/org/apache/maven/cli/event/ExecutionEventLoggerTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/cli/event/ExecutionEventLoggerTest.java @@ -26,9 +26,9 @@ import static org.mockito.Mockito.when; import org.apache.maven.execution.ExecutionEvent; import org.apache.maven.project.MavenProject; import org.apache.maven.shared.utils.logging.MessageUtils; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.mockito.InOrder; import org.slf4j.Logger; @@ -36,13 +36,13 @@ public class ExecutionEventLoggerTest { private ExecutionEventLogger executionEventLogger; - @BeforeClass + @BeforeAll public static void setUp() { MessageUtils.setColorEnabled( false ); } - @AfterClass + @AfterAll public static void tearDown() { MessageUtils.setColorEnabled( true ); diff --git a/maven-embedder/src/test/java/org/apache/maven/cli/transfer/FileSizeFormatTest.java b/maven-embedder/src/test/java/org/apache/maven/cli/transfer/FileSizeFormatTest.java index e595aceb91..5090facdd9 100644 --- a/maven-embedder/src/test/java/org/apache/maven/cli/transfer/FileSizeFormatTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/cli/transfer/FileSizeFormatTest.java @@ -23,19 +23,20 @@ import java.util.Locale; import org.apache.maven.cli.transfer.AbstractMavenTransferListener.FileSizeFormat; import org.apache.maven.cli.transfer.AbstractMavenTransferListener.FileSizeFormat.ScaleUnit; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; public class FileSizeFormatTest { - @Test( expected = IllegalArgumentException.class ) + @Test public void testNegativeSize() { FileSizeFormat format = new FileSizeFormat( Locale.ENGLISH ); long negativeSize = -100L; - format.format( negativeSize ); + assertThrows( IllegalArgumentException.class, () -> format.format( negativeSize ) ); } @Test @@ -209,21 +210,21 @@ public class FileSizeFormatTest { assertEquals( "1.0 GB", format.format( _1000_megabytes, ScaleUnit.GIGABYTE ) ); } - @Test( expected = IllegalArgumentException.class ) + @Test public void testNegativeProgressedSize() { FileSizeFormat format = new FileSizeFormat( Locale.ENGLISH ); long negativeProgressedSize = -100L; - format.formatProgress( negativeProgressedSize, 10L ); + assertThrows( IllegalArgumentException.class, () -> format.formatProgress( negativeProgressedSize, 10L ) ); } - @Test( expected = IllegalArgumentException.class ) + @Test public void testNegativeProgressedSizeBiggerThanSize() { FileSizeFormat format = new FileSizeFormat( Locale.ENGLISH ); - format.formatProgress( 100L, 10L ); + assertThrows( IllegalArgumentException.class, () -> format.formatProgress( 100L, 10L ) ); } @Test diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/building/ComplexActivationTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/building/ComplexActivationTest.java index 9ef31b3db3..1401652d34 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/building/ComplexActivationTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/building/ComplexActivationTest.java @@ -19,16 +19,19 @@ package org.apache.maven.model.building; * under the License. */ -import junit.framework.TestCase; - import java.io.File; import java.util.Properties; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + /** * @author Konstantin Perikov */ public class ComplexActivationTest - extends TestCase { private File getPom( String name ) @@ -36,6 +39,7 @@ public class ComplexActivationTest return new File( "src/test/resources/poms/factory/" + name + ".xml" ).getAbsoluteFile(); } + @Test public void testAndConditionInActivation() throws Exception { diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/building/DefaultModelBuilderFactoryTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/building/DefaultModelBuilderFactoryTest.java index 90b65a4c92..5f12d6b626 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/building/DefaultModelBuilderFactoryTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/building/DefaultModelBuilderFactoryTest.java @@ -22,14 +22,15 @@ package org.apache.maven.model.building; import java.io.File; import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.junit.jupiter.api.Test; -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * @author Benjamin Bentmann */ public class DefaultModelBuilderFactoryTest - extends TestCase { private File getPom( String name ) @@ -37,6 +38,7 @@ public class DefaultModelBuilderFactoryTest return new File( "src/test/resources/poms/factory/" + name + ".xml" ).getAbsoluteFile(); } + @Test public void testCompleteWiring() throws Exception { diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/building/DefaultModelBuilderTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/building/DefaultModelBuilderTest.java index 2b6d53a49b..d61e2aa685 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/building/DefaultModelBuilderTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/building/DefaultModelBuilderTest.java @@ -25,10 +25,10 @@ import org.apache.maven.model.Repository; import org.apache.maven.model.resolution.InvalidRepositoryException; import org.apache.maven.model.resolution.ModelResolver; import org.apache.maven.model.resolution.UnresolvableModelException; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * @author Guillaume Nodet diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/building/FileModelSourceTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/building/FileModelSourceTest.java index 996adf83d8..d4a489c5dd 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/building/FileModelSourceTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/building/FileModelSourceTest.java @@ -18,13 +18,17 @@ package org.apache.maven.model.building; * specific language governing permissions and limitations * under the License. */ + import java.io.File; import java.io.IOException; -import static junit.framework.TestCase.assertFalse; -import static junit.framework.TestCase.assertTrue; + import org.apache.commons.lang3.SystemUtils; -import static org.junit.Assume.assumeTrue; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assumptions.assumeTrue; + /** * Test that validate the solution of MNG-6261 issue diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/building/FileToRawModelMergerTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/building/FileToRawModelMergerTest.java index 9dd3f555b9..9d5301411c 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/building/FileToRawModelMergerTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/building/FileToRawModelMergerTest.java @@ -19,9 +19,6 @@ package org.apache.maven.model.building; * under the License. */ -import static org.hamcrest.Matchers.hasItems; -import static org.junit.Assert.assertThat; - import java.lang.reflect.Method; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; @@ -31,7 +28,10 @@ import java.util.stream.Stream; import org.apache.maven.model.building.DefaultModelBuilder.FileToRawModelMerger; import org.apache.maven.model.merge.ModelMerger; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasItems; public class FileToRawModelMergerTest { diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/building/SimpleProblemCollector.java b/maven-model-builder/src/test/java/org/apache/maven/model/building/SimpleProblemCollector.java index 64e9b3807c..b311d771fd 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/building/SimpleProblemCollector.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/building/SimpleProblemCollector.java @@ -24,7 +24,6 @@ import java.util.List; import org.apache.maven.model.Model; - /** * A simple model problem collector for testing the model building components. * diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/inheritance/DefaultInheritanceAssemblerTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/inheritance/DefaultInheritanceAssemblerTest.java index 2b1eed8127..b36c18475d 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/inheritance/DefaultInheritanceAssemblerTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/inheritance/DefaultInheritanceAssemblerTest.java @@ -19,20 +19,6 @@ package org.apache.maven.model.inheritance; * under the License. */ -import org.apache.maven.model.Model; -import org.apache.maven.model.building.AbstractModelSourceTransformer; -import org.apache.maven.model.building.SimpleProblemCollector; -import org.apache.maven.model.building.TransformerContext; -import org.apache.maven.model.io.DefaultModelReader; -import org.apache.maven.model.io.DefaultModelWriter; -import org.apache.maven.model.io.ModelWriter; -import org.apache.maven.xml.sax.filter.AbstractSAXFilter; -import org.xml.sax.SAXException; -import org.xml.sax.ext.LexicalHandler; -import org.xmlunit.matchers.CompareMatcher; - -import junit.framework.TestCase; - import java.io.File; import java.io.IOException; import java.nio.file.Path; @@ -41,13 +27,29 @@ import java.util.function.Consumer; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.TransformerConfigurationException; +import org.xml.sax.SAXException; +import org.xml.sax.ext.LexicalHandler; + +import org.apache.maven.model.Model; +import org.apache.maven.model.building.AbstractModelSourceTransformer; +import org.apache.maven.model.building.SimpleProblemCollector; +import org.apache.maven.model.building.TransformerContext; +import org.apache.maven.model.io.DefaultModelReader; +import org.apache.maven.model.io.DefaultModelWriter; +import org.apache.maven.model.io.ModelWriter; +import org.apache.maven.xml.sax.filter.AbstractSAXFilter; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.xmlunit.matchers.CompareMatcher; + import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Hervé Boutemy */ public class DefaultInheritanceAssemblerTest - extends TestCase { private DefaultModelReader reader; @@ -55,12 +57,10 @@ public class DefaultInheritanceAssemblerTest private InheritanceAssembler assembler; - @Override - protected void setUp() + @BeforeEach + public void setUp() throws Exception { - super.setUp(); - reader = new DefaultModelReader(); reader.setTransformer( new AbstractModelSourceTransformer() { @@ -87,6 +87,7 @@ public class DefaultInheritanceAssemblerTest return reader.read( getPom( name ), null ); } + @Test public void testPluginConfiguration() throws Exception { @@ -98,6 +99,7 @@ public class DefaultInheritanceAssemblerTest * and child directory == artifactId * @throws IOException Model read problem */ + @Test public void testUrls() throws Exception { @@ -108,6 +110,7 @@ public class DefaultInheritanceAssemblerTest * Flat directory structure: parent & child POMs in sibling directories, child directory == artifactId. * @throws IOException Model read problem */ + @Test public void testFlatUrls() throws IOException { @@ -118,6 +121,7 @@ public class DefaultInheritanceAssemblerTest * MNG-5951 MNG-6059 child.x.y.inherit.append.path="false" test * @throws Exception */ + @Test public void testNoAppendUrls() throws Exception { @@ -128,6 +132,7 @@ public class DefaultInheritanceAssemblerTest * MNG-5951 special case test: inherit with partial override * @throws Exception */ + @Test public void testNoAppendUrls2() throws Exception { @@ -138,6 +143,7 @@ public class DefaultInheritanceAssemblerTest * MNG-5951 special case test: child.x.y.inherit.append.path="true" in child should not reset content * @throws Exception */ + @Test public void testNoAppendUrls3() throws Exception { @@ -150,6 +156,7 @@ public class DefaultInheritanceAssemblerTest * This is why MNG-5000 fix in code is marked as bad practice (uses file names) * @throws IOException Model read problem */ + @Test public void testFlatTrickyUrls() throws IOException { @@ -164,10 +171,10 @@ public class DefaultInheritanceAssemblerTest catch ( AssertionError afe ) { // expected failure: wrong relative path calculation - assertTrue( afe.getMessage(), - afe.getMessage().contains( + assertTrue( afe.getMessage().contains( "Expected text value 'http://www.apache.org/path/to/parent/child-artifact-id/' but was " + - "'http://www.apache.org/path/to/parent/../child-artifact-id/'" ) ); + "'http://www.apache.org/path/to/parent/../child-artifact-id/'" ), + afe.getMessage() ); } // but ok from repo: local disk is ignored testInheritance( "tricky-flat-artifactId-urls", true ); @@ -175,20 +182,19 @@ public class DefaultInheritanceAssemblerTest // parent references child with directory name (which is not artifact id) // then relative path calculation will success during build from disk but fail when calculated from repo testInheritance( "tricky-flat-directory-urls", false ); - try - { - testInheritance( "tricky-flat-directory-urls", true ); - fail( "should have failed since module reference == directory name != artifactId" ); - } - catch ( AssertionError afe ) - { - // expected failure - assertTrue( afe.getMessage(), afe.getMessage().contains( - "Expected text value 'http://www.apache.org/path/to/parent/../child-artifact-id/' but was " + - "'http://www.apache.org/path/to/parent/child-artifact-id/'" ) ); - } + + AssertionError afe = assertThrows( + AssertionError.class, + () -> testInheritance( "tricky-flat-directory-urls", true ), + "should have failed since module reference == directory name != artifactId" ); + // expected failure + assertTrue( afe.getMessage().contains( + "Expected text value 'http://www.apache.org/path/to/parent/../child-artifact-id/' but was " + + "'http://www.apache.org/path/to/parent/child-artifact-id/'" ), + afe.getMessage() ); } + @Test public void testWithEmptyUrl() throws IOException { @@ -232,6 +238,7 @@ public class DefaultInheritanceAssemblerTest assertThat( actual, CompareMatcher.isIdenticalTo( expected ).ignoreComments().ignoreWhitespace() ); } + @Test public void testModulePathNotArtifactId() throws IOException { diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/AbstractModelInterpolatorTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/AbstractModelInterpolatorTest.java index 01cac27310..032ef2827b 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/AbstractModelInterpolatorTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/AbstractModelInterpolatorTest.java @@ -19,6 +19,15 @@ package org.apache.maven.model.interpolation; * under the License. */ +import java.io.File; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.Properties; +import java.util.TimeZone; + import org.apache.maven.model.Build; import org.apache.maven.model.Dependency; import org.apache.maven.model.Model; @@ -29,30 +38,21 @@ import org.apache.maven.model.Scm; import org.apache.maven.model.building.DefaultModelBuildingRequest; import org.apache.maven.model.building.ModelBuildingRequest; import org.apache.maven.model.building.SimpleProblemCollector; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import org.junit.Before; -import org.junit.Test; - -import java.io.File; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.Properties; -import java.util.TimeZone; - -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author jdcasey */ public abstract class AbstractModelInterpolatorTest { - protected ModelInterpolator interpolator; private Properties context; - @Before + @BeforeEach public void setUp() { context = new Properties(); @@ -63,16 +63,16 @@ public abstract class AbstractModelInterpolatorTest protected void assertProblemFree( SimpleProblemCollector collector ) { - assertEquals( "Expected no errors", 0, collector.getErrors().size() ); - assertEquals( "Expected no warnings", 0, collector.getWarnings().size() ); - assertEquals( "Expected no fatals", 0, collector.getFatals().size() ); + assertEquals( 0, collector.getErrors().size(), "Expected no errors" ); + assertEquals( 0, collector.getWarnings().size(), "Expected no warnings" ); + assertEquals( 0, collector.getFatals().size(), "Expected no fatals" ); } protected void assertCollectorState( int numFatals, int numErrors, int numWarnings, SimpleProblemCollector collector ) { - assertEquals( "Errors", numErrors, collector.getErrors().size() ); - assertEquals( "Warnings", numWarnings, collector.getWarnings().size() ); - assertEquals( "Fatals", numFatals, collector.getFatals().size() ); + assertEquals( numErrors, collector.getErrors().size(), "Errors" ); + assertEquals( numWarnings, collector.getWarnings().size(), "Warnings" ); + assertEquals( numFatals, collector.getFatals().size(), "Fatals" ); } private ModelBuildingRequest createModelBuildingRequest( Properties p ) diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/MavenBuildTimestampTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/MavenBuildTimestampTest.java index 8af32fc5b3..73ea3996ba 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/MavenBuildTimestampTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/MavenBuildTimestampTest.java @@ -22,17 +22,19 @@ package org.apache.maven.model.interpolation; import java.util.Date; import java.util.Properties; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertTrue; public class MavenBuildTimestampTest - extends TestCase { + @Test public void testMavenBuildTimestampUsesUTC() { Properties interpolationProperties = new Properties(); interpolationProperties.setProperty( "maven.build.timestamp.format", "yyyyMMdd'T'HHmm'Z'" ); MavenBuildTimestamp timestamp = new MavenBuildTimestamp( new Date(), interpolationProperties ); String formattedTimestamp = timestamp.formattedTimestamp(); - assertTrue( "We expect the UTC marker at the end of the timestamp.", formattedTimestamp.endsWith( "Z" ) ); + assertTrue( formattedTimestamp.endsWith( "Z" ), "We expect the UTC marker at the end of the timestamp." ); } } diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/StringSearchModelInterpolatorTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/StringSearchModelInterpolatorTest.java index dbb72c4f73..d0d71fda9b 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/StringSearchModelInterpolatorTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/StringSearchModelInterpolatorTest.java @@ -19,27 +19,33 @@ package org.apache.maven.model.interpolation; * under the License. */ +import java.io.File; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.concurrent.Callable; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.Future; +import java.util.concurrent.FutureTask; + import org.apache.maven.model.InputLocation; import org.apache.maven.model.InputSource; import org.apache.maven.model.Model; import org.apache.maven.model.building.DefaultModelBuildingRequest; import org.apache.maven.model.building.ModelBuildingRequest; import org.apache.maven.model.building.SimpleProblemCollector; -import org.junit.Test; - -import java.io.File; -import java.lang.reflect.Field; -import java.util.*; -import java.util.concurrent.Callable; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.Future; -import java.util.concurrent.FutureTask; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.anyOf; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * StringSearchModelInterpolatorTest - not in use @@ -51,16 +57,9 @@ import static org.junit.Assert.assertNotNull; public class StringSearchModelInterpolatorTest extends AbstractModelInterpolatorTest { - @Override - public void setUp() - { - super.setUp(); - interpolator = new StringSearchModelInterpolator(); - } - protected ModelInterpolator createInterpolator() { - return this.interpolator; + return new StringSearchModelInterpolator(); } @Test diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/StringVisitorModelInterpolatorTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/StringVisitorModelInterpolatorTest.java index bd201ed780..7c90b07a1b 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/StringVisitorModelInterpolatorTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/StringVisitorModelInterpolatorTest.java @@ -21,15 +21,8 @@ package org.apache.maven.model.interpolation; public class StringVisitorModelInterpolatorTest extends AbstractModelInterpolatorTest { - @Override - public void setUp() - { - super.setUp(); - interpolator = new StringVisitorModelInterpolator(); - } - protected ModelInterpolator createInterpolator() { - return this.interpolator; + return new StringVisitorModelInterpolator(); } } \ No newline at end of file diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/merge/MavenModelMergerTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/merge/MavenModelMergerTest.java index c23be0fdf5..636f3fb571 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/merge/MavenModelMergerTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/merge/MavenModelMergerTest.java @@ -20,15 +20,15 @@ package org.apache.maven.model.merge; * under the License. */ -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - import java.util.Collections; import org.apache.maven.model.Model; import org.apache.maven.model.Prerequisites; import org.apache.maven.model.Profile; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; public class MavenModelMergerTest { diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/path/DefaultUrlNormalizerTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/path/DefaultUrlNormalizerTest.java index 095ff62942..010abe01bf 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/path/DefaultUrlNormalizerTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/path/DefaultUrlNormalizerTest.java @@ -19,10 +19,10 @@ package org.apache.maven.model.path; * under the License. */ -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import org.junit.jupiter.api.Test; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; /** * @author Benjamin Bentmann diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/AbstractProfileActivatorTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/AbstractProfileActivatorTest.java index 5198d04b5f..c665125e9f 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/AbstractProfileActivatorTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/AbstractProfileActivatorTest.java @@ -1,7 +1,5 @@ package org.apache.maven.model.profile.activation; -import java.util.Objects; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -21,14 +19,17 @@ import java.util.Objects; * under the License. */ +import java.util.Objects; import java.util.Properties; import org.apache.maven.model.Profile; import org.apache.maven.model.building.SimpleProblemCollector; import org.apache.maven.model.profile.DefaultProfileActivationContext; import org.apache.maven.model.profile.ProfileActivationContext; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Provides common services to test {@link ProfileActivator} implementations. @@ -36,7 +37,6 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public abstract class AbstractProfileActivatorTest - extends TestCase { private Class activatorClass; @@ -48,22 +48,18 @@ public abstract class AbstractProfileActivatorTest this.activatorClass = Objects.requireNonNull( activatorClass, "activatorClass cannot be null" );; } - @Override - protected void setUp() + @BeforeEach + public void setUp() throws Exception { - super.setUp(); - activator = activatorClass.getConstructor().newInstance(); } - @Override - protected void tearDown() + @AfterEach + public void tearDown() throws Exception { activator = null; - - super.tearDown(); } protected ProfileActivationContext newContext( final Properties userProperties, final Properties systemProperties ) @@ -78,8 +74,8 @@ public abstract class AbstractProfileActivatorTest assertEquals( active, activator.isActive( profile, context, problems ) ); - assertEquals( problems.getErrors().toString(), 0, problems.getErrors().size() ); - assertEquals( problems.getWarnings().toString(), 0, problems.getWarnings().size() ); + assertEquals( 0, problems.getErrors().size(), problems.getErrors().toString() ); + assertEquals( 0, problems.getWarnings().size(), problems.getWarnings().toString() ); } } diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivatorTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivatorTest.java index 440f120bbb..51bd93f27a 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivatorTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivatorTest.java @@ -23,6 +23,7 @@ import java.util.Properties; import org.apache.maven.model.Activation; import org.apache.maven.model.Profile; +import org.junit.jupiter.api.Test; /** * Tests {@link JdkVersionProfileActivator}. @@ -56,6 +57,7 @@ public class JdkVersionProfileActivatorTest return props; } + @Test public void testNullSafe() throws Exception { @@ -68,6 +70,7 @@ public class JdkVersionProfileActivatorTest assertActivation( false, p, newContext( null, null ) ); } + @Test public void testPrefix() throws Exception { @@ -83,6 +86,7 @@ public class JdkVersionProfileActivatorTest assertActivation( false, profile, newContext( null, newProperties( "1.5" ) ) ); } + @Test public void testPrefixNegated() throws Exception { @@ -98,6 +102,7 @@ public class JdkVersionProfileActivatorTest assertActivation( true, profile, newContext( null, newProperties( "1.5" ) ) ); } + @Test public void testVersionRangeInclusiveBounds() throws Exception { @@ -120,6 +125,7 @@ public class JdkVersionProfileActivatorTest assertActivation( true, profile, newContext( null, newProperties( "1.6.0_09-b03" ) ) ); } + @Test public void testVersionRangeExclusiveBounds() throws Exception { @@ -143,6 +149,7 @@ public class JdkVersionProfileActivatorTest assertActivation( false, profile, newContext( null, newProperties( "1.6" ) ) ); } + @Test public void testVersionRangeInclusiveLowerBound() throws Exception { @@ -165,6 +172,7 @@ public class JdkVersionProfileActivatorTest assertActivation( true, profile, newContext( null, newProperties( "1.6.0_09-b03" ) ) ); } + @Test public void testVersionRangeExclusiveUpperBound() throws Exception { diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/PropertyProfileActivatorTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/PropertyProfileActivatorTest.java index 73ab967e53..251ea7d602 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/PropertyProfileActivatorTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/PropertyProfileActivatorTest.java @@ -24,6 +24,7 @@ import java.util.Properties; import org.apache.maven.model.Activation; import org.apache.maven.model.ActivationProperty; import org.apache.maven.model.Profile; +import org.junit.jupiter.api.Test; /** * Tests {@link PropertyProfileActivator}. @@ -61,6 +62,7 @@ public class PropertyProfileActivatorTest return props; } + @Test public void testNullSafe() throws Exception { @@ -73,6 +75,7 @@ public class PropertyProfileActivatorTest assertActivation( false, p, newContext( null, null ) ); } + @Test public void testWithNameOnly_UserProperty() throws Exception { @@ -85,6 +88,7 @@ public class PropertyProfileActivatorTest assertActivation( false, profile, newContext( newProperties( "other", "value" ), null ) ); } + @Test public void testWithNameOnly_SystemProperty() throws Exception { @@ -97,6 +101,7 @@ public class PropertyProfileActivatorTest assertActivation( false, profile, newContext( null, newProperties( "other", "value" ) ) ); } + @Test public void testWithNegatedNameOnly_UserProperty() throws Exception { @@ -109,6 +114,7 @@ public class PropertyProfileActivatorTest assertActivation( true, profile, newContext( newProperties( "other", "value" ), null ) ); } + @Test public void testWithNegatedNameOnly_SystemProperty() throws Exception { @@ -121,6 +127,7 @@ public class PropertyProfileActivatorTest assertActivation( true, profile, newContext( null, newProperties( "other", "value" ) ) ); } + @Test public void testWithValue_UserProperty() throws Exception { @@ -133,6 +140,7 @@ public class PropertyProfileActivatorTest assertActivation( false, profile, newContext( newProperties( "prop", "" ), null ) ); } + @Test public void testWithValue_SystemProperty() throws Exception { @@ -145,6 +153,7 @@ public class PropertyProfileActivatorTest assertActivation( false, profile, newContext( null, newProperties( "other", "" ) ) ); } + @Test public void testWithNegatedValue_UserProperty() throws Exception { @@ -157,6 +166,7 @@ public class PropertyProfileActivatorTest assertActivation( true, profile, newContext( newProperties( "prop", "" ), null ) ); } + @Test public void testWithNegatedValue_SystemProperty() throws Exception { @@ -169,6 +179,7 @@ public class PropertyProfileActivatorTest assertActivation( true, profile, newContext( null, newProperties( "other", "" ) ) ); } + @Test public void testWithValue_UserPropertyDominantOverSystemProperty() throws Exception { diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java index 7e94234f23..5f17a8aded 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java @@ -27,14 +27,18 @@ import org.apache.maven.model.building.DefaultModelBuildingRequest; import org.apache.maven.model.building.ModelBuildingRequest; import org.apache.maven.model.building.SimpleProblemCollector; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Trygve Laugstøl */ public class DefaultModelValidatorTest - extends TestCase { private ModelValidator validator; @@ -44,7 +48,7 @@ public class DefaultModelValidatorTest { String resource = "/poms/validation/" + pom; InputStream is = getClass().getResourceAsStream( resource ); - assertNotNull( "missing resource: " + resource, is ); + assertNotNull( is, "missing resource: " + resource ); return new MavenXpp3Reader().read( is ); } @@ -92,34 +96,31 @@ public class DefaultModelValidatorTest private void assertContains( String msg, String substring ) { - assertTrue( "\"" + substring + "\" was not found in: " + msg, msg.contains( substring ) ); + assertTrue( msg.contains( substring ), "\"" + substring + "\" was not found in: " + msg ); } - @Override - protected void setUp() + @BeforeEach + public void setUp() throws Exception { - super.setUp(); - validator = new DefaultModelValidator(); } - @Override - protected void tearDown() + @AfterEach + public void tearDown() throws Exception { this.validator = null; - - super.tearDown(); } private void assertViolations( SimpleProblemCollector result, int fatals, int errors, int warnings ) { - assertEquals( String.valueOf( result.getFatals() ), fatals, result.getFatals().size() ); - assertEquals( String.valueOf( result.getErrors() ), errors, result.getErrors().size() ); - assertEquals( String.valueOf( result.getWarnings() ), warnings, result.getWarnings().size() ); + assertEquals( fatals, result.getFatals().size(), String.valueOf( result.getFatals() ) ); + assertEquals( errors, result.getErrors().size(), String.valueOf( result.getErrors() ) ); + assertEquals( warnings, result.getWarnings().size(), String.valueOf( result.getWarnings() ) ); } + @Test public void testMissingModelVersion() throws Exception { @@ -130,6 +131,7 @@ public class DefaultModelValidatorTest assertEquals( "'modelVersion' is missing.", result.getErrors().get( 0 ) ); } + @Test public void testBadModelVersion() throws Exception { @@ -141,6 +143,7 @@ public class DefaultModelValidatorTest assertTrue( result.getFatals().get( 0 ).contains( "modelVersion" ) ); } + @Test public void testMissingArtifactId() throws Exception { @@ -151,6 +154,7 @@ public class DefaultModelValidatorTest assertEquals( "'artifactId' is missing.", result.getErrors().get( 0 ) ); } + @Test public void testMissingGroupId() throws Exception { @@ -161,6 +165,7 @@ public class DefaultModelValidatorTest assertEquals( "'groupId' is missing.", result.getErrors().get( 0 ) ); } + @Test public void testInvalidIds() throws Exception { @@ -174,6 +179,7 @@ public class DefaultModelValidatorTest result.getErrors().get( 1 ) ); } + @Test public void testMissingType() throws Exception { @@ -184,6 +190,7 @@ public class DefaultModelValidatorTest assertEquals( "'packaging' is missing.", result.getErrors().get( 0 ) ); } + @Test public void testMissingVersion() throws Exception { @@ -194,6 +201,7 @@ public class DefaultModelValidatorTest assertEquals( "'version' is missing.", result.getErrors().get( 0 ) ); } + @Test public void testInvalidAggregatorPackaging() throws Exception { @@ -204,6 +212,7 @@ public class DefaultModelValidatorTest assertTrue( result.getErrors().get( 0 ).contains( "Aggregator projects require 'pom' as packaging." ) ); } + @Test public void testMissingDependencyArtifactId() throws Exception { @@ -214,6 +223,7 @@ public class DefaultModelValidatorTest assertTrue( result.getErrors().get( 0 ).contains( "'dependencies.dependency.artifactId' for groupId:null:jar is missing" ) ); } + @Test public void testMissingDependencyGroupId() throws Exception { @@ -224,6 +234,7 @@ public class DefaultModelValidatorTest assertTrue( result.getErrors().get( 0 ).contains( "'dependencies.dependency.groupId' for null:artifactId:jar is missing" ) ); } + @Test public void testMissingDependencyVersion() throws Exception { @@ -234,6 +245,7 @@ public class DefaultModelValidatorTest assertTrue( result.getErrors().get( 0 ).contains( "'dependencies.dependency.version' for groupId:artifactId:jar is missing" ) ); } + @Test public void testMissingDependencyManagementArtifactId() throws Exception { @@ -244,6 +256,7 @@ public class DefaultModelValidatorTest assertTrue( result.getErrors().get( 0 ).contains( "'dependencyManagement.dependencies.dependency.artifactId' for groupId:null:jar is missing" ) ); } + @Test public void testMissingDependencyManagementGroupId() throws Exception { @@ -254,6 +267,7 @@ public class DefaultModelValidatorTest assertTrue( result.getErrors().get( 0 ).contains( "'dependencyManagement.dependencies.dependency.groupId' for null:artifactId:jar is missing" ) ); } + @Test public void testMissingAll() throws Exception { @@ -270,6 +284,7 @@ public class DefaultModelValidatorTest // type is inherited from the super pom } + @Test public void testMissingPluginArtifactId() throws Exception { @@ -280,6 +295,7 @@ public class DefaultModelValidatorTest assertEquals( "'build.plugins.plugin.artifactId' is missing.", result.getErrors().get( 0 ) ); } + @Test public void testEmptyPluginVersion() throws Exception { @@ -291,6 +307,7 @@ public class DefaultModelValidatorTest + " must be a valid version but is ''.", result.getErrors().get( 0 ) ); } + @Test public void testMissingRepositoryId() throws Exception { @@ -308,6 +325,7 @@ public class DefaultModelValidatorTest assertEquals( "'pluginRepositories.pluginRepository.[null].url' is missing.", result.getErrors().get( 3 ) ); } + @Test public void testMissingResourceDirectory() throws Exception { @@ -320,6 +338,7 @@ public class DefaultModelValidatorTest assertEquals( "'build.testResources.testResource.directory' is missing.", result.getErrors().get( 1 ) ); } + @Test public void testBadPluginDependencyScope() throws Exception { @@ -334,6 +353,7 @@ public class DefaultModelValidatorTest assertTrue( result.getErrors().get( 2 ).contains( "test:f" ) ); } + @Test public void testBadDependencyScope() throws Exception { @@ -346,6 +366,7 @@ public class DefaultModelValidatorTest assertTrue( result.getWarnings().get( 1 ).contains( "test:g" ) ); } + @Test public void testBadDependencyManagementScope() throws Exception { @@ -356,6 +377,7 @@ public class DefaultModelValidatorTest assertContains( result.getWarnings().get( 0 ), "test:g" ); } + @Test public void testBadDependencyVersion() throws Exception { @@ -369,6 +391,7 @@ public class DefaultModelValidatorTest "'dependencies.dependency.version' for test:c:jar must not contain any of these characters" ); } + @Test public void testDuplicateModule() throws Exception { @@ -379,6 +402,7 @@ public class DefaultModelValidatorTest assertTrue( result.getErrors().get( 0 ).contains( "child" ) ); } + @Test public void testDuplicateProfileId() throws Exception { @@ -389,6 +413,7 @@ public class DefaultModelValidatorTest assertTrue( result.getErrors().get( 0 ).contains( "non-unique-id" ) ); } + @Test public void testBadPluginVersion() throws Exception { @@ -406,6 +431,7 @@ public class DefaultModelValidatorTest "'build.plugins.plugin.version' for test:ifsc must not contain any of these characters" ); } + @Test public void testDistributionManagementStatus() throws Exception { @@ -416,6 +442,7 @@ public class DefaultModelValidatorTest assertTrue( result.getErrors().get( 0 ).contains( "distributionManagement.status" ) ); } + @Test public void testIncompleteParent() throws Exception { @@ -427,6 +454,7 @@ public class DefaultModelValidatorTest assertTrue( result.getFatals().get( 2 ).contains( "parent.version" ) ); } + @Test public void testHardCodedSystemPath() throws Exception { @@ -451,6 +479,7 @@ public class DefaultModelValidatorTest } + @Test public void testEmptyModule() throws Exception { @@ -461,6 +490,7 @@ public class DefaultModelValidatorTest assertTrue( result.getErrors().get( 0 ).contains( "'modules.module[0]' has been specified without a path" ) ); } + @Test public void testDuplicatePlugin() throws Exception { @@ -474,6 +504,7 @@ public class DefaultModelValidatorTest assertTrue( result.getWarnings().get( 3 ).contains( "duplicate declaration of plugin profile:managed-duplicate" ) ); } + @Test public void testDuplicatePluginExecution() throws Exception { @@ -487,6 +518,7 @@ public class DefaultModelValidatorTest assertContains( result.getErrors().get( 3 ), "duplicate execution with id b" ); } + @Test public void testReservedRepositoryId() throws Exception { @@ -501,6 +533,7 @@ public class DefaultModelValidatorTest "'distributionManagement.snapshotRepository.id' must not be 'local'" ); } + @Test public void testMissingPluginDependencyGroupId() throws Exception { @@ -511,6 +544,7 @@ public class DefaultModelValidatorTest assertTrue( result.getErrors().get( 0 ).contains( ":a:" ) ); } + @Test public void testMissingPluginDependencyArtifactId() throws Exception { @@ -521,6 +555,7 @@ public class DefaultModelValidatorTest assertTrue( result.getErrors().get( 0 ).contains( "test:" ) ); } + @Test public void testMissingPluginDependencyVersion() throws Exception { @@ -531,6 +566,7 @@ public class DefaultModelValidatorTest assertTrue( result.getErrors().get( 0 ).contains( "test:a" ) ); } + @Test public void testBadPluginDependencyVersion() throws Exception { @@ -541,6 +577,7 @@ public class DefaultModelValidatorTest assertTrue( result.getErrors().get( 0 ).contains( "test:b" ) ); } + @Test public void testBadVersion() throws Exception { @@ -551,6 +588,7 @@ public class DefaultModelValidatorTest assertContains( result.getWarnings().get( 0 ), "'version' must not contain any of these characters" ); } + @Test public void testBadSnapshotVersion() throws Exception { @@ -561,6 +599,7 @@ public class DefaultModelValidatorTest assertContains( result.getWarnings().get( 0 ), "'version' uses an unsupported snapshot version format" ); } + @Test public void testBadRepositoryId() throws Exception { @@ -578,6 +617,7 @@ public class DefaultModelValidatorTest "'distributionManagement.snapshotRepository.id' must not contain any of these characters" ); } + @Test public void testBadDependencyExclusionId() throws Exception { @@ -599,6 +639,7 @@ public class DefaultModelValidatorTest } + @Test public void testMissingDependencyExclusionId() throws Exception { @@ -612,6 +653,7 @@ public class DefaultModelValidatorTest "'dependencies.dependency.exclusions.exclusion.artifactId' for gid:aid:jar is missing" ); } + @Test public void testBadImportScopeType() throws Exception { @@ -623,6 +665,7 @@ public class DefaultModelValidatorTest "'dependencyManagement.dependencies.dependency.type' for test:a:jar must be 'pom'" ); } + @Test public void testBadImportScopeClassifier() throws Exception { @@ -634,6 +677,7 @@ public class DefaultModelValidatorTest "'dependencyManagement.dependencies.dependency.classifier' for test:a:pom:cls must be empty" ); } + @Test public void testSystemPathRefersToProjectBasedir() throws Exception { @@ -661,6 +705,7 @@ public class DefaultModelValidatorTest "'dependencies.dependency.systemPath' for test:b:jar should not point at files within the project directory" ); } + @Test public void testInvalidVersionInPluginManagement() throws Exception { @@ -673,6 +718,7 @@ public class DefaultModelValidatorTest } + @Test public void testInvalidGroupIdInPluginManagement() throws Exception { @@ -685,6 +731,7 @@ public class DefaultModelValidatorTest } + @Test public void testInvalidArtifactIdInPluginManagement() throws Exception { @@ -697,6 +744,7 @@ public class DefaultModelValidatorTest } + @Test public void testInvalidGroupAndArtifactIdInPluginManagement() throws Exception { @@ -712,6 +760,7 @@ public class DefaultModelValidatorTest } + @Test public void testMissingReportPluginVersion() throws Exception { @@ -720,6 +769,7 @@ public class DefaultModelValidatorTest assertViolations( result, 0, 0, 0 ); } + @Test public void testDeprecatedDependencyMetaversionsLatestAndRelease() throws Exception { @@ -733,6 +783,7 @@ public class DefaultModelValidatorTest "'dependencies.dependency.version' for test:b:jar is either LATEST or RELEASE (both of them are being deprecated)" ); } + @Test public void testSelfReferencingDependencyInRawModel() throws Exception { @@ -745,6 +796,7 @@ public class DefaultModelValidatorTest } + @Test public void testSelfReferencingDependencyWithClassifierInRawModel() throws Exception { SimpleProblemCollector result = validateRaw( "raw-model/self-referencing-classifier.xml" ); @@ -752,6 +804,7 @@ public class DefaultModelValidatorTest assertViolations( result, 0, 0, 0 ); } + @Test public void testCiFriendlySha1() throws Exception { @@ -759,6 +812,7 @@ public class DefaultModelValidatorTest assertViolations( result, 0, 0, 0 ); } + @Test public void testCiFriendlyRevision() throws Exception { @@ -766,6 +820,7 @@ public class DefaultModelValidatorTest assertViolations( result, 0, 0, 0 ); } + @Test public void testCiFriendlyChangeList() throws Exception { @@ -773,6 +828,7 @@ public class DefaultModelValidatorTest assertViolations( result, 0, 0, 0 ); } + @Test public void testCiFriendlyAllExpressions() throws Exception { @@ -780,6 +836,7 @@ public class DefaultModelValidatorTest assertViolations( result, 0, 0, 0 ); } + @Test public void testCiFriendlyBad() throws Exception { @@ -788,6 +845,7 @@ public class DefaultModelValidatorTest assertEquals( "'version' contains an expression but should be a constant.", result.getWarnings().get( 0 ) ); } + @Test public void testCiFriendlyBadSha1Plus() throws Exception { @@ -796,6 +854,7 @@ public class DefaultModelValidatorTest assertEquals( "'version' contains an expression but should be a constant.", result.getWarnings().get( 0 ) ); } + @Test public void testCiFriendlyBadSha1Plus2() throws Exception { @@ -804,6 +863,7 @@ public class DefaultModelValidatorTest assertEquals( "'version' contains an expression but should be a constant.", result.getWarnings().get( 0 ) ); } + @Test public void testParentVersionLATEST() throws Exception { @@ -812,6 +872,7 @@ public class DefaultModelValidatorTest assertEquals( "'parent.version' is either LATEST or RELEASE (both of them are being deprecated)", result.getWarnings().get( 0 ) ); } + @Test public void testParentVersionRELEASE() throws Exception { diff --git a/maven-model/src/test/java/org/apache/maven/model/ActivationFileTest.java b/maven-model/src/test/java/org/apache/maven/model/ActivationFileTest.java index f88da58142..cbfdc2a69b 100644 --- a/maven-model/src/test/java/org/apache/maven/model/ActivationFileTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/ActivationFileTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code ActivationFile}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class ActivationFileTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new ActivationFile().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new ActivationFile().equals( null ) ); @@ -42,12 +47,14 @@ public class ActivationFileTest new ActivationFile().equals( new ActivationFile() ); } + @Test public void testEqualsIdentity() { ActivationFile thing = new ActivationFile(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new ActivationFile().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/ActivationOSTest.java b/maven-model/src/test/java/org/apache/maven/model/ActivationOSTest.java index f0d3045078..3be5cd9826 100644 --- a/maven-model/src/test/java/org/apache/maven/model/ActivationOSTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/ActivationOSTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code ActivationOS}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class ActivationOSTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new ActivationOS().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new ActivationOS().equals( null ) ); @@ -42,12 +47,14 @@ public class ActivationOSTest new ActivationOS().equals( new ActivationOS() ); } + @Test public void testEqualsIdentity() { ActivationOS thing = new ActivationOS(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new ActivationOS().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/ActivationPropertyTest.java b/maven-model/src/test/java/org/apache/maven/model/ActivationPropertyTest.java index 5f5e048a90..564adc010e 100644 --- a/maven-model/src/test/java/org/apache/maven/model/ActivationPropertyTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/ActivationPropertyTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code ActivationProperty}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class ActivationPropertyTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new ActivationProperty().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new ActivationProperty().equals( null ) ); @@ -42,12 +47,14 @@ public class ActivationPropertyTest new ActivationProperty().equals( new ActivationProperty() ); } + @Test public void testEqualsIdentity() { ActivationProperty thing = new ActivationProperty(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new ActivationProperty().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/ActivationTest.java b/maven-model/src/test/java/org/apache/maven/model/ActivationTest.java index f6d0f91002..520c0a9073 100644 --- a/maven-model/src/test/java/org/apache/maven/model/ActivationTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/ActivationTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code Activation}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class ActivationTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new Activation().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new Activation().equals( null ) ); @@ -42,12 +47,14 @@ public class ActivationTest new Activation().equals( new Activation() ); } + @Test public void testEqualsIdentity() { Activation thing = new Activation(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new Activation().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/BuildTest.java b/maven-model/src/test/java/org/apache/maven/model/BuildTest.java index 80a60d57ea..3a14bd3c3e 100644 --- a/maven-model/src/test/java/org/apache/maven/model/BuildTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/BuildTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code Build}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class BuildTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new Build().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new Build().equals( null ) ); @@ -42,12 +47,14 @@ public class BuildTest new Build().equals( new Build() ); } + @Test public void testEqualsIdentity() { Build thing = new Build(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new Build().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/CiManagementTest.java b/maven-model/src/test/java/org/apache/maven/model/CiManagementTest.java index 7194c8442c..ee6d41d559 100644 --- a/maven-model/src/test/java/org/apache/maven/model/CiManagementTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/CiManagementTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code CiManagement}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class CiManagementTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new CiManagement().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new CiManagement().equals( null ) ); @@ -42,12 +47,14 @@ public class CiManagementTest new CiManagement().equals( new CiManagement() ); } + @Test public void testEqualsIdentity() { CiManagement thing = new CiManagement(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new CiManagement().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/ContributorTest.java b/maven-model/src/test/java/org/apache/maven/model/ContributorTest.java index 491b99ae82..e2f3dbb5c8 100644 --- a/maven-model/src/test/java/org/apache/maven/model/ContributorTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/ContributorTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code Contributor}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class ContributorTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new Contributor().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new Contributor().equals( null ) ); @@ -42,12 +47,14 @@ public class ContributorTest new Contributor().equals( new Contributor() ); } + @Test public void testEqualsIdentity() { Contributor thing = new Contributor(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new Contributor().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/DependencyManagementTest.java b/maven-model/src/test/java/org/apache/maven/model/DependencyManagementTest.java index 7702c62fd9..e63d224332 100644 --- a/maven-model/src/test/java/org/apache/maven/model/DependencyManagementTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/DependencyManagementTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code DependencyManagement}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class DependencyManagementTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new DependencyManagement().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new DependencyManagement().equals( null ) ); @@ -42,12 +47,14 @@ public class DependencyManagementTest new DependencyManagement().equals( new DependencyManagement() ); } + @Test public void testEqualsIdentity() { DependencyManagement thing = new DependencyManagement(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new DependencyManagement().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/DependencyTest.java b/maven-model/src/test/java/org/apache/maven/model/DependencyTest.java index ec0a833655..6b7bc3f325 100644 --- a/maven-model/src/test/java/org/apache/maven/model/DependencyTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/DependencyTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code Dependency}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class DependencyTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new Dependency().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new Dependency().equals( null ) ); @@ -42,12 +47,14 @@ public class DependencyTest new Dependency().equals( new Dependency() ); } + @Test public void testEqualsIdentity() { Dependency thing = new Dependency(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new Dependency().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/DeploymentRepositoryTest.java b/maven-model/src/test/java/org/apache/maven/model/DeploymentRepositoryTest.java index 169ec65079..c648ffd293 100644 --- a/maven-model/src/test/java/org/apache/maven/model/DeploymentRepositoryTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/DeploymentRepositoryTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code DeploymentRepository}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class DeploymentRepositoryTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new DeploymentRepository().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new DeploymentRepository().equals( null ) ); @@ -42,12 +47,14 @@ public class DeploymentRepositoryTest new DeploymentRepository().equals( new DeploymentRepository() ); } + @Test public void testEqualsIdentity() { DeploymentRepository thing = new DeploymentRepository(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new DeploymentRepository().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/DeveloperTest.java b/maven-model/src/test/java/org/apache/maven/model/DeveloperTest.java index c0dfe56dfa..61d86f0840 100644 --- a/maven-model/src/test/java/org/apache/maven/model/DeveloperTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/DeveloperTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code Developer}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class DeveloperTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new Developer().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new Developer().equals( null ) ); @@ -42,12 +47,14 @@ public class DeveloperTest new Developer().equals( new Developer() ); } + @Test public void testEqualsIdentity() { Developer thing = new Developer(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new Developer().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/DistributionManagementTest.java b/maven-model/src/test/java/org/apache/maven/model/DistributionManagementTest.java index 0314d61b71..db8ba213ba 100644 --- a/maven-model/src/test/java/org/apache/maven/model/DistributionManagementTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/DistributionManagementTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code DistributionManagement}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class DistributionManagementTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new DistributionManagement().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new DistributionManagement().equals( null ) ); @@ -42,12 +47,14 @@ public class DistributionManagementTest new DistributionManagement().equals( new DistributionManagement() ); } + @Test public void testEqualsIdentity() { DistributionManagement thing = new DistributionManagement(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new DistributionManagement().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/ExclusionTest.java b/maven-model/src/test/java/org/apache/maven/model/ExclusionTest.java index 6febacebed..90e4b744d3 100644 --- a/maven-model/src/test/java/org/apache/maven/model/ExclusionTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/ExclusionTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code Exclusion}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class ExclusionTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new Exclusion().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new Exclusion().equals( null ) ); @@ -42,12 +47,14 @@ public class ExclusionTest new Exclusion().equals( new Exclusion() ); } + @Test public void testEqualsIdentity() { Exclusion thing = new Exclusion(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new Exclusion().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/ExtensionTest.java b/maven-model/src/test/java/org/apache/maven/model/ExtensionTest.java index 4b8cd8a117..218ff50b6a 100644 --- a/maven-model/src/test/java/org/apache/maven/model/ExtensionTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/ExtensionTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code Extension}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class ExtensionTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new Extension().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new Extension().equals( null ) ); @@ -42,12 +47,14 @@ public class ExtensionTest new Extension().equals( new Extension() ); } + @Test public void testEqualsIdentity() { Extension thing = new Extension(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new Extension().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/IssueManagementTest.java b/maven-model/src/test/java/org/apache/maven/model/IssueManagementTest.java index 5e50c15715..27e1eb0a32 100644 --- a/maven-model/src/test/java/org/apache/maven/model/IssueManagementTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/IssueManagementTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code IssueManagement}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class IssueManagementTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new IssueManagement().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new IssueManagement().equals( null ) ); @@ -42,12 +47,14 @@ public class IssueManagementTest new IssueManagement().equals( new IssueManagement() ); } + @Test public void testEqualsIdentity() { IssueManagement thing = new IssueManagement(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new IssueManagement().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/LicenseTest.java b/maven-model/src/test/java/org/apache/maven/model/LicenseTest.java index 179921b2b7..dd56616fb0 100644 --- a/maven-model/src/test/java/org/apache/maven/model/LicenseTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/LicenseTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code License}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class LicenseTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new License().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new License().equals( null ) ); @@ -42,12 +47,14 @@ public class LicenseTest new License().equals( new License() ); } + @Test public void testEqualsIdentity() { License thing = new License(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new License().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/MailingListTest.java b/maven-model/src/test/java/org/apache/maven/model/MailingListTest.java index 612969520d..5de9edcf30 100644 --- a/maven-model/src/test/java/org/apache/maven/model/MailingListTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/MailingListTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code MailingList}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class MailingListTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new MailingList().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new MailingList().equals( null ) ); @@ -42,12 +47,14 @@ public class MailingListTest new MailingList().equals( new MailingList() ); } + @Test public void testEqualsIdentity() { MailingList thing = new MailingList(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new MailingList().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/ModelTest.java b/maven-model/src/test/java/org/apache/maven/model/ModelTest.java index c9ec4da96a..37adc82166 100644 --- a/maven-model/src/test/java/org/apache/maven/model/ModelTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/ModelTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code Model}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class ModelTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new Model().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new Model().equals( null ) ); @@ -42,12 +47,14 @@ public class ModelTest new Model().equals( new Model() ); } + @Test public void testEqualsIdentity() { Model thing = new Model(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new Model().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/NotifierTest.java b/maven-model/src/test/java/org/apache/maven/model/NotifierTest.java index 4e5d0685ca..026632ad60 100644 --- a/maven-model/src/test/java/org/apache/maven/model/NotifierTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/NotifierTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code Notifier}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class NotifierTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new Notifier().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new Notifier().equals( null ) ); @@ -42,12 +47,14 @@ public class NotifierTest new Notifier().equals( new Notifier() ); } + @Test public void testEqualsIdentity() { Notifier thing = new Notifier(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new Notifier().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/OrganizationTest.java b/maven-model/src/test/java/org/apache/maven/model/OrganizationTest.java index 48abe77e2b..ef19d2a546 100644 --- a/maven-model/src/test/java/org/apache/maven/model/OrganizationTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/OrganizationTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code Organization}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class OrganizationTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new Organization().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new Organization().equals( null ) ); @@ -42,12 +47,14 @@ public class OrganizationTest new Organization().equals( new Organization() ); } + @Test public void testEqualsIdentity() { Organization thing = new Organization(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new Organization().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/ParentTest.java b/maven-model/src/test/java/org/apache/maven/model/ParentTest.java index 78d45672a3..d8690fc3c9 100644 --- a/maven-model/src/test/java/org/apache/maven/model/ParentTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/ParentTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code Parent}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class ParentTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new Parent().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new Parent().equals( null ) ); @@ -42,12 +47,14 @@ public class ParentTest new Parent().equals( new Parent() ); } + @Test public void testEqualsIdentity() { Parent thing = new Parent(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new Parent().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/PluginConfigurationTest.java b/maven-model/src/test/java/org/apache/maven/model/PluginConfigurationTest.java index cbb123d5ab..3e52df79f6 100644 --- a/maven-model/src/test/java/org/apache/maven/model/PluginConfigurationTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/PluginConfigurationTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code PluginConfiguration}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class PluginConfigurationTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new PluginConfiguration().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new PluginConfiguration().equals( null ) ); @@ -42,12 +47,14 @@ public class PluginConfigurationTest new PluginConfiguration().equals( new PluginConfiguration() ); } + @Test public void testEqualsIdentity() { PluginConfiguration thing = new PluginConfiguration(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new PluginConfiguration().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/PluginContainerTest.java b/maven-model/src/test/java/org/apache/maven/model/PluginContainerTest.java index 878298cf3e..ed4e9e3d79 100644 --- a/maven-model/src/test/java/org/apache/maven/model/PluginContainerTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/PluginContainerTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code PluginContainer}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class PluginContainerTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new PluginContainer().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new PluginContainer().equals( null ) ); @@ -42,12 +47,14 @@ public class PluginContainerTest new PluginContainer().equals( new PluginContainer() ); } + @Test public void testEqualsIdentity() { PluginContainer thing = new PluginContainer(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new PluginContainer().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/PluginExecutionTest.java b/maven-model/src/test/java/org/apache/maven/model/PluginExecutionTest.java index e8fff5129a..35b78bdd89 100644 --- a/maven-model/src/test/java/org/apache/maven/model/PluginExecutionTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/PluginExecutionTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code PluginExecution}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class PluginExecutionTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new PluginExecution().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new PluginExecution().equals( null ) ); @@ -42,12 +47,14 @@ public class PluginExecutionTest new PluginExecution().equals( new PluginExecution() ); } + @Test public void testEqualsIdentity() { PluginExecution thing = new PluginExecution(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new PluginExecution().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/PluginManagementTest.java b/maven-model/src/test/java/org/apache/maven/model/PluginManagementTest.java index 571399feb0..b4d826624c 100644 --- a/maven-model/src/test/java/org/apache/maven/model/PluginManagementTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/PluginManagementTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code PluginManagement}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class PluginManagementTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new PluginManagement().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new PluginManagement().equals( null ) ); @@ -42,12 +47,14 @@ public class PluginManagementTest new PluginManagement().equals( new PluginManagement() ); } + @Test public void testEqualsIdentity() { PluginManagement thing = new PluginManagement(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new PluginManagement().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/PluginTest.java b/maven-model/src/test/java/org/apache/maven/model/PluginTest.java index 582145e096..d8e345b6b3 100644 --- a/maven-model/src/test/java/org/apache/maven/model/PluginTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/PluginTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code Plugin}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class PluginTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new Plugin().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new Plugin().equals( null ) ); @@ -42,12 +47,14 @@ public class PluginTest new Plugin().equals( new Plugin() ); } + @Test public void testEqualsIdentity() { Plugin thing = new Plugin(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new Plugin().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/PrerequisitesTest.java b/maven-model/src/test/java/org/apache/maven/model/PrerequisitesTest.java index 727f2c3f23..2c91e47108 100644 --- a/maven-model/src/test/java/org/apache/maven/model/PrerequisitesTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/PrerequisitesTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code Prerequisites}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class PrerequisitesTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new Prerequisites().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new Prerequisites().equals( null ) ); @@ -42,12 +47,14 @@ public class PrerequisitesTest new Prerequisites().equals( new Prerequisites() ); } + @Test public void testEqualsIdentity() { Prerequisites thing = new Prerequisites(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new Prerequisites().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/ProfileTest.java b/maven-model/src/test/java/org/apache/maven/model/ProfileTest.java index 512e2a8892..ac719e4677 100644 --- a/maven-model/src/test/java/org/apache/maven/model/ProfileTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/ProfileTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code Profile}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class ProfileTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new Profile().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new Profile().equals( null ) ); @@ -42,12 +47,14 @@ public class ProfileTest new Profile().equals( new Profile() ); } + @Test public void testEqualsIdentity() { Profile thing = new Profile(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new Profile().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/RelocationTest.java b/maven-model/src/test/java/org/apache/maven/model/RelocationTest.java index 265304d8da..ea825a6fd3 100644 --- a/maven-model/src/test/java/org/apache/maven/model/RelocationTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/RelocationTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code Relocation}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class RelocationTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new Relocation().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new Relocation().equals( null ) ); @@ -42,12 +47,14 @@ public class RelocationTest new Relocation().equals( new Relocation() ); } + @Test public void testEqualsIdentity() { Relocation thing = new Relocation(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new Relocation().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/ReportPluginTest.java b/maven-model/src/test/java/org/apache/maven/model/ReportPluginTest.java index d10cb791d5..094d2d5f69 100644 --- a/maven-model/src/test/java/org/apache/maven/model/ReportPluginTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/ReportPluginTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code ReportPlugin}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class ReportPluginTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new ReportPlugin().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new ReportPlugin().equals( null ) ); @@ -42,12 +47,14 @@ public class ReportPluginTest new ReportPlugin().equals( new ReportPlugin() ); } + @Test public void testEqualsIdentity() { ReportPlugin thing = new ReportPlugin(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new ReportPlugin().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/ReportSetTest.java b/maven-model/src/test/java/org/apache/maven/model/ReportSetTest.java index 2f51415329..c0bb2575c2 100644 --- a/maven-model/src/test/java/org/apache/maven/model/ReportSetTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/ReportSetTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code ReportSet}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class ReportSetTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new ReportSet().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new ReportSet().equals( null ) ); @@ -42,12 +47,14 @@ public class ReportSetTest new ReportSet().equals( new ReportSet() ); } + @Test public void testEqualsIdentity() { ReportSet thing = new ReportSet(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new ReportSet().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/ReportingTest.java b/maven-model/src/test/java/org/apache/maven/model/ReportingTest.java index dbc0fa2256..3b04d02405 100644 --- a/maven-model/src/test/java/org/apache/maven/model/ReportingTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/ReportingTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code Reporting}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class ReportingTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new Reporting().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new Reporting().equals( null ) ); @@ -42,12 +47,14 @@ public class ReportingTest new Reporting().equals( new Reporting() ); } + @Test public void testEqualsIdentity() { Reporting thing = new Reporting(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new Reporting().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/RepositoryPolicyTest.java b/maven-model/src/test/java/org/apache/maven/model/RepositoryPolicyTest.java index 3ae3435040..770bce206d 100644 --- a/maven-model/src/test/java/org/apache/maven/model/RepositoryPolicyTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/RepositoryPolicyTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code RepositoryPolicy}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class RepositoryPolicyTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new RepositoryPolicy().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new RepositoryPolicy().equals( null ) ); @@ -42,12 +47,14 @@ public class RepositoryPolicyTest new RepositoryPolicy().equals( new RepositoryPolicy() ); } + @Test public void testEqualsIdentity() { RepositoryPolicy thing = new RepositoryPolicy(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new RepositoryPolicy().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/RepositoryTest.java b/maven-model/src/test/java/org/apache/maven/model/RepositoryTest.java index b68b70a1ff..62f32d723f 100644 --- a/maven-model/src/test/java/org/apache/maven/model/RepositoryTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/RepositoryTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code Repository}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class RepositoryTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new Repository().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new Repository().equals( null ) ); @@ -42,12 +47,14 @@ public class RepositoryTest new Repository().equals( new Repository() ); } + @Test public void testEqualsIdentity() { Repository thing = new Repository(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new Repository().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/ResourceTest.java b/maven-model/src/test/java/org/apache/maven/model/ResourceTest.java index fa40ab43d9..3e5b1b3a02 100644 --- a/maven-model/src/test/java/org/apache/maven/model/ResourceTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/ResourceTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code Resource}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class ResourceTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new Resource().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new Resource().equals( null ) ); @@ -42,12 +47,14 @@ public class ResourceTest new Resource().equals( new Resource() ); } + @Test public void testEqualsIdentity() { Resource thing = new Resource(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new Resource().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/ScmTest.java b/maven-model/src/test/java/org/apache/maven/model/ScmTest.java index 4d7699310e..a6ccc248d3 100644 --- a/maven-model/src/test/java/org/apache/maven/model/ScmTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/ScmTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code Scm}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class ScmTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new Scm().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new Scm().equals( null ) ); @@ -42,12 +47,14 @@ public class ScmTest new Scm().equals( new Scm() ); } + @Test public void testEqualsIdentity() { Scm thing = new Scm(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new Scm().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/SiteTest.java b/maven-model/src/test/java/org/apache/maven/model/SiteTest.java index 84896bb4d7..5fe49756cb 100644 --- a/maven-model/src/test/java/org/apache/maven/model/SiteTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/SiteTest.java @@ -19,7 +19,11 @@ package org.apache.maven.model; * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@code Site}. @@ -27,14 +31,15 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class SiteTest - extends TestCase { + @Test public void testHashCodeNullSafe() { new Site().hashCode(); } + @Test public void testEqualsNullSafe() { assertFalse( new Site().equals( null ) ); @@ -42,12 +47,14 @@ public class SiteTest new Site().equals( new Site() ); } + @Test public void testEqualsIdentity() { Site thing = new Site(); assertTrue( thing.equals( thing ) ); } + @Test public void testToStringNullSafe() { assertNotNull( new Site().toString() ); diff --git a/maven-model/src/test/java/org/apache/maven/model/merge/ModelMergerTest.java b/maven-model/src/test/java/org/apache/maven/model/merge/ModelMergerTest.java index 732c277894..104b9771ae 100644 --- a/maven-model/src/test/java/org/apache/maven/model/merge/ModelMergerTest.java +++ b/maven-model/src/test/java/org/apache/maven/model/merge/ModelMergerTest.java @@ -1,5 +1,6 @@ package org.apache.maven.model.merge; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.is; @@ -22,8 +23,6 @@ import static org.hamcrest.Matchers.is; * under the License. */ -import static org.junit.Assert.assertThat; - import java.util.Arrays; import org.apache.maven.model.Build; @@ -37,7 +36,7 @@ import org.apache.maven.model.PluginExecution; import org.apache.maven.model.Profile; import org.apache.maven.model.ReportSet; import org.apache.maven.model.Repository; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * ModelMerger is based on same instances, subclasses should override KeyComputer per type diff --git a/maven-plugin-api/src/test/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilderTest.java b/maven-plugin-api/src/test/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilderTest.java index b9f5ab9e9e..5b245af208 100644 --- a/maven-plugin-api/src/test/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilderTest.java +++ b/maven-plugin-api/src/test/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilderTest.java @@ -27,8 +27,10 @@ import org.codehaus.plexus.component.repository.ComponentRequirement; import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.configuration.PlexusConfigurationException; import org.codehaus.plexus.util.ReaderFactory; +import org.junit.jupiter.api.Test; -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * Tests {@link PluginDescriptorBuilder}. @@ -36,7 +38,6 @@ import junit.framework.TestCase; * @author Benjamin Bentmann */ public class PluginDescriptorBuilderTest - extends TestCase { private PluginDescriptor build( String resource ) @@ -47,6 +48,7 @@ public class PluginDescriptorBuilderTest return new PluginDescriptorBuilder().build( reader ); } + @Test public void testBuildReader() throws Exception { diff --git a/maven-resolver-provider/pom.xml b/maven-resolver-provider/pom.xml index de33876bd1..5bbeb849c3 100644 --- a/maven-resolver-provider/pom.xml +++ b/maven-resolver-provider/pom.xml @@ -83,6 +83,11 @@ under the License. + + org.apache.maven + maven-test-support + test + org.apache.maven.resolver maven-resolver-connector-basic diff --git a/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/AbstractRepositoryTestCase.java b/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/AbstractRepositoryTestCase.java index b81450cea6..0301a605eb 100644 --- a/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/AbstractRepositoryTestCase.java +++ b/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/AbstractRepositoryTestCase.java @@ -21,50 +21,36 @@ package org.apache.maven.repository.internal; import java.net.MalformedURLException; +import javax.inject.Inject; + +import org.apache.maven.test.PlexusTestCase; import org.apache.maven.repository.internal.util.ConsoleRepositoryListener; import org.apache.maven.repository.internal.util.ConsoleTransferListener; -import org.codehaus.plexus.ContainerConfiguration; -import org.codehaus.plexus.PlexusConstants; -import org.codehaus.plexus.PlexusTestCase; import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.repository.LocalRepository; import org.eclipse.aether.repository.RemoteRepository; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; public abstract class AbstractRepositoryTestCase extends PlexusTestCase { + @Inject protected RepositorySystem system; protected RepositorySystemSession session; + @BeforeEach @Override - protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration ) - { - super.customizeContainerConfiguration( containerConfiguration ); - containerConfiguration.setAutoWiring( true ); - containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); - } - - @Override - protected void setUp() + public void setUp() throws Exception { super.setUp(); - system = lookup( RepositorySystem.class ); session = newMavenRepositorySystemSession( system ); } - @Override - protected void tearDown() - throws Exception - { - session = null; - system = null; - super.tearDown(); - } - public static RepositorySystemSession newMavenRepositorySystemSession( RepositorySystem system ) { DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession(); diff --git a/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReaderTest.java b/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReaderTest.java index e873138093..cd45fe36d9 100644 --- a/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReaderTest.java +++ b/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReaderTest.java @@ -19,21 +19,25 @@ package org.apache.maven.repository.internal; * under the License. */ -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; - import org.eclipse.aether.RepositoryEvent; import org.eclipse.aether.RepositoryEvent.EventType; import org.eclipse.aether.artifact.DefaultArtifact; import org.eclipse.aether.impl.ArtifactDescriptorReader; import org.eclipse.aether.impl.RepositoryEventDispatcher; import org.eclipse.aether.resolution.ArtifactDescriptorRequest; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + public class DefaultArtifactDescriptorReaderTest extends AbstractRepositoryTestCase { + @Test public void testMng5459() throws Exception { @@ -69,9 +73,6 @@ public class DefaultArtifactDescriptorReaderTest } } - if( !missingArtifactDescriptor ) - { - fail( "Expected missing artifact descriptor for org.apache.maven.its:dep-mng5459:pom:0.4.0-20130404.090532-2" ); - } + assertTrue( missingArtifactDescriptor, "Expected missing artifact descriptor for org.apache.maven.its:dep-mng5459:pom:0.4.0-20130404.090532-2" ); } } diff --git a/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultModelResolverTest.java b/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultModelResolverTest.java index e895bbb099..ce09b4b325 100644 --- a/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultModelResolverTest.java +++ b/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultModelResolverTest.java @@ -30,6 +30,12 @@ import org.codehaus.plexus.component.repository.exception.ComponentLookupExcepti import org.eclipse.aether.impl.ArtifactResolver; import org.eclipse.aether.impl.RemoteRepositoryManager; import org.eclipse.aether.impl.VersionRangeResolver; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Test cases for the default {@code ModelResolver} implementation. @@ -48,6 +54,7 @@ public final class DefaultModelResolverTest extends AbstractRepositoryTestCase super(); } + @Test public void testResolveParentThrowsUnresolvableModelExceptionWhenNotFound() throws Exception { final Parent parent = new Parent(); @@ -55,18 +62,15 @@ public final class DefaultModelResolverTest extends AbstractRepositoryTestCase parent.setArtifactId( "artifact" ); parent.setVersion( "0" ); - try - { - this.newModelResolver().resolveModel( parent ); - fail( "Expected 'UnresolvableModelException' not thrown." ); - } - catch ( final UnresolvableModelException e ) - { - assertNotNull( e.getMessage() ); - assertTrue( e.getMessage().startsWith( "Could not find artifact ut.simple:artifact:pom:0 in repo" ) ); - } + UnresolvableModelException e = assertThrows( + UnresolvableModelException.class, + () -> newModelResolver().resolveModel( parent ), + "Expected 'UnresolvableModelException' not thrown." ); + assertNotNull( e.getMessage() ); + assertTrue( e.getMessage().startsWith( "Could not find artifact ut.simple:artifact:pom:0 in repo" ) ); } + @Test public void testResolveParentThrowsUnresolvableModelExceptionWhenNoMatchingVersionFound() throws Exception { final Parent parent = new Parent(); @@ -74,19 +78,16 @@ public final class DefaultModelResolverTest extends AbstractRepositoryTestCase parent.setArtifactId( "artifact" ); parent.setVersion( "[2.0,2.1)" ); - try - { - this.newModelResolver().resolveModel( parent ); - fail( "Expected 'UnresolvableModelException' not thrown." ); - } - catch ( final UnresolvableModelException e ) - { - assertEquals( "No versions matched the requested parent version range '[2.0,2.1)'", - e.getMessage() ); - - } + UnresolvableModelException e = assertThrows( + UnresolvableModelException.class, + () -> newModelResolver().resolveModel( parent ), + "Expected 'UnresolvableModelException' not thrown." ); + assertNotNull( e.getMessage() ); + assertEquals( "No versions matched the requested parent version range '[2.0,2.1)'", + e.getMessage() ); } + @Test public void testResolveParentThrowsUnresolvableModelExceptionWhenUsingRangesWithoutUpperBound() throws Exception { final Parent parent = new Parent(); @@ -94,19 +95,15 @@ public final class DefaultModelResolverTest extends AbstractRepositoryTestCase parent.setArtifactId( "artifact" ); parent.setVersion( "[1.0,)" ); - try - { - this.newModelResolver().resolveModel( parent ); - fail( "Expected 'UnresolvableModelException' not thrown." ); - } - catch ( final UnresolvableModelException e ) - { - assertEquals( "The requested parent version range '[1.0,)' does not specify an upper bound", - e.getMessage() ); - - } + UnresolvableModelException e = assertThrows( + UnresolvableModelException.class, + () -> newModelResolver().resolveModel( parent ), + "Expected 'UnresolvableModelException' not thrown." ); + assertEquals( "The requested parent version range '[1.0,)' does not specify an upper bound", + e.getMessage() ); } + @Test public void testResolveParentSuccessfullyResolvesExistingParentWithoutRange() throws Exception { final Parent parent = new Parent(); @@ -118,6 +115,7 @@ public final class DefaultModelResolverTest extends AbstractRepositoryTestCase assertEquals( "1.0", parent.getVersion() ); } + @Test public void testResolveParentSuccessfullyResolvesExistingParentUsingHighestVersion() throws Exception { final Parent parent = new Parent(); @@ -129,6 +127,7 @@ public final class DefaultModelResolverTest extends AbstractRepositoryTestCase assertEquals( "1.0", parent.getVersion() ); } + @Test public void testResolveDependencyThrowsUnresolvableModelExceptionWhenNotFound() throws Exception { final Dependency dependency = new Dependency(); @@ -136,18 +135,15 @@ public final class DefaultModelResolverTest extends AbstractRepositoryTestCase dependency.setArtifactId( "artifact" ); dependency.setVersion( "0" ); - try - { - this.newModelResolver().resolveModel( dependency ); - fail( "Expected 'UnresolvableModelException' not thrown." ); - } - catch ( final UnresolvableModelException e ) - { - assertNotNull( e.getMessage() ); - assertTrue( e.getMessage().startsWith( "Could not find artifact ut.simple:artifact:pom:0 in repo" ) ); - } + UnresolvableModelException e = assertThrows( + UnresolvableModelException.class, + () -> newModelResolver().resolveModel( dependency ), + "Expected 'UnresolvableModelException' not thrown." ); + assertNotNull( e.getMessage() ); + assertTrue( e.getMessage().startsWith( "Could not find artifact ut.simple:artifact:pom:0 in repo" ) ); } + @Test public void testResolveDependencyThrowsUnresolvableModelExceptionWhenNoMatchingVersionFound() throws Exception { final Dependency dependency = new Dependency(); @@ -155,19 +151,15 @@ public final class DefaultModelResolverTest extends AbstractRepositoryTestCase dependency.setArtifactId( "artifact" ); dependency.setVersion( "[2.0,2.1)" ); - try - { - this.newModelResolver().resolveModel( dependency ); - fail( "Expected 'UnresolvableModelException' not thrown." ); - } - catch ( final UnresolvableModelException e ) - { - assertEquals( "No versions matched the requested dependency version range '[2.0,2.1)'", - e.getMessage() ); - - } + UnresolvableModelException e = assertThrows( + UnresolvableModelException.class, + () -> newModelResolver().resolveModel( dependency ), + "Expected 'UnresolvableModelException' not thrown." ); + assertEquals( "No versions matched the requested dependency version range '[2.0,2.1)'", + e.getMessage() ); } + @Test public void testResolveDependencyThrowsUnresolvableModelExceptionWhenUsingRangesWithoutUpperBound() throws Exception { final Dependency dependency = new Dependency(); @@ -175,19 +167,15 @@ public final class DefaultModelResolverTest extends AbstractRepositoryTestCase dependency.setArtifactId( "artifact" ); dependency.setVersion( "[1.0,)" ); - try - { - this.newModelResolver().resolveModel( dependency ); - fail( "Expected 'UnresolvableModelException' not thrown." ); - } - catch ( final UnresolvableModelException e ) - { - assertEquals( "The requested dependency version range '[1.0,)' does not specify an upper bound", - e.getMessage() ); - - } + UnresolvableModelException e = assertThrows( + UnresolvableModelException.class, + () -> newModelResolver().resolveModel( dependency ), + "Expected 'UnresolvableModelException' not thrown." ); + assertEquals( "The requested dependency version range '[1.0,)' does not specify an upper bound", + e.getMessage() ); } + @Test public void testResolveDependencySuccessfullyResolvesExistingDependencyWithoutRange() throws Exception { final Dependency dependency = new Dependency(); @@ -199,6 +187,7 @@ public final class DefaultModelResolverTest extends AbstractRepositoryTestCase assertEquals( "1.0", dependency.getVersion() ); } + @Test public void testResolveDependencySuccessfullyResolvesExistingDependencyUsingHighestVersion() throws Exception { final Dependency dependency = new Dependency(); diff --git a/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultVersionResolverTest.java b/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultVersionResolverTest.java index 90dd6a4cf3..8eebaf55a4 100644 --- a/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultVersionResolverTest.java +++ b/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultVersionResolverTest.java @@ -19,34 +19,25 @@ package org.apache.maven.repository.internal; * under the License. */ +import javax.inject.Inject; + import org.eclipse.aether.artifact.Artifact; -import org.eclipse.aether.impl.VersionResolver; +import org.eclipse.aether.artifact.DefaultArtifact; import org.eclipse.aether.resolution.VersionRequest; import org.eclipse.aether.resolution.VersionResult; -import org.eclipse.aether.artifact.DefaultArtifact; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class DefaultVersionResolverTest extends AbstractRepositoryTestCase { + @Inject private DefaultVersionResolver versionResolver; - @Override - protected void setUp() - throws Exception - { - super.setUp(); - // be sure we're testing the right class, i.e. DefaultVersionResolver.class - versionResolver = (DefaultVersionResolver) lookup( VersionResolver.class, "default" ); - } - - @Override - protected void tearDown() - throws Exception - { - versionResolver = null; - super.tearDown(); - } - + @Test public void testResolveSeparateInstalledClassifiedNonUniqueVersionedArtifacts() throws Exception { @@ -70,6 +61,7 @@ public class DefaultVersionResolverTest assertEquals( "07.20.3-20120809.112124-88", resultA.getVersion() ); } + @Test public void testResolveSeparateInstalledClassifiedNonVersionedArtifacts() throws Exception { diff --git a/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/MavenRepositorySystemUtilsTest.java b/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/MavenRepositorySystemUtilsTest.java index 768835a555..e54ceb1483 100644 --- a/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/MavenRepositorySystemUtilsTest.java +++ b/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/MavenRepositorySystemUtilsTest.java @@ -22,13 +22,15 @@ package org.apache.maven.repository.internal; import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.impl.MetadataGeneratorFactory; import org.eclipse.aether.spi.locator.ServiceLocator; +import org.junit.jupiter.api.Test; -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class MavenRepositorySystemUtilsTest - extends TestCase { + @Test public void testGetRepositorySystem() { ServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator(); @@ -36,6 +38,7 @@ public class MavenRepositorySystemUtilsTest assertNotNull( repoSys ); } + @Test public void testGetMetadataGeneratorFactories() { ServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator(); diff --git a/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/RemoteSnapshotMetadataTest.java b/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/RemoteSnapshotMetadataTest.java index 566710dcdb..86c7269089 100644 --- a/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/RemoteSnapshotMetadataTest.java +++ b/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/RemoteSnapshotMetadataTest.java @@ -19,8 +19,6 @@ package org.apache.maven.repository.internal; * under the License. */ -import static org.junit.Assert.assertTrue; - import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.Date; @@ -31,22 +29,24 @@ import java.util.Set; import org.apache.maven.artifact.repository.metadata.Metadata; import org.eclipse.aether.artifact.DefaultArtifact; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertTrue; public class RemoteSnapshotMetadataTest { private Locale defaultLocale; - @Before + @BeforeEach public void setLocaleToUseBuddhistCalendar() { defaultLocale = Locale.getDefault(); Locale.setDefault( new Locale( "th", "TH" ) ); } - @After + @AfterEach public void restoreLocale() { Locale.setDefault( defaultLocale ); @@ -76,7 +76,6 @@ public class RemoteSnapshotMetadataTest /* Allow for this test running across midnight */ Set expected = new HashSet<>( Arrays.asList( dateBefore, dateAfter ) ); - assertTrue( "Expected " + datePart + " to be in " + expected, - expected.contains( datePart ) ); + assertTrue( expected.contains( datePart ), "Expected " + datePart + " to be in " + expected ); } } diff --git a/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/RepositorySystemTest.java b/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/RepositorySystemTest.java index 7943dc802d..77b2781bee 100644 --- a/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/RepositorySystemTest.java +++ b/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/RepositorySystemTest.java @@ -23,6 +23,7 @@ import java.util.Arrays; import java.util.List; import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.artifact.DefaultArtifact; import org.eclipse.aether.collection.CollectRequest; import org.eclipse.aether.collection.CollectResult; import org.eclipse.aether.graph.Dependency; @@ -31,11 +32,18 @@ import org.eclipse.aether.resolution.ArtifactDescriptorRequest; import org.eclipse.aether.resolution.ArtifactDescriptorResult; import org.eclipse.aether.resolution.ArtifactRequest; import org.eclipse.aether.resolution.ArtifactResult; -import org.eclipse.aether.artifact.DefaultArtifact; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class RepositorySystemTest extends AbstractRepositoryTestCase { + @Test public void testResolveVersionRange() throws Exception { @@ -44,6 +52,7 @@ public class RepositorySystemTest } + @Test public void testResolveVersion() throws Exception { @@ -51,6 +60,7 @@ public class RepositorySystemTest // throws VersionResolutionException; } + @Test public void testReadArtifactDescriptor() throws Exception { @@ -109,6 +119,7 @@ public class RepositorySystemTest assertEquals( 4, depArtifact.getProperties().size() ); } + @Test public void testCollectDependencies() throws Exception { @@ -126,6 +137,7 @@ public class RepositorySystemTest checkUtSimpleArtifactDependencies( nodes.get( 0 ).getDependency(), nodes.get( 1 ).getDependency() ); } + @Test public void testResolveArtifact() throws Exception { @@ -158,6 +170,7 @@ public class RepositorySystemTest assertEquals( filename, artifact.getFile().getName() ); } + @Test public void testResolveArtifacts() throws Exception { @@ -183,6 +196,7 @@ public class RepositorySystemTest checkArtifactResult( results.get( 2 ), "artifact-1.0-classifier.zip" ); } + @Test public void testResolveMetadata() throws Exception { @@ -190,6 +204,7 @@ public class RepositorySystemTest // Collection requests ); } + @Test public void testInstall() throws Exception { @@ -198,6 +213,7 @@ public class RepositorySystemTest // release, snapshot unique ou non unique, attachment } + @Test public void testDeploy() throws Exception { @@ -205,12 +221,14 @@ public class RepositorySystemTest // throws DeploymentException; } + @Test public void testNewLocalRepositoryManager() throws Exception { //LocalRepositoryManager newLocalRepositoryManager( LocalRepository localRepository ); } + @Test public void testNewSyncContext() throws Exception { diff --git a/maven-settings-builder/src/test/java/org/apache/maven/settings/building/DefaultSettingsBuilderFactoryTest.java b/maven-settings-builder/src/test/java/org/apache/maven/settings/building/DefaultSettingsBuilderFactoryTest.java index 722abf3251..63d62be58e 100644 --- a/maven-settings-builder/src/test/java/org/apache/maven/settings/building/DefaultSettingsBuilderFactoryTest.java +++ b/maven-settings-builder/src/test/java/org/apache/maven/settings/building/DefaultSettingsBuilderFactoryTest.java @@ -21,13 +21,14 @@ package org.apache.maven.settings.building; import java.io.File; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * @author Benjamin Bentmann */ public class DefaultSettingsBuilderFactoryTest - extends TestCase { private File getSettings( String name ) @@ -35,6 +36,7 @@ public class DefaultSettingsBuilderFactoryTest return new File( "src/test/resources/settings/factory/" + name + ".xml" ).getAbsoluteFile(); } + @Test public void testCompleteWiring() throws Exception { diff --git a/maven-settings-builder/src/test/java/org/apache/maven/settings/validation/DefaultSettingsValidatorTest.java b/maven-settings-builder/src/test/java/org/apache/maven/settings/validation/DefaultSettingsValidatorTest.java index b9f487385b..c23ebd2120 100644 --- a/maven-settings-builder/src/test/java/org/apache/maven/settings/validation/DefaultSettingsValidatorTest.java +++ b/maven-settings-builder/src/test/java/org/apache/maven/settings/validation/DefaultSettingsValidatorTest.java @@ -22,47 +22,49 @@ package org.apache.maven.settings.validation; import java.util.ArrayList; import java.util.List; -import junit.framework.TestCase; - import org.apache.maven.settings.Mirror; import org.apache.maven.settings.Profile; import org.apache.maven.settings.Proxy; import org.apache.maven.settings.Repository; import org.apache.maven.settings.Server; import org.apache.maven.settings.Settings; -import org.apache.maven.settings.building.SettingsProblemCollector; import org.apache.maven.settings.building.SettingsProblem.Severity; +import org.apache.maven.settings.building.SettingsProblemCollector; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author mkleint */ public class DefaultSettingsValidatorTest - extends TestCase { private DefaultSettingsValidator validator; - protected void setUp() + @BeforeEach + public void setUp() throws Exception { - super.setUp(); - validator = new DefaultSettingsValidator(); } - protected void tearDown() + @AfterEach + public void tearDown() throws Exception { validator = null; - - super.tearDown(); } private void assertContains( String msg, String substring ) { - assertTrue( "\"" + substring + "\" was not found in: " + msg, msg.contains( substring ) ); + assertTrue( msg.contains( substring ), "\"" + substring + "\" was not found in: " + msg ); } + @Test public void testValidate() { Settings model = new Settings(); @@ -90,6 +92,7 @@ public class DefaultSettingsValidatorTest assertEquals( 0, problems.messages.size() ); } + @Test public void testValidateMirror() throws Exception { @@ -112,6 +115,7 @@ public class DefaultSettingsValidatorTest assertContains( problems.messages.get( 3 ), "'mirrors.mirror.id' must not contain any of these characters" ); } + @Test public void testValidateRepository() throws Exception { @@ -137,6 +141,7 @@ public class DefaultSettingsValidatorTest "'profiles.profile[default].repositories.repository.id' must not contain any of these characters" ); } + @Test public void testValidateUniqueServerId() throws Exception { @@ -155,6 +160,7 @@ public class DefaultSettingsValidatorTest "'servers.server.id' must be unique but found duplicate server with id test" ); } + @Test public void testValidateUniqueProfileId() throws Exception { @@ -173,6 +179,7 @@ public class DefaultSettingsValidatorTest "'profiles.profile.id' must be unique but found duplicate profile with id test" ); } + @Test public void testValidateUniqueRepositoryId() throws Exception { @@ -196,6 +203,7 @@ public class DefaultSettingsValidatorTest + " but found duplicate repository with id test" ); } + @Test public void testValidateUniqueProxyId() throws Exception { @@ -215,6 +223,7 @@ public class DefaultSettingsValidatorTest } + @Test public void testValidateProxy() throws Exception { diff --git a/maven-slf4j-provider/src/test/java/org/slf4j/impl/MavenLoggerFactoryTest.java b/maven-slf4j-provider/src/test/java/org/slf4j/impl/MavenLoggerFactoryTest.java index 352d627044..44ac3d2f40 100644 --- a/maven-slf4j-provider/src/test/java/org/slf4j/impl/MavenLoggerFactoryTest.java +++ b/maven-slf4j-provider/src/test/java/org/slf4j/impl/MavenLoggerFactoryTest.java @@ -20,16 +20,17 @@ package org.slf4j.impl; */ import org.apache.maven.logwrapper.LogLevelRecorder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import static org.hamcrest.CoreMatchers.instanceOf; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; public class MavenLoggerFactoryTest { @@ -80,11 +81,12 @@ public class MavenLoggerFactoryTest assertTrue( logLevelRecorder.metThreshold() ); } - @Test( expected = IllegalStateException.class ) + @Test public void failOnSeverityThresholdCanOnlyBeSetOnce() { MavenLoggerFactory mavenLoggerFactory = new MavenLoggerFactory(); mavenLoggerFactory.setLogLevelRecorder( new LogLevelRecorder( "WARN" ) ); - mavenLoggerFactory.setLogLevelRecorder( new LogLevelRecorder( "ERROR" ) ); + assertThrows( IllegalStateException.class, + () -> mavenLoggerFactory.setLogLevelRecorder( new LogLevelRecorder( "ERROR" ) ) ); } } diff --git a/maven-slf4j-wrapper/pom.xml b/maven-slf4j-wrapper/pom.xml index bdb768718c..263113566f 100644 --- a/maven-slf4j-wrapper/pom.xml +++ b/maven-slf4j-wrapper/pom.xml @@ -40,5 +40,10 @@ under the License. org.slf4j slf4j-api + + org.hamcrest + hamcrest-library + test + \ No newline at end of file diff --git a/maven-slf4j-wrapper/src/test/java/org/apache/maven/logwrapper/LogLevelRecorderTest.java b/maven-slf4j-wrapper/src/test/java/org/apache/maven/logwrapper/LogLevelRecorderTest.java index 2bdb8670f7..1e521a90cb 100644 --- a/maven-slf4j-wrapper/src/test/java/org/apache/maven/logwrapper/LogLevelRecorderTest.java +++ b/maven-slf4j-wrapper/src/test/java/org/apache/maven/logwrapper/LogLevelRecorderTest.java @@ -19,13 +19,13 @@ package org.apache.maven.logwrapper; * under the License. */ -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.event.Level; import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; public class LogLevelRecorderTest { @@ -38,10 +38,10 @@ public class LogLevelRecorderTest assertTrue( logLevelRecorder.metThreshold() ); } - @Test( expected = IllegalArgumentException.class ) + @Test public void failsOnLowerThanWarn () { - new LogLevelRecorder( "INFO" ); + assertThrows( IllegalArgumentException.class, () -> new LogLevelRecorder( "INFO" ) ); } @Test diff --git a/maven-test-support/pom.xml b/maven-test-support/pom.xml new file mode 100644 index 0000000000..c051cc4471 --- /dev/null +++ b/maven-test-support/pom.xml @@ -0,0 +1,85 @@ + + + + + + 4.0.0 + + + org.apache.maven + maven + 4.0.0-alpha-1-SNAPSHOT + + + maven-test-support + + Maven Test Support + Test support classes for maven. + + + + org.junit.jupiter + junit-jupiter-engine + ${junitVersion} + + + org.junit.jupiter + junit-jupiter-params + ${junitVersion} + test + + + com.google.inject + guice + no_aop + + + javax.inject + javax.inject + + + org.codehaus.plexus + plexus-utils + + + org.codehaus.plexus + plexus-interpolation + + + org.codehaus.plexus + plexus-cipher + + + org.eclipse.sisu + org.eclipse.sisu.plexus + + + org.codehaus.plexus + plexus-component-annotations + + + org.junit.jupiter + junit-jupiter-params + 5.7.0 + compile + + + + diff --git a/maven-test-support/src/main/java/org/apache/maven/test/Parameter.java b/maven-test-support/src/main/java/org/apache/maven/test/Parameter.java new file mode 100644 index 0000000000..f5164c5eef --- /dev/null +++ b/maven-test-support/src/main/java/org/apache/maven/test/Parameter.java @@ -0,0 +1,32 @@ +package org.apache.maven.test; + +/* + * 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 java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * Parameter + */ +@Retention( RetentionPolicy.RUNTIME ) +public @interface Parameter +{ + int value() default 0; +} diff --git a/maven-test-support/src/main/java/org/apache/maven/test/Parameterized.java b/maven-test-support/src/main/java/org/apache/maven/test/Parameterized.java new file mode 100644 index 0000000000..a15fbaf1f6 --- /dev/null +++ b/maven-test-support/src/main/java/org/apache/maven/test/Parameterized.java @@ -0,0 +1,37 @@ +package org.apache.maven.test; + +/* + * 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 java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.junit.jupiter.api.extension.ExtendWith; + +/** + * Parameterized + */ +@Target( { ElementType.ANNOTATION_TYPE, ElementType.TYPE } ) +@Retention( RetentionPolicy.RUNTIME ) +@ExtendWith( ParameterizedExtension.class ) +public @interface Parameterized +{ +} diff --git a/maven-test-support/src/main/java/org/apache/maven/test/ParameterizedExtension.java b/maven-test-support/src/main/java/org/apache/maven/test/ParameterizedExtension.java new file mode 100644 index 0000000000..5741db49db --- /dev/null +++ b/maven-test-support/src/main/java/org/apache/maven/test/ParameterizedExtension.java @@ -0,0 +1,182 @@ +package org.apache.maven.test; + +/* + * 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 java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.junit.jupiter.api.extension.Extension; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.TestInstancePostProcessor; +import org.junit.jupiter.api.extension.TestInstantiationException; +import org.junit.jupiter.api.extension.TestTemplateInvocationContext; +import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider; +import org.junit.jupiter.params.converter.DefaultArgumentConverter; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.platform.commons.util.CollectionUtils; +import org.junit.platform.commons.util.ReflectionUtils; + +import static org.junit.jupiter.params.provider.Arguments.arguments; +import static org.junit.platform.commons.util.AnnotationUtils.isAnnotated; + +/** + * ParameterizedExtension + */ +public class ParameterizedExtension implements TestTemplateInvocationContextProvider +{ + + @Override + public boolean supportsTestTemplate( ExtensionContext context ) + { + return context.getTestMethod() + .map( m -> isAnnotated( m, Test.class ) ) + .orElse( false ); + } + + @Override + public Stream provideTestTemplateInvocationContexts( + ExtensionContext extensionContext ) + { + Class testClass = extensionContext.getRequiredTestClass(); + try + { + List parameters = getParametersMethods( testClass ); + if ( parameters.size() != 1 ) + { + throw new IllegalStateException( + "Class " + testClass.getName() + " should provide a single method annotated with @" + + Parameters.class.getSimpleName() ); + } + Object params = parameters.iterator().next().invoke( null ); + return CollectionUtils.toStream( params ) + .map( ParameterizedExtension::toArguments ) + .map( Arguments::get ) + .map( ParameterizedTemplate::new ); + } + catch ( Exception e ) + { + throw new IllegalStateException( "Unable to generate test templates for class " + testClass.getName(), e ); + } + } + + private List getParametersMethods( Class testClass ) + { + List parameters = Stream.of( testClass.getDeclaredMethods() ) + .filter( m -> Modifier.isStatic( m.getModifiers() ) ) + .filter( m -> m.getAnnotation( Parameters.class ) != null ) + .collect( Collectors.toList() ); + if ( parameters.isEmpty() && testClass != null ) + { + return getParametersMethods( testClass.getSuperclass() ); + } + else + { + return parameters; + } + } + + private static Arguments toArguments( Object item ) + { + // Nothing to do except cast. + if ( item instanceof Arguments ) + { + return ( Arguments ) item; + } + // Pass all multidimensional arrays "as is", in contrast to Object[]. + // See https://github.com/junit-team/junit5/issues/1665 + if ( ReflectionUtils.isMultidimensionalArray( item ) ) + { + return arguments( item ); + } + // Special treatment for one-dimensional reference arrays. + // See https://github.com/junit-team/junit5/issues/1665 + if ( item instanceof Object[] ) + { + return arguments( ( Object[] ) item ); + } + // Pass everything else "as is". + return arguments( item ); + } + + /** + * ParameterizedTemplate + */ + public static class ParameterizedTemplate implements TestTemplateInvocationContext + { + + private final Object[] params; + + public ParameterizedTemplate( Object[] params ) + { + this.params = params; + } + + @Override + public String getDisplayName( int invocationIndex ) + { + return "[" + invocationIndex + "] " + + Stream.of( params ).map( Object::toString ).collect( Collectors.joining( ", " ) ); + } + + @Override + public List getAdditionalExtensions() + { + return Arrays.asList( + ( TestInstancePostProcessor ) this::postProcessTestInstance ); + } + + protected void postProcessTestInstance( Object testInstance, ExtensionContext context ) throws Exception + { + Class clazz = testInstance.getClass(); + List fields = hierarchy( clazz ) + .map( Class::getDeclaredFields ) + .flatMap( Stream::of ) + .filter( f -> isAnnotated( f, Parameter.class ) ) + .sorted( Comparator.comparing( f -> ( Integer ) f.getAnnotation( Parameter.class ).value() ) ) + .collect( Collectors.toList() ); + if ( params.length != fields.size() ) + { + throw new TestInstantiationException( + "Expected " + fields.size() + " parameters bug got " + params.length + " when instantiating " + + clazz.getName() ); + } + for ( int i = 0; i < fields.size(); i++ ) + { + Field f = fields.get( i ); + f.setAccessible( true ); + f.set( testInstance, DefaultArgumentConverter.INSTANCE.convert( params[i], f.getType() ) ); + } + } + + protected Stream> hierarchy( Class clazz ) + { + Class superclass = clazz.getSuperclass(); + return Stream.concat( Stream.of( clazz ), superclass != null ? hierarchy( superclass ) : Stream.empty() ); + } + + } + +} diff --git a/maven-test-support/src/main/java/org/apache/maven/test/Parameters.java b/maven-test-support/src/main/java/org/apache/maven/test/Parameters.java new file mode 100644 index 0000000000..b643a3a98f --- /dev/null +++ b/maven-test-support/src/main/java/org/apache/maven/test/Parameters.java @@ -0,0 +1,35 @@ +package org.apache.maven.test; + +/* + * 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 java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Parameters + */ +@Retention( RetentionPolicy.RUNTIME ) +@Target( ElementType.METHOD ) +public @interface Parameters +{ + String name() default "{index}"; +} diff --git a/maven-test-support/src/main/java/org/apache/maven/test/PlexusTestCase.java b/maven-test-support/src/main/java/org/apache/maven/test/PlexusTestCase.java new file mode 100644 index 0000000000..91dc25e15f --- /dev/null +++ b/maven-test-support/src/main/java/org/apache/maven/test/PlexusTestCase.java @@ -0,0 +1,325 @@ +package org.apache.maven.test; + +/* + * 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. + */ + +/* + * Copyright 2001-2006 Codehaus Foundation. + * + * Licensed 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 java.io.File; +import java.io.InputStream; +import java.util.Collections; + +import org.codehaus.plexus.ContainerConfiguration; +import org.codehaus.plexus.DefaultContainerConfiguration; +import org.codehaus.plexus.DefaultPlexusContainer; +import org.codehaus.plexus.PlexusConstants; +import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.PlexusContainerException; +import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; +import org.codehaus.plexus.configuration.PlexusConfiguration; +import org.codehaus.plexus.context.Context; +import org.codehaus.plexus.context.DefaultContext; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; + +/** + * This is a slightly modified version of the original plexus class + * available at https://raw.githubusercontent.com/codehaus-plexus/plexus-containers/master/plexus-container-default/ + * src/main/java/org/codehaus/plexus/PlexusTestCase.java + * in order to migrate the tests to JUnit 4. + * + * @author Jason van Zyl + * @author Trygve Laugstøl + * @author Michal Maczka + * @author Guillaume Nodet + */ +public abstract class PlexusTestCase +{ + private PlexusContainer container; + + private static String basedir; + + @BeforeEach + public void setUp() + throws Exception + { + basedir = getBasedir(); + + ( (DefaultPlexusContainer) getContainer() ).addPlexusInjector( Collections.emptyList(), + binder -> binder.requestInjection( this ) ); + } + + @SuppressWarnings( "ResultOfMethodCallIgnored" ) + protected void setupContainer() + { + // ---------------------------------------------------------------------------- + // Context Setup + // ---------------------------------------------------------------------------- + + DefaultContext context = new DefaultContext(); + + context.put( "basedir", getBasedir() ); + + customizeContext( context ); + + boolean hasPlexusHome = context.contains( "plexus.home" ); + + if ( !hasPlexusHome ) + { + File f = getTestFile( "target/plexus-home" ); + + if ( !f.isDirectory() ) + { + f.mkdir(); + } + + context.put( "plexus.home", f.getAbsolutePath() ); + } + + // ---------------------------------------------------------------------------- + // Configuration + // ---------------------------------------------------------------------------- + + String config = getCustomConfigurationName(); + + ContainerConfiguration containerConfiguration = new DefaultContainerConfiguration() + .setName( "test" ) + .setContext( context.getContextData() ); + + if ( config != null ) + { + containerConfiguration.setContainerConfiguration( config ); + } + else + { + String resource = getConfigurationName( null ); + + containerConfiguration.setContainerConfiguration( resource ); + } + + customizeContainerConfiguration( containerConfiguration ); + + try + { + container = new DefaultPlexusContainer( containerConfiguration ); + } + catch ( PlexusContainerException e ) + { + throw new IllegalArgumentException( "Failed to create plexus container.", e ); + } + } + + /** + * Allow custom test case implementations do augment the default container configuration before + * executing tests. + * + * @param containerConfiguration {@link ContainerConfiguration}. + */ + protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration ) + { + containerConfiguration.setAutoWiring( true ); + containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); + } + + protected void customizeContext( Context context ) + { + } + + protected PlexusConfiguration customizeComponentConfiguration() + { + return null; + } + + @AfterEach + public void tearDown() + throws Exception + { + if ( container != null ) + { + container.dispose(); + + container = null; + } + } + + protected PlexusContainer getContainer() + { + if ( container == null ) + { + setupContainer(); + } + + return container; + } + + protected InputStream getConfiguration() + throws Exception + { + return getConfiguration( null ); + } + + protected InputStream getConfiguration( String subname ) + throws Exception + { + return getResourceAsStream( getConfigurationName( subname ) ); + } + + protected String getCustomConfigurationName() + { + return null; + } + + /** + * Allow the retrieval of a container configuration that is based on the name + * of the test class being run. So if you have a test class called org.foo.FunTest, then + * this will produce a resource name of org/foo/FunTest.xml which would be used to + * configure the Plexus container before running your test. + * + * @param subname the subname + * @return A configruation name + */ + protected String getConfigurationName( String subname ) + { + return getClass().getName().replace( '.', '/' ) + ".xml"; + } + + protected InputStream getResourceAsStream( String resource ) + { + return getClass().getResourceAsStream( resource ); + } + + protected ClassLoader getClassLoader() + { + return getClass().getClassLoader(); + } + + // ---------------------------------------------------------------------- + // Container access + // ---------------------------------------------------------------------- + + @SuppressWarnings( "unchecked" ) + protected T lookup( String componentKey ) + throws ComponentLookupException + { + return (T) getContainer().lookup( componentKey ); + } + + @SuppressWarnings( "unchecked" ) + protected T lookup( String role, + String roleHint ) + throws ComponentLookupException + { + return (T) getContainer().lookup( role, roleHint ); + } + + protected T lookup( Class componentClass ) + throws ComponentLookupException + { + return getContainer().lookup( componentClass ); + } + + protected T lookup( Class componentClass, String roleHint ) + throws ComponentLookupException + { + return getContainer().lookup( componentClass, roleHint ); + } + + protected void release( Object component ) + throws ComponentLifecycleException + { + getContainer().release( component ); + } + + // ---------------------------------------------------------------------- + // Helper methods for sub classes + // ---------------------------------------------------------------------- + + public static File getTestFile( String path ) + { + return new File( getBasedir(), path ); + } + + public static File getTestFile( String basedir, + String path ) + { + File basedirFile = new File( basedir ); + + if ( !basedirFile.isAbsolute() ) + { + basedirFile = getTestFile( basedir ); + } + + return new File( basedirFile, path ); + } + + public static String getTestPath( String path ) + { + return getTestFile( path ).getAbsolutePath(); + } + + public static String getTestPath( String basedir, + String path ) + { + return getTestFile( basedir, path ).getAbsolutePath(); + } + + public static String getBasedir() + { + if ( basedir != null ) + { + return basedir; + } + + basedir = System.getProperty( "basedir" ); + + if ( basedir == null ) + { + basedir = new File( "" ).getAbsolutePath(); + } + + return basedir; + } + + public String getTestConfiguration() + { + return getTestConfiguration( getClass() ); + } + + public static String getTestConfiguration( Class clazz ) + { + String s = clazz.getName().replace( '.', '/' ); + + return s.substring( 0, s.indexOf( "$" ) ) + ".xml"; + } +} diff --git a/maven-test-support/src/main/java/org/apache/maven/test/Test.java b/maven-test-support/src/main/java/org/apache/maven/test/Test.java new file mode 100644 index 0000000000..5b542b6638 --- /dev/null +++ b/maven-test-support/src/main/java/org/apache/maven/test/Test.java @@ -0,0 +1,34 @@ +package org.apache.maven.test; + +/* + * 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 java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import org.junit.jupiter.api.TestTemplate; + +/** + * Test + */ +@Retention( RetentionPolicy.RUNTIME ) +@TestTemplate +public @interface Test +{ +} diff --git a/maven-wrapper/src/test/java/org/apache/maven/wrapper/DownloaderTest.java b/maven-wrapper/src/test/java/org/apache/maven/wrapper/DownloaderTest.java index 68bc5c61f1..c0e84c7b72 100644 --- a/maven-wrapper/src/test/java/org/apache/maven/wrapper/DownloaderTest.java +++ b/maven-wrapper/src/test/java/org/apache/maven/wrapper/DownloaderTest.java @@ -19,7 +19,7 @@ package org.apache.maven.wrapper; * under the License. */ -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.net.URI; import java.nio.file.Files; @@ -27,15 +27,14 @@ import java.nio.file.Path; import java.util.Arrays; import java.util.stream.Collectors; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; public class DownloaderTest { - @Rule - public TemporaryFolder testDir = new TemporaryFolder(); + @TempDir + public Path testDir; private DefaultDownloader download; @@ -47,14 +46,14 @@ public class DownloaderTest private Path remoteFile; - @Before + @BeforeEach public void setUp() throws Exception { download = new DefaultDownloader( "mvnw", "aVersion" ); - rootDir = testDir.newFolder( "root" ).toPath(); + rootDir = testDir.resolve( "root" ); downloadFile = rootDir.resolve( "file" ); - remoteFile = testDir.newFile( "remoteFile" ).toPath(); + remoteFile = testDir.resolve( "remoteFile" ); Files.write( remoteFile, Arrays.asList( "sometext" ) ); sourceRoot = remoteFile.toUri(); } diff --git a/maven-wrapper/src/test/java/org/apache/maven/wrapper/InstallerTest.java b/maven-wrapper/src/test/java/org/apache/maven/wrapper/InstallerTest.java index 3ff712a429..bef2057587 100644 --- a/maven-wrapper/src/test/java/org/apache/maven/wrapper/InstallerTest.java +++ b/maven-wrapper/src/test/java/org/apache/maven/wrapper/InstallerTest.java @@ -31,18 +31,18 @@ import java.util.Arrays; import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.Zip; import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; /** * @author Hans Dockter */ public class InstallerTest { - @Rule - public TemporaryFolder temporaryFolder = new TemporaryFolder(); + @TempDir + public Path temporaryFolder; private Installer install; @@ -62,7 +62,7 @@ public class InstallerTest private PathAssembler.LocalDistribution localDistribution; - @Before + @BeforeEach public void setup() throws Exception { @@ -73,9 +73,11 @@ public class InstallerTest configuration.setDistribution( new URI( "http://server/maven-0.9.zip" ) ); configuration.setAlwaysDownload( false ); configuration.setAlwaysUnpack( false ); - distributionDir = temporaryFolder.newFolder( "someDistPath" ).toPath(); + distributionDir = temporaryFolder.resolve( "someDistPath" ); + Files.createDirectories( distributionDir ); mavenHomeDir = distributionDir.resolve( "maven-0.9" ); - zipStore = temporaryFolder.newFolder( "zips" ).toPath(); + zipStore = temporaryFolder.resolve( "zips" ); + Files.createDirectories( zipStore ); zipDestination = zipStore.resolve( "maven-0.9.zip" ); download = mock( Downloader.class ); @@ -94,7 +96,7 @@ public class InstallerTest { Files.createDirectories( zipDestination.getParent() ); - Path explodedZipDir = temporaryFolder.newFolder( "explodedZip" ).toPath(); + Path explodedZipDir = temporaryFolder.resolve( "explodedZip" ); Path mavenScript = explodedZipDir.resolve( "maven-0.9/bin/mvn" ); Files.createDirectories( mavenScript.getParent() ); @@ -103,6 +105,8 @@ public class InstallerTest zipTo( explodedZipDir, zipDestination ); } + @Test + @Disabled("not working") public void testCreateDist() throws Exception { diff --git a/maven-wrapper/src/test/java/org/apache/maven/wrapper/PathAssemblerTest.java b/maven-wrapper/src/test/java/org/apache/maven/wrapper/PathAssemblerTest.java index 9e22be0ea6..a2334c1397 100644 --- a/maven-wrapper/src/test/java/org/apache/maven/wrapper/PathAssemblerTest.java +++ b/maven-wrapper/src/test/java/org/apache/maven/wrapper/PathAssemblerTest.java @@ -22,20 +22,15 @@ package org.apache.maven.wrapper; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; -import java.io.File; import java.net.URI; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.regex.Pattern; -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; -import org.hamcrest.Matcher; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * @author Hans Dockter @@ -48,7 +43,7 @@ public class PathAssemblerTest final WrapperConfiguration configuration = new WrapperConfiguration(); - @Before + @BeforeEach public void setup() { configuration.setDistributionBase( PathAssembler.MAVEN_USER_HOME_STRING ); diff --git a/maven-wrapper/src/test/java/org/apache/maven/wrapper/WrapperExecutorTest.java b/maven-wrapper/src/test/java/org/apache/maven/wrapper/WrapperExecutorTest.java index b160be0352..23bcf21e43 100644 --- a/maven-wrapper/src/test/java/org/apache/maven/wrapper/WrapperExecutorTest.java +++ b/maven-wrapper/src/test/java/org/apache/maven/wrapper/WrapperExecutorTest.java @@ -19,6 +19,11 @@ package org.apache.maven.wrapper; * under the License. */ +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -30,17 +35,15 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Properties; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.mockito.Mockito; public class WrapperExecutorTest { - @Rule - public TemporaryFolder testDir = new TemporaryFolder(); + @TempDir + public Path testDir; private Installer install; @@ -52,17 +55,17 @@ public class WrapperExecutorTest private Path mockInstallDir; - @Before + @BeforeEach public void setUp() throws Exception { - mockInstallDir = testDir.newFolder( "mock-dir" ).toPath(); + mockInstallDir = testDir.resolve( "mock-dir" ); install = mock( Installer.class ); when( install.createDist( Mockito.any( WrapperConfiguration.class ) ) ).thenReturn( mockInstallDir ); start = mock( BootstrapMainStarter.class ); - propertiesFile = testDir.newFolder( "maven", "wrapper" ).toPath().resolve( "maven-wrapper.properties" ); + propertiesFile = testDir.resolve( "maven" ).resolve( "wrapper" ).resolve( "maven-wrapper.properties" ); properties.put( "distributionUrl", "http://server/test/maven.zip" ); properties.put( "distributionBase", "testDistBase" ); @@ -79,40 +82,40 @@ public class WrapperExecutorTest { WrapperExecutor wrapper = WrapperExecutor.forWrapperPropertiesFile( propertiesFile ); - Assert.assertEquals( new URI( "http://server/test/maven.zip" ), wrapper.getDistribution() ); - Assert.assertEquals( new URI( "http://server/test/maven.zip" ), wrapper.getConfiguration().getDistribution() ); - Assert.assertEquals( "testDistBase", wrapper.getConfiguration().getDistributionBase() ); - Assert.assertEquals( "testDistPath", wrapper.getConfiguration().getDistributionPath() ); - Assert.assertEquals( "testZipBase", wrapper.getConfiguration().getZipBase() ); - Assert.assertEquals( "testZipPath", wrapper.getConfiguration().getZipPath() ); + assertEquals( new URI( "http://server/test/maven.zip" ), wrapper.getDistribution() ); + assertEquals( new URI( "http://server/test/maven.zip" ), wrapper.getConfiguration().getDistribution() ); + assertEquals( "testDistBase", wrapper.getConfiguration().getDistributionBase() ); + assertEquals( "testDistPath", wrapper.getConfiguration().getDistributionPath() ); + assertEquals( "testZipBase", wrapper.getConfiguration().getZipBase() ); + assertEquals( "testZipPath", wrapper.getConfiguration().getZipPath() ); } @Test public void loadWrapperMetadataFromDirectory() throws Exception { - WrapperExecutor wrapper = WrapperExecutor.forProjectDirectory( testDir.getRoot().toPath() ); + WrapperExecutor wrapper = WrapperExecutor.forProjectDirectory( testDir ); - Assert.assertEquals( new URI( "http://server/test/maven.zip" ), wrapper.getDistribution() ); - Assert.assertEquals( new URI( "http://server/test/maven.zip" ), wrapper.getConfiguration().getDistribution() ); - Assert.assertEquals( "testDistBase", wrapper.getConfiguration().getDistributionBase() ); - Assert.assertEquals( "testDistPath", wrapper.getConfiguration().getDistributionPath() ); - Assert.assertEquals( "testZipBase", wrapper.getConfiguration().getZipBase() ); - Assert.assertEquals( "testZipPath", wrapper.getConfiguration().getZipPath() ); + assertEquals( new URI( "http://server/test/maven.zip" ), wrapper.getDistribution() ); + assertEquals( new URI( "http://server/test/maven.zip" ), wrapper.getConfiguration().getDistribution() ); + assertEquals( "testDistBase", wrapper.getConfiguration().getDistributionBase() ); + assertEquals( "testDistPath", wrapper.getConfiguration().getDistributionPath() ); + assertEquals( "testZipBase", wrapper.getConfiguration().getZipBase() ); + assertEquals( "testZipPath", wrapper.getConfiguration().getZipPath() ); } @Test public void useDefaultMetadataNoProeprtiesFile() throws Exception { - WrapperExecutor wrapper = WrapperExecutor.forProjectDirectory( testDir.getRoot().toPath().resolve( "unknown" ) ); + WrapperExecutor wrapper = WrapperExecutor.forProjectDirectory( testDir.resolve( "unknown" ) ); - Assert.assertNull( wrapper.getDistribution() ); - Assert.assertNull( wrapper.getConfiguration().getDistribution() ); - Assert.assertEquals( PathAssembler.MAVEN_USER_HOME_STRING, wrapper.getConfiguration().getDistributionBase() ); - Assert.assertEquals( Installer.DEFAULT_DISTRIBUTION_PATH, wrapper.getConfiguration().getDistributionPath() ); - Assert.assertEquals( PathAssembler.MAVEN_USER_HOME_STRING, wrapper.getConfiguration().getZipBase() ); - Assert.assertEquals( Installer.DEFAULT_DISTRIBUTION_PATH, wrapper.getConfiguration().getZipPath() ); + assertNull( wrapper.getDistribution() ); + assertNull( wrapper.getConfiguration().getDistribution() ); + assertEquals( PathAssembler.MAVEN_USER_HOME_STRING, wrapper.getConfiguration().getDistributionBase() ); + assertEquals( Installer.DEFAULT_DISTRIBUTION_PATH, wrapper.getConfiguration().getDistributionPath() ); + assertEquals( PathAssembler.MAVEN_USER_HOME_STRING, wrapper.getConfiguration().getZipBase() ); + assertEquals( Installer.DEFAULT_DISTRIBUTION_PATH, wrapper.getConfiguration().getZipPath() ); } @Test @@ -126,12 +129,12 @@ public class WrapperExecutorTest WrapperExecutor wrapper = WrapperExecutor.forWrapperPropertiesFile( propertiesFile ); - Assert.assertEquals( new URI( "http://server/test/maven.zip" ), wrapper.getDistribution() ); - Assert.assertEquals( new URI( "http://server/test/maven.zip" ), wrapper.getConfiguration().getDistribution() ); - Assert.assertEquals( PathAssembler.MAVEN_USER_HOME_STRING, wrapper.getConfiguration().getDistributionBase() ); - Assert.assertEquals( Installer.DEFAULT_DISTRIBUTION_PATH, wrapper.getConfiguration().getDistributionPath() ); - Assert.assertEquals( PathAssembler.MAVEN_USER_HOME_STRING, wrapper.getConfiguration().getZipBase() ); - Assert.assertEquals( Installer.DEFAULT_DISTRIBUTION_PATH, wrapper.getConfiguration().getZipPath() ); + assertEquals( new URI( "http://server/test/maven.zip" ), wrapper.getDistribution() ); + assertEquals( new URI( "http://server/test/maven.zip" ), wrapper.getConfiguration().getDistribution() ); + assertEquals( PathAssembler.MAVEN_USER_HOME_STRING, wrapper.getConfiguration().getDistributionBase() ); + assertEquals( Installer.DEFAULT_DISTRIBUTION_PATH, wrapper.getConfiguration().getDistributionPath() ); + assertEquals( PathAssembler.MAVEN_USER_HOME_STRING, wrapper.getConfiguration().getZipBase() ); + assertEquals( Installer.DEFAULT_DISTRIBUTION_PATH, wrapper.getConfiguration().getZipPath() ); } @Test @@ -152,32 +155,24 @@ public class WrapperExecutorTest properties = new Properties(); writePropertiesFile( properties, propertiesFile, "header" ); - try - { - WrapperExecutor.forWrapperPropertiesFile( propertiesFile ); - Assert.fail( "Expected RuntimeException" ); - } - catch ( RuntimeException e ) - { - Assert.assertEquals( "No value with key 'distributionUrl' specified in wrapper properties file '" - + propertiesFile + "'.", e.getMessage() ); - } + RuntimeException e = assertThrows( + RuntimeException.class, + () -> WrapperExecutor.forWrapperPropertiesFile( propertiesFile ), + "Expected RuntimeException" ); + assertEquals( "No value with key 'distributionUrl' specified in wrapper properties file '" + + propertiesFile + "'.", e.getMessage() ); } @Test public void failWhenPropertiesFileDoesNotExist() { - propertiesFile = testDir.getRoot().toPath().resolve( "unknown.properties" ); + propertiesFile = testDir.resolve( "unknown.properties" ); - try - { - WrapperExecutor.forWrapperPropertiesFile( propertiesFile ); - Assert.fail( "Expected RuntimeException" ); - } - catch ( RuntimeException e ) - { - Assert.assertEquals( "Wrapper properties file '" + propertiesFile + "' does not exist.", e.getMessage() ); - } + RuntimeException e = assertThrows( + RuntimeException.class, + () -> WrapperExecutor.forWrapperPropertiesFile( propertiesFile ), + "Expected RuntimeException" ); + assertEquals( "Wrapper properties file '" + propertiesFile + "' does not exist.", e.getMessage() ); } @Test @@ -190,8 +185,8 @@ public class WrapperExecutorTest writePropertiesFile( properties, propertiesFile, "header" ); WrapperExecutor wrapper = WrapperExecutor.forWrapperPropertiesFile( propertiesFile ); - Assert.assertNotEquals( "some/relative/url/to/bin.zip", wrapper.getDistribution().getSchemeSpecificPart() ); - Assert.assertTrue( wrapper.getDistribution().getSchemeSpecificPart().endsWith( "some/relative/url/to/bin.zip" ) ); + assertNotEquals( "some/relative/url/to/bin.zip", wrapper.getDistribution().getSchemeSpecificPart() ); + assertTrue( wrapper.getDistribution().getSchemeSpecificPart().endsWith( "some/relative/url/to/bin.zip" ) ); } private void writePropertiesFile( Properties properties, Path propertiesFile, String message ) diff --git a/maven-xml/pom.xml b/maven-xml/pom.xml index 7995e98548..600c2b9cf4 100644 --- a/maven-xml/pom.xml +++ b/maven-xml/pom.xml @@ -32,6 +32,11 @@ under the License. Maven XML + + org.apache.maven + maven-test-support + test + org.xmlunit xmlunit-assertj diff --git a/maven-xml/src/test/java/org/apache/maven/xml/sax/ChainedFilterTest.java b/maven-xml/src/test/java/org/apache/maven/xml/sax/ChainedFilterTest.java index 47ac4562a1..e9b10c9ba6 100644 --- a/maven-xml/src/test/java/org/apache/maven/xml/sax/ChainedFilterTest.java +++ b/maven-xml/src/test/java/org/apache/maven/xml/sax/ChainedFilterTest.java @@ -34,7 +34,7 @@ import javax.xml.transform.stream.StreamResult; import org.apache.maven.xml.Factories; import org.apache.maven.xml.sax.filter.AbstractSAXFilter; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xml.sax.InputSource; import org.xml.sax.SAXException; diff --git a/maven-xml/src/test/java/org/apache/maven/xml/sax/SAXEventUtilsTest.java b/maven-xml/src/test/java/org/apache/maven/xml/sax/SAXEventUtilsTest.java index 02e55dc599..048ee845f8 100644 --- a/maven-xml/src/test/java/org/apache/maven/xml/sax/SAXEventUtilsTest.java +++ b/maven-xml/src/test/java/org/apache/maven/xml/sax/SAXEventUtilsTest.java @@ -19,13 +19,10 @@ package org.apache.maven.xml.sax; * under the License. */ -import static org.junit.Assert.assertThat; - -import org.apache.maven.xml.sax.SAXEventUtils; - +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.CoreMatchers.is; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class SAXEventUtilsTest { diff --git a/maven-xml/src/test/java/org/apache/maven/xml/sax/ext/CommentRenormalizerTest.java b/maven-xml/src/test/java/org/apache/maven/xml/sax/ext/CommentRenormalizerTest.java index c1885e216b..dad847e129 100644 --- a/maven-xml/src/test/java/org/apache/maven/xml/sax/ext/CommentRenormalizerTest.java +++ b/maven-xml/src/test/java/org/apache/maven/xml/sax/ext/CommentRenormalizerTest.java @@ -25,18 +25,19 @@ import static org.mockito.Mockito.verify; import java.util.Arrays; import java.util.Collection; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.apache.maven.test.Parameter; +import org.apache.maven.test.Parameterized; +import org.apache.maven.test.Parameters; +import org.apache.maven.test.Test; import org.xml.sax.ext.LexicalHandler; -@RunWith( Parameterized.class ) +@Parameterized public class CommentRenormalizerTest { - private LexicalHandler lexicalHandler; + private LexicalHandler lexicalHandler = mock( LexicalHandler.class ); - private final String lineSeparator; + @Parameter + private String lineSeparator; @Parameters public static Collection data() { @@ -47,12 +48,6 @@ public class CommentRenormalizerTest }); } - public CommentRenormalizerTest( String lineSeparator ) - { - this.lineSeparator = lineSeparator; - this.lexicalHandler = mock( LexicalHandler.class ); - } - @Test public void singleLine() throws Exception diff --git a/maven-xml/src/test/java/org/apache/maven/xml/sax/filter/CiFriendlyXMLFilterTest.java b/maven-xml/src/test/java/org/apache/maven/xml/sax/filter/CiFriendlyXMLFilterTest.java index e51b76db35..d83617e41d 100644 --- a/maven-xml/src/test/java/org/apache/maven/xml/sax/filter/CiFriendlyXMLFilterTest.java +++ b/maven-xml/src/test/java/org/apache/maven/xml/sax/filter/CiFriendlyXMLFilterTest.java @@ -19,20 +19,21 @@ package org.apache.maven.xml.sax.filter; * under the License. */ -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.TransformerException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.BeforeEach; + import org.xml.sax.SAXException; public class CiFriendlyXMLFilterTest extends AbstractXMLFilterTests { private CiFriendlyXMLFilter filter; - @Before + @BeforeEach public void setUp() { filter = new CiFriendlyXMLFilter( true ); diff --git a/maven-xml/src/test/java/org/apache/maven/xml/sax/filter/ConsumerPomXMLFilterTest.java b/maven-xml/src/test/java/org/apache/maven/xml/sax/filter/ConsumerPomXMLFilterTest.java index 300246ae66..df81175ce0 100644 --- a/maven-xml/src/test/java/org/apache/maven/xml/sax/filter/ConsumerPomXMLFilterTest.java +++ b/maven-xml/src/test/java/org/apache/maven/xml/sax/filter/ConsumerPomXMLFilterTest.java @@ -31,7 +31,7 @@ import java.util.function.Function; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.TransformerConfigurationException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xml.sax.SAXException; import org.xml.sax.ext.LexicalHandler; diff --git a/maven-xml/src/test/java/org/apache/maven/xml/sax/filter/ModulesXMLFilterTest.java b/maven-xml/src/test/java/org/apache/maven/xml/sax/filter/ModulesXMLFilterTest.java index fac2b79fe9..301e316427 100644 --- a/maven-xml/src/test/java/org/apache/maven/xml/sax/filter/ModulesXMLFilterTest.java +++ b/maven-xml/src/test/java/org/apache/maven/xml/sax/filter/ModulesXMLFilterTest.java @@ -23,7 +23,7 @@ import static org.xmlunit.assertj.XmlAssert.assertThat; import java.util.function.Consumer; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xml.sax.ext.LexicalHandler; public class ModulesXMLFilterTest extends AbstractXMLFilterTests { diff --git a/maven-xml/src/test/java/org/apache/maven/xml/sax/filter/ParentXMLFilterTest.java b/maven-xml/src/test/java/org/apache/maven/xml/sax/filter/ParentXMLFilterTest.java index 809aef5e08..222e11fb40 100644 --- a/maven-xml/src/test/java/org/apache/maven/xml/sax/filter/ParentXMLFilterTest.java +++ b/maven-xml/src/test/java/org/apache/maven/xml/sax/filter/ParentXMLFilterTest.java @@ -19,7 +19,7 @@ package org.apache.maven.xml.sax.filter; * under the License. */ -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.nio.file.Paths; import java.util.Optional; @@ -28,7 +28,7 @@ import java.util.function.Consumer; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.TransformerException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xml.sax.SAXException; import org.xml.sax.ext.LexicalHandler; diff --git a/maven-xml/src/test/java/org/apache/maven/xml/sax/filter/ReactorDependencyXMLFilterTest.java b/maven-xml/src/test/java/org/apache/maven/xml/sax/filter/ReactorDependencyXMLFilterTest.java index 21a1742699..d9385033cf 100644 --- a/maven-xml/src/test/java/org/apache/maven/xml/sax/filter/ReactorDependencyXMLFilterTest.java +++ b/maven-xml/src/test/java/org/apache/maven/xml/sax/filter/ReactorDependencyXMLFilterTest.java @@ -25,7 +25,7 @@ import java.util.function.Consumer; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.TransformerException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xml.sax.SAXException; import org.xml.sax.ext.LexicalHandler; diff --git a/maven-xml/src/test/java/org/apache/maven/xml/sax/filter/RelativePathXMLFilterTest.java b/maven-xml/src/test/java/org/apache/maven/xml/sax/filter/RelativePathXMLFilterTest.java index 51ee41d215..16282667f3 100644 --- a/maven-xml/src/test/java/org/apache/maven/xml/sax/filter/RelativePathXMLFilterTest.java +++ b/maven-xml/src/test/java/org/apache/maven/xml/sax/filter/RelativePathXMLFilterTest.java @@ -21,8 +21,7 @@ package org.apache.maven.xml.sax.filter; import static org.xmlunit.assertj.XmlAssert.assertThat; -import org.apache.maven.xml.sax.filter.RelativePathXMLFilter; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class RelativePathXMLFilterTest extends AbstractXMLFilterTests { diff --git a/pom.xml b/pom.xml index 23f976f2a9..07aa46add8 100644 --- a/pom.xml +++ b/pom.xml @@ -52,7 +52,7 @@ under the License. 2.6.0 1.4 3.8.1 - 4.13.1 + 5.7.0 3.2.0 2.1.0 1.26 @@ -80,6 +80,7 @@ under the License. + maven-test-support maven-plugin-api maven-builder-support maven-model @@ -181,6 +182,11 @@ under the License. + + org.apache.maven + maven-test-support + ${project.version} + org.apache.maven maven-model @@ -468,11 +474,16 @@ under the License. - junit - junit + org.junit.jupiter + junit-jupiter-engine ${junitVersion} test + + org.hamcrest + hamcrest-core + test +