diff --git a/core-it-suite/pom.xml b/core-it-suite/pom.xml index 3e225ee7b..e3b8be7a3 100644 --- a/core-it-suite/pom.xml +++ b/core-it-suite/pom.xml @@ -88,17 +88,10 @@ under the License. - junit - junit - 4.12 + org.junit.jupiter + junit-jupiter - - org.hamcrest - hamcrest-all - 1.3 - test - org.codehaus.plexus plexus-utils @@ -166,9 +159,10 @@ under the License. maven-surefire-plugin - **/IntegrationTestSuite.java + **/MavenIT*.java - never + 0 + true true @@ -318,7 +312,8 @@ under the License. maven-surefire-plugin false - once + 1 + true ${surefireMemory} -Dcom.sun.management.jmxremote=true diff --git a/core-it-support/core-it-plugins/maven-it-plugin-class-loader/maven-it-plugin-class-loader/src/test/java/org/apache/maven/plugin/coreit/ExpressionUtilTest.java b/core-it-support/core-it-plugins/maven-it-plugin-class-loader/maven-it-plugin-class-loader/src/test/java/org/apache/maven/plugin/coreit/ExpressionUtilTest.java index 53c5e97a9..b1920f86c 100644 --- a/core-it-support/core-it-plugins/maven-it-plugin-class-loader/maven-it-plugin-class-loader/src/test/java/org/apache/maven/plugin/coreit/ExpressionUtilTest.java +++ b/core-it-support/core-it-plugins/maven-it-plugin-class-loader/maven-it-plugin-class-loader/src/test/java/org/apache/maven/plugin/coreit/ExpressionUtilTest.java @@ -19,29 +19,33 @@ * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Map; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; + /** * @author Benjamin Bentmann * */ public class ExpressionUtilTest - extends TestCase { + @Test public void testEvaluate() { Object array = new String[]{ "one", "two", "three" }; - Object list = Arrays.asList( new String[]{ "0", "-1", "-2" } ); + Object list = Arrays.asList( "0", "-1", "-2" ); Object map = Collections.singletonMap( "some.key", "value" ); Object bean = new BeanTwo(); - Map contexts = new HashMap(); + Map contexts = new HashMap<>(); contexts.put( "array", array ); contexts.put( "list", list ); contexts.put( "map", map ); @@ -78,6 +82,7 @@ public void testEvaluate() assertEquals( "arg", ExpressionUtil.evaluate( "bean/bean/arg", contexts ) ); } + @Test public void testGetProperty() { BeanOne bean1 = new BeanOne(); diff --git a/core-it-support/core-it-plugins/maven-it-plugin-expression/pom.xml b/core-it-support/core-it-plugins/maven-it-plugin-expression/pom.xml index c24a8ec99..4212fe116 100644 --- a/core-it-support/core-it-plugins/maven-it-plugin-expression/pom.xml +++ b/core-it-support/core-it-plugins/maven-it-plugin-expression/pom.xml @@ -45,9 +45,8 @@ under the License. 2.0 - junit - junit - 3.8.2 + org.junit.jupiter + junit-jupiter test diff --git a/core-it-support/core-it-plugins/maven-it-plugin-expression/src/test/java/org/apache/maven/plugin/coreit/ExpressionUtilTest.java b/core-it-support/core-it-plugins/maven-it-plugin-expression/src/test/java/org/apache/maven/plugin/coreit/ExpressionUtilTest.java index cc5dd5258..f30a94a8c 100644 --- a/core-it-support/core-it-plugins/maven-it-plugin-expression/src/test/java/org/apache/maven/plugin/coreit/ExpressionUtilTest.java +++ b/core-it-support/core-it-plugins/maven-it-plugin-expression/src/test/java/org/apache/maven/plugin/coreit/ExpressionUtilTest.java @@ -19,29 +19,33 @@ * under the License. */ -import junit.framework.TestCase; - import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Map; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; + /** * @author Benjamin Bentmann * */ public class ExpressionUtilTest - extends TestCase { + @Test public void testEvaluate() { Object array = new String[]{ "one", "two", "three" }; - Object list = Arrays.asList( new String[]{ "0", "-1", "-2" } ); + Object list = Arrays.asList( "0", "-1", "-2" ); Object map = Collections.singletonMap( "some.key", "value" ); Object bean = new BeanTwo(); - Map contexts = new HashMap(); + Map contexts = new HashMap<>(); contexts.put( "array", array ); contexts.put( "list", list ); contexts.put( "map", map ); @@ -91,6 +95,7 @@ private static Object evaluate( String expression, Object context ) return ExpressionUtil.evaluate( expression, context ).get( expression ); } + @Test public void testGetProperty() { BeanOne bean1 = new BeanOne(); diff --git a/core-it-support/core-it-plugins/maven-it-plugin-expression/src/test/java/org/apache/maven/plugin/coreit/PropertyUtilTest.java b/core-it-support/core-it-plugins/maven-it-plugin-expression/src/test/java/org/apache/maven/plugin/coreit/PropertyUtilTest.java index df39b3e09..3d8dc1f63 100644 --- a/core-it-support/core-it-plugins/maven-it-plugin-expression/src/test/java/org/apache/maven/plugin/coreit/PropertyUtilTest.java +++ b/core-it-support/core-it-plugins/maven-it-plugin-expression/src/test/java/org/apache/maven/plugin/coreit/PropertyUtilTest.java @@ -19,21 +19,25 @@ * under the License. */ -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; import java.io.File; import java.util.Arrays; import java.util.Collections; import java.util.Properties; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + /** * @author Benjamin Bentmann * */ public class PropertyUtilTest - extends TestCase { + @Test public void testStoreScalar() { Properties props = new Properties(); @@ -51,6 +55,7 @@ public void testStoreScalar() assertEquals( 4, props.size() ); } + @Test public void testStoreArray() { Properties props = new Properties(); @@ -62,6 +67,7 @@ public void testStoreArray() assertEquals( 3, props.size() ); } + @Test public void testStoreList() { Properties props = new Properties(); @@ -73,6 +79,7 @@ public void testStoreList() assertEquals( 3, props.size() ); } + @Test public void testStoreMap() { Properties props = new Properties(); @@ -83,6 +90,7 @@ public void testStoreMap() assertEquals( 2, props.size() ); } + @Test public void testStoreBean() { Properties props = new Properties(); @@ -93,6 +101,7 @@ public void testStoreBean() assertEquals( 2, props.size() ); } + @Test public void testStoreCycle() { Object[] arr = { null }; @@ -100,9 +109,10 @@ public void testStoreCycle() Properties props = new Properties(); PropertyUtil.store( props, "cycle", arr ); - assertTrue( "Should not die because of stack overflow", true ); + assertTrue( true, "Should not die because of stack overflow" ); } + @Test public void testGetPropertyName() { assertEquals( "name", PropertyUtil.getPropertyName( "getName" ) ); diff --git a/core-it-support/core-it-plugins/maven-it-plugin-model-interpolation/src/main/java/org/apache/maven/plugin/coreit/PathInterpolationMojo.java b/core-it-support/core-it-plugins/maven-it-plugin-model-interpolation/src/main/java/org/apache/maven/plugin/coreit/PathInterpolationMojo.java index 5f2b01476..fdca91423 100644 --- a/core-it-support/core-it-plugins/maven-it-plugin-model-interpolation/src/main/java/org/apache/maven/plugin/coreit/PathInterpolationMojo.java +++ b/core-it-support/core-it-plugins/maven-it-plugin-model-interpolation/src/main/java/org/apache/maven/plugin/coreit/PathInterpolationMojo.java @@ -35,10 +35,17 @@ public class PathInterpolationMojo extends AbstractMojo { - /** @component */ + /** + * The model interpolator + * @component + */ private ModelInterpolator modelInterpolator; - /** @parameter default-value="${project}" */ + /** + * The current Maven project. + * + * @parameter default-value="${project}" + */ private MavenProject project; public void execute() diff --git a/core-it-support/core-it-plugins/maven-it-plugin-project-interpolation/src/main/java/org/apache/maven/plugin/coreit/PluginParamInterpolationMojo.java b/core-it-support/core-it-plugins/maven-it-plugin-project-interpolation/src/main/java/org/apache/maven/plugin/coreit/PluginParamInterpolationMojo.java index c06e4dfb4..7e4c4ebfc 100644 --- a/core-it-support/core-it-plugins/maven-it-plugin-project-interpolation/src/main/java/org/apache/maven/plugin/coreit/PluginParamInterpolationMojo.java +++ b/core-it-support/core-it-plugins/maven-it-plugin-project-interpolation/src/main/java/org/apache/maven/plugin/coreit/PluginParamInterpolationMojo.java @@ -33,10 +33,18 @@ public class PluginParamInterpolationMojo extends AbstractMojo { - /** @parameter */ + /** + * myDirectory + * + * @parameter + */ private String myDirectory; - /** @parameter default-value="${project}" */ + /** + * The current Maven project. + * + * @parameter default-value="${project}" + */ private MavenProject project; public void execute() diff --git a/core-it-support/core-it-plugins/maven-it-plugin-project-interpolation/src/main/java/org/apache/maven/plugin/coreit/PropertyInterpolationMojo.java b/core-it-support/core-it-plugins/maven-it-plugin-project-interpolation/src/main/java/org/apache/maven/plugin/coreit/PropertyInterpolationMojo.java index 2bff6cd81..3177fbf4d 100644 --- a/core-it-support/core-it-plugins/maven-it-plugin-project-interpolation/src/main/java/org/apache/maven/plugin/coreit/PropertyInterpolationMojo.java +++ b/core-it-support/core-it-plugins/maven-it-plugin-project-interpolation/src/main/java/org/apache/maven/plugin/coreit/PropertyInterpolationMojo.java @@ -34,7 +34,11 @@ public class PropertyInterpolationMojo extends AbstractMojo { - /** @parameter default-value="${project}" */ + /** + * The current Maven project. + * + * @parameter default-value="${project}" + */ private MavenProject project; public void execute() diff --git a/core-it-support/core-it-plugins/maven-it-plugin-project-interpolation/src/main/java/org/apache/maven/plugin/coreit/PropertyInterpolationVerifierMojo.java b/core-it-support/core-it-plugins/maven-it-plugin-project-interpolation/src/main/java/org/apache/maven/plugin/coreit/PropertyInterpolationVerifierMojo.java index fb11cf15b..5de48c06e 100644 --- a/core-it-support/core-it-plugins/maven-it-plugin-project-interpolation/src/main/java/org/apache/maven/plugin/coreit/PropertyInterpolationVerifierMojo.java +++ b/core-it-support/core-it-plugins/maven-it-plugin-project-interpolation/src/main/java/org/apache/maven/plugin/coreit/PropertyInterpolationVerifierMojo.java @@ -37,11 +37,15 @@ public class PropertyInterpolationVerifierMojo { /** + * The current Maven project. + * * @parameter default-value="${project}" */ private MavenProject project; /** + * The properties. + * * @parameter property="properties" */ private Properties properties; diff --git a/core-it-support/core-it-plugins/pom.xml b/core-it-support/core-it-plugins/pom.xml index ed0e815a5..2bcf95a7f 100644 --- a/core-it-support/core-it-plugins/pom.xml +++ b/core-it-support/core-it-plugins/pom.xml @@ -105,24 +105,11 @@ under the License. https://repository.apache.org/content/repositories/snapshots - - - - - org.apache.maven.plugins - maven-plugin-plugin - 3.3 - - - - - org.apache.maven.plugins maven-plugin-plugin - 3.3 diff --git a/core-it-support/maven-it-helper/pom.xml b/core-it-support/maven-it-helper/pom.xml index 9019474f0..2fdc6f104 100644 --- a/core-it-support/maven-it-helper/pom.xml +++ b/core-it-support/maven-it-helper/pom.xml @@ -56,9 +56,8 @@ under the License. 0.1 - junit - junit - 3.8.2 + org.junit.jupiter + junit-jupiter diff --git a/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/AbstractMavenIntegrationTestCase.java b/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/AbstractMavenIntegrationTestCase.java index 0f873f058..213291392 100644 --- a/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/AbstractMavenIntegrationTestCase.java +++ b/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/AbstractMavenIntegrationTestCase.java @@ -20,7 +20,9 @@ */ import java.io.File; +import java.io.FilterInputStream; import java.io.IOException; +import java.io.InputStream; import java.io.PrintStream; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; @@ -28,22 +30,23 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import junit.framework.TestCase; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.shared.utils.io.FileUtils; - -import org.apache.maven.shared.verifier.Verifier; import org.apache.maven.shared.verifier.VerificationException; +import org.apache.maven.shared.verifier.Verifier; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.TestInfo; +import org.opentest4j.TestAbortedException; /** * @author Jason van Zyl * @author Kenney Westerhof */ public abstract class AbstractMavenIntegrationTestCase - extends TestCase { /** * Save System.out for progress reports etc. @@ -73,6 +76,8 @@ public abstract class AbstractMavenIntegrationTestCase private String matchPattern; + private String testName; + private static final String DEFAULT_MATCH_PATTERN = "(.*?)-(RC[0-9]+|SNAPSHOT|RC[0-9]+-SNAPSHOT)"; protected static final String ALL_MAVEN_VERSIONS = "[2.0,)"; @@ -86,24 +91,16 @@ protected AbstractMavenIntegrationTestCase( String versionRangeStr, String match { this.matchPattern = matchPattern; - try - { - versionRange = VersionRange.createFromVersionSpec( versionRangeStr ); - } - catch ( InvalidVersionSpecificationException e ) - { - throw (RuntimeException) new IllegalArgumentException( "Invalid version range: " + versionRangeStr, e ); - } + requiresMavenVersion( versionRangeStr ); + } - ArtifactVersion version = getMavenVersion(); - if ( version != null ) + + @BeforeAll + static void setupInputStream() + { + if ( !( System.in instanceof NonCloseableInputStream ) ) { - skip = !versionRange.containsVersion( removePattern( version ) ); - } - else - { - out.println( "WARNING: " + getITName() + ": version range '" + versionRange - + "' supplied but no Maven version - not skipping test." ); + System.setIn( new NonCloseableInputStream( System.in ) ); } } @@ -260,7 +257,8 @@ protected void runTest() long milliseconds = System.currentTimeMillis(); try { - super.runTest(); + // TODO: JUNIT5 + //super.runTest(); milliseconds = System.currentTimeMillis() - milliseconds; if ( invert != null ) { @@ -400,8 +398,21 @@ protected void failingMavenVersions( String versionRange ) } } + private static class NonCloseableInputStream extends FilterInputStream + { + NonCloseableInputStream( InputStream delegate ) + { + super( delegate ); + } + + @Override + public void close() throws IOException + { + } + } + private class UnsupportedJavaVersionException - extends RuntimeException + extends TestAbortedException { @SuppressWarnings( "checkstyle:visibilitymodifier" ) public ArtifactVersion javaVersion; @@ -411,6 +422,7 @@ private class UnsupportedJavaVersionException private UnsupportedJavaVersionException( ArtifactVersion javaVersion, VersionRange supportedRange ) { + super( "Java version " + javaVersion + " not in range " + supportedRange ); this.javaVersion = javaVersion; this.supportedRange = supportedRange; } @@ -418,7 +430,7 @@ private UnsupportedJavaVersionException( ArtifactVersion javaVersion, VersionRan } private class UnsupportedMavenVersionException - extends RuntimeException + extends TestAbortedException { @SuppressWarnings( "checkstyle:visibilitymodifier" ) public ArtifactVersion mavenVersion; @@ -428,6 +440,7 @@ private class UnsupportedMavenVersionException private UnsupportedMavenVersionException( ArtifactVersion mavenVersion, VersionRange supportedRange ) { + super( "Maven version " + mavenVersion + " not in range " + supportedRange ); this.mavenVersion = mavenVersion; this.supportedRange = supportedRange; } @@ -622,6 +635,17 @@ protected Verifier newVerifier( String basedir, String settings, boolean debug ) return verifier; } + @BeforeEach + void setupContext( TestInfo testInfo ) + { + testName = testInfo.getTestMethod().get().getName(); + } + + protected String getName() + { + return testName; + } + public static void assertCanonicalFileEquals( String message, File expected, File actual ) throws IOException { @@ -645,4 +669,70 @@ public static void assertCanonicalFileEquals( String expected, String actual ) { assertCanonicalFileEquals( null, new File( expected ), new File( actual ) ); } + + public static void assertEquals( Object o1, Object o2 ) + { + assertEquals( null, o1, o2 ); + } + + public static void assertEquals( String message, Object o1, Object o2 ) + { + org.junit.jupiter.api.Assertions.assertEquals( o1, o2, message ); + } + + public static void assertNotEquals( Object o1, Object o2 ) + { + assertNotEquals( null, o1, o2 ); + } + + public static void assertNotEquals( String message, Object o1, Object o2 ) + { + org.junit.jupiter.api.Assertions.assertNotEquals( o1, o2, message ); + } + + public static void assertTrue( boolean test ) + { + assertTrue( null, test ); + } + + public static void assertTrue( String message, boolean test ) + { + org.junit.jupiter.api.Assertions.assertTrue( test, message ); + } + + public static void assertFalse( boolean test ) + { + assertFalse( null, test ); + } + + public static void assertFalse( String message, boolean test ) + { + org.junit.jupiter.api.Assertions.assertFalse( test, message ); + } + + public static void assertNotNull( Object o ) + { + assertNotNull( null, o ); + } + + public static void assertNotNull( String message, Object o ) + { + org.junit.jupiter.api.Assertions.assertNotNull( o, message ); + } + + public static void assertNull( Object o ) + { + assertNull( null, o ); + } + + public static void assertNull( String message, Object o ) + { + org.junit.jupiter.api.Assertions.assertNull( o, message ); + } + + public static void fail( String message ) + { + org.junit.jupiter.api.Assertions.fail( message ); + } + } diff --git a/core-it-support/maven-it-helper/src/test/java/org/apache/maven/it/MavenIntegrationTestCaseTest.java b/core-it-support/maven-it-helper/src/test/java/org/apache/maven/it/MavenIntegrationTestCaseTest.java index 69509cced..3971d8132 100644 --- a/core-it-support/maven-it-helper/src/test/java/org/apache/maven/it/MavenIntegrationTestCaseTest.java +++ b/core-it-support/maven-it-helper/src/test/java/org/apache/maven/it/MavenIntegrationTestCaseTest.java @@ -19,14 +19,15 @@ * under the License. */ -import junit.framework.TestCase; - import org.apache.maven.artifact.versioning.DefaultArtifactVersion; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class MavenIntegrationTestCaseTest - extends TestCase { + @Test public void testRemovePatternForTestWithVersionRange() { AbstractMavenIntegrationTestCase test = new AbstractMavenIntegrationTestCase( "[2.0,)" ) @@ -49,6 +50,7 @@ private static void assertVersionEquals( String expected, String version, Abstra assertEquals( expected, test.removePattern( new DefaultArtifactVersion( version ) ).toString() ); } + @Test public void testRequiresMavenVersion() { System.setProperty( "maven.version", "2.1" ); diff --git a/core-it-support/maven-it-plugin-bootstrap/pom.xml b/core-it-support/maven-it-plugin-bootstrap/pom.xml index 841f9efed..4eef3049f 100644 --- a/core-it-support/maven-it-plugin-bootstrap/pom.xml +++ b/core-it-support/maven-it-plugin-bootstrap/pom.xml @@ -57,6 +57,11 @@ under the License. maven-resolver-impl ${mavenResolverVersion} + + org.apache.maven.plugin-tools + maven-plugin-annotations + 3.3 + diff --git a/core-it-support/maven-it-sample-archetype/src/main/resources/archetype-resources/src/test/java/MavenITmngXXXXDescriptionOfProblemTest.java b/core-it-support/maven-it-sample-archetype/src/main/resources/archetype-resources/src/test/java/MavenITmngXXXXDescriptionOfProblemTest.java index 1392707d1..2009a503f 100644 --- a/core-it-support/maven-it-sample-archetype/src/main/resources/archetype-resources/src/test/java/MavenITmngXXXXDescriptionOfProblemTest.java +++ b/core-it-support/maven-it-sample-archetype/src/main/resources/archetype-resources/src/test/java/MavenITmngXXXXDescriptionOfProblemTest.java @@ -55,6 +55,7 @@ public MavenITmngXXXXDescriptionOfProblemTest() super( "(2.0.8,)" ); // only test in 2.0.9+ } + @Test public void testitMNGxxxx () throws Exception { diff --git a/core-it-support/maven-it-sample/src/test/java/org/apache/maven/it/MavenITmngXXXXDescriptionOfProblemTest.java b/core-it-support/maven-it-sample/src/test/java/org/apache/maven/it/MavenITmngXXXXDescriptionOfProblemTest.java index 01355ef99..06578f39d 100644 --- a/core-it-support/maven-it-sample/src/test/java/org/apache/maven/it/MavenITmngXXXXDescriptionOfProblemTest.java +++ b/core-it-support/maven-it-sample/src/test/java/org/apache/maven/it/MavenITmngXXXXDescriptionOfProblemTest.java @@ -23,10 +23,8 @@ import java.util.ArrayList; import java.util.List; -import org.apache.maven.it.Verifier; -import org.apache.maven.shared.verifier.util.ResourceExtractor; import org.apache.maven.shared.verifier.Verifier; -import org.apache.maven.shared.verifier.VerificationException; +import org.apache.maven.shared.verifier.util.ResourceExtractor; /** * This is a sample integration test. The IT tests typically @@ -54,6 +52,7 @@ public MavenITmngXXXXDescriptionOfProblemTest() super( "(2.0.8,)" ); // only test in 2.0.9+ } + @Test public void testitMNGxxxx () throws Exception { diff --git a/pom.xml b/pom.xml index 78d7401ca..0f7965532 100644 --- a/pom.xml +++ b/pom.xml @@ -84,6 +84,11 @@ under the License. maven-verifier 2.0.0-M1 + + org.junit.jupiter + junit-jupiter + 5.8.0 + @@ -136,7 +141,7 @@ under the License. org.apache.maven.plugins maven-surefire-plugin - 2.22.0 + 3.0.0-M7 true @@ -194,6 +199,16 @@ under the License. + + org.apache.maven.plugins + maven-resources-plugin + 3.2.0 + + + org.apache.maven.plugins + maven-plugin-plugin + 3.6.4 +