From 97fd50cdb34708da336c54d115593cdff32caa9c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Feb 2022 03:59:38 +0000 Subject: [PATCH 1/2] Bump plexus-components from 6.5 to 6.6 Bumps [plexus-components](https://github.com/codehaus-plexus/plexus-components) from 6.5 to 6.6. - [Release notes](https://github.com/codehaus-plexus/plexus-components/releases) - [Commits](https://github.com/codehaus-plexus/plexus-components/compare/plexus-components-6.5...plexus-components-6.6) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus-components dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7a851cf9..2cbb5998 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.codehaus.plexus plexus-components - 6.5 + 6.6 plexus-compiler From 4ff2cb0a52f58ea33c5f5f58f62f3f38a4f3be42 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Tue, 8 Feb 2022 11:17:07 +1000 Subject: [PATCH 2/2] move to junit5 Signed-off-by: Olivier Lamy --- plexus-compiler-api/pom.xml | 6 + .../compiler/CompilerConfigurationTest.java | 29 +- .../AbstractSourceInclusionScannerTest.java | 37 +- .../SimpleSourceInclusionScannerTest.java | 7 +- .../util/scan/StaleSourceScannerTest.java | 90 ++--- .../util/scan/mapping/SuffixMappingTest.java | 39 ++- plexus-compiler-manager/pom.xml | 10 + .../compiler/manager/CompilerManagerTest.java | 25 +- plexus-compiler-test/pom.xml | 13 +- .../compiler/AbstractCompilerTckTest.java | 34 +- .../plexus/compiler/AbstractCompilerTest.java | 37 +- .../plexus-compiler-csharp/pom.xml | 10 + .../compiler/csharp/CSharpCompilerTest.java | 61 ++-- .../plexus-compiler-eclipse/pom.xml | 15 +- .../EclipseCompilerConfigurationTest.java | 54 +-- .../EclipseCompilerDashedArgumentsTest.java | 36 +- .../EclipseCompilerErrorsAsWarningsTest.java | 17 +- .../EclipseCompilerFailOnWarningsTest.java | 10 +- .../eclipse/EclipseCompilerTckTest.java | 3 +- .../compiler/eclipse/EclipseCompilerTest.java | 13 +- .../plexus-compiler-j2objc/pom.xml | 10 + .../compiler/j2objc/J2ObjCCompilerTest.java | 30 +- .../plexus-compiler-javac/pom.xml | 10 +- .../javac/AbstractJavacCompilerTest.java | 13 +- .../javac/ErrorMessageParserTest.java | 322 ++++++++++-------- .../compiler/javac/JavacCompilerTest.java | 1 - pom.xml | 21 +- 27 files changed, 525 insertions(+), 428 deletions(-) diff --git a/plexus-compiler-api/pom.xml b/plexus-compiler-api/pom.xml index 7ce8603f..7bc754e6 100644 --- a/plexus-compiler-api/pom.xml +++ b/plexus-compiler-api/pom.xml @@ -21,6 +21,12 @@ org.junit.jupiter junit-jupiter-api + test + + + org.hamcrest + hamcrest + test diff --git a/plexus-compiler-api/src/test/java/org/codehaus/plexus/compiler/CompilerConfigurationTest.java b/plexus-compiler-api/src/test/java/org/codehaus/plexus/compiler/CompilerConfigurationTest.java index 3c89ed5d..d295b69b 100644 --- a/plexus-compiler-api/src/test/java/org/codehaus/plexus/compiler/CompilerConfigurationTest.java +++ b/plexus-compiler-api/src/test/java/org/codehaus/plexus/compiler/CompilerConfigurationTest.java @@ -1,39 +1,44 @@ package org.codehaus.plexus.compiler; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import java.util.Iterator; import java.util.Map; -import junit.framework.TestCase; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; public class CompilerConfigurationTest - extends TestCase { private CompilerConfiguration configuration; - @Override + + @BeforeEach protected void setUp() throws Exception { configuration = new CompilerConfiguration(); } - + + @Test public void testCustomArguments() { configuration.addCompilerCustomArgument( "--add-exports", "FROM-MOD/package1=OTHER-MOD" ); configuration.addCompilerCustomArgument( "--add-exports", "FROM-MOD/package2=OTHER-MOD" ); - assertEquals( 1, configuration.getCustomCompilerArgumentsAsMap().size() ); - assertEquals( "FROM-MOD/package2=OTHER-MOD", configuration.getCustomCompilerArgumentsAsMap().get( "--add-exports" ) ); - - assertEquals( 2, configuration.getCustomCompilerArgumentsEntries().size() ); + assertThat(configuration.getCustomCompilerArgumentsAsMap().size(), is( 1 )); + assertThat( configuration.getCustomCompilerArgumentsAsMap().get( "--add-exports" ), is( "FROM-MOD/package2=OTHER-MOD" ) ); + + assertThat( configuration.getCustomCompilerArgumentsEntries().size(), is( 2 ) ); Iterator> entries = configuration.getCustomCompilerArgumentsEntries().iterator(); Map.Entry entry; entry = entries.next(); - assertEquals( "--add-exports", entry.getKey() ); - assertEquals( "FROM-MOD/package1=OTHER-MOD", entry.getValue() ); + assertThat( entry.getKey(), is( "--add-exports" ) ); + assertThat( entry.getValue(), is( "FROM-MOD/package1=OTHER-MOD" ) ); entry = entries.next(); - assertEquals( "--add-exports", entry.getKey() ); - assertEquals( "FROM-MOD/package2=OTHER-MOD", entry.getValue() ); + assertThat( entry.getKey(), is( "--add-exports" )); + assertThat( entry.getValue(), is( "FROM-MOD/package2=OTHER-MOD") ); } } diff --git a/plexus-compiler-api/src/test/java/org/codehaus/plexus/compiler/util/scan/AbstractSourceInclusionScannerTest.java b/plexus-compiler-api/src/test/java/org/codehaus/plexus/compiler/util/scan/AbstractSourceInclusionScannerTest.java index efe343d4..1ddd35a0 100644 --- a/plexus-compiler-api/src/test/java/org/codehaus/plexus/compiler/util/scan/AbstractSourceInclusionScannerTest.java +++ b/plexus-compiler-api/src/test/java/org/codehaus/plexus/compiler/util/scan/AbstractSourceInclusionScannerTest.java @@ -23,10 +23,13 @@ import java.net.URL; import java.util.Set; -import junit.framework.TestCase; - import org.codehaus.plexus.compiler.util.scan.mapping.SuffixMapping; -import org.codehaus.plexus.util.IOUtil; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.io.FileMatchers.anExistingFile; /** * Tests for all the implementations of SourceInclusionScanner @@ -34,7 +37,6 @@ * @author Carlos Sanchez */ public abstract class AbstractSourceInclusionScannerTest - extends TestCase { private static final String TESTFILE_DEST_MARKER_FILE = @@ -42,6 +44,7 @@ public abstract class AbstractSourceInclusionScannerTest protected SourceInclusionScanner scanner; + @Test public void testGetIncludedSources() throws Exception { @@ -59,11 +62,11 @@ public void testGetIncludedSources() Set includedSources = scanner.getIncludedSources( base, base ); - assertTrue( "no sources were included", !includedSources.isEmpty() ); + assertThat( "no sources were included", includedSources, not( empty() ) ); for ( File file : includedSources ) { - assertTrue( "file included does not exist", file.exists() ); + assertThat( "file included does not exist", file, anExistingFile() ); } } @@ -100,24 +103,18 @@ protected File getTestBaseDir() protected void writeFile( File file ) throws IOException { - FileWriter fWriter = null; - try - { - File parent = file.getParentFile(); - if ( !parent.exists() ) - { - parent.mkdirs(); - } - file.deleteOnExit(); + File parent = file.getParentFile(); + if ( !parent.exists() ) + { + parent.mkdirs(); + } - fWriter = new FileWriter( file ); + file.deleteOnExit(); - fWriter.write( "This is just a test file." ); - } - finally + try (FileWriter fWriter = new FileWriter( file )) { - IOUtil.close( fWriter ); + fWriter.write( "This is just a test file." ); } } diff --git a/plexus-compiler-api/src/test/java/org/codehaus/plexus/compiler/util/scan/SimpleSourceInclusionScannerTest.java b/plexus-compiler-api/src/test/java/org/codehaus/plexus/compiler/util/scan/SimpleSourceInclusionScannerTest.java index 32f4dad6..a8783501 100644 --- a/plexus-compiler-api/src/test/java/org/codehaus/plexus/compiler/util/scan/SimpleSourceInclusionScannerTest.java +++ b/plexus-compiler-api/src/test/java/org/codehaus/plexus/compiler/util/scan/SimpleSourceInclusionScannerTest.java @@ -16,6 +16,8 @@ * limitations under the License. */ +import org.junit.jupiter.api.BeforeEach; + import java.util.Collections; import java.util.HashSet; import java.util.Set; @@ -32,11 +34,10 @@ public class SimpleSourceInclusionScannerTest private Set includes, excludes; - protected void setUp() + @BeforeEach + public void setUp() throws Exception { - super.setUp(); - includes = Collections.singleton( "*.java" ); excludes = new HashSet<>(); scanner = new SimpleSourceInclusionScanner( includes, excludes ); diff --git a/plexus-compiler-api/src/test/java/org/codehaus/plexus/compiler/util/scan/StaleSourceScannerTest.java b/plexus-compiler-api/src/test/java/org/codehaus/plexus/compiler/util/scan/StaleSourceScannerTest.java index 83e60499..6679bb97 100644 --- a/plexus-compiler-api/src/test/java/org/codehaus/plexus/compiler/util/scan/StaleSourceScannerTest.java +++ b/plexus-compiler-api/src/test/java/org/codehaus/plexus/compiler/util/scan/StaleSourceScannerTest.java @@ -23,6 +23,15 @@ import org.codehaus.plexus.compiler.util.scan.mapping.SingleTargetSourceMapping; import org.codehaus.plexus.compiler.util.scan.mapping.SourceMapping; import org.codehaus.plexus.compiler.util.scan.mapping.SuffixMapping; +import org.hamcrest.Matchers; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.is; /** * @author jdcasey @@ -32,14 +41,14 @@ public class StaleSourceScannerTest extends AbstractSourceInclusionScannerTest { - protected void setUp() + @BeforeEach + public void setUp() throws Exception { - super.setUp(); scanner = new StaleSourceScanner(); } - // test 1. + @Test public void testWithDefaultConstructorShouldFindOneStaleSource() throws Exception { @@ -65,12 +74,12 @@ public void testWithDefaultConstructorShouldFindOneStaleSource() Set result = scanner.getIncludedSources( base, base ); - assertEquals( "wrong number of stale sources returned.", 1, result.size() ); + assertThat( "wrong number of stale sources returned.", result.size(), is( 1) ); - assertTrue( "expected stale source file not found in result", result.contains( sourceFile ) ); + assertThat( "expected stale source file not found in result", result, Matchers.contains( sourceFile ) ); } - // test 2. + @Test public void testWithDefaultConstructorShouldNotFindStaleSources() throws Exception { @@ -96,12 +105,12 @@ public void testWithDefaultConstructorShouldNotFindStaleSources() Set result = scanner.getIncludedSources( base, base ); - assertEquals( "wrong number of stale sources returned.", 0, result.size() ); + assertThat( "wrong number of stale sources returned.", result.size(), is( 0 ) ); - assertFalse( "expected stale source file not found in result", result.contains( sourceFile ) ); + assertThat( "expected stale source file not found in result", result, empty( ) ); } - // test 3. + @Test public void testWithDefaultConstructorShouldFindStaleSourcesBecauseOfMissingTargetFile() throws Exception { @@ -117,12 +126,12 @@ public void testWithDefaultConstructorShouldFindStaleSourcesBecauseOfMissingTarg Set result = scanner.getIncludedSources( base, base ); - assertEquals( "wrong number of stale sources returned.", 1, result.size() ); + assertThat( "wrong number of stale sources returned.", result.size(), is( 1) ); - assertTrue( "expected stale source file not found in result", result.contains( sourceFile ) ); + assertThat( "expected stale source file not found in result", result, contains( sourceFile ) ); } - // test 4. + @Test public void testWithDefaultConstructorShouldFindStaleSourcesOneBecauseOfMissingTargetAndOneBecauseOfStaleTarget() throws Exception { @@ -152,14 +161,13 @@ public void testWithDefaultConstructorShouldFindStaleSourcesOneBecauseOfMissingT Set result = scanner.getIncludedSources( base, base ); - assertEquals( "wrong number of stale sources returned.", 2, result.size() ); + assertThat( "wrong number of stale sources returned.", result.size(), is( 2) ); - assertTrue( "expected stale source file not found in result", result.contains( sourceFile ) ); + assertThat( "expected stale source file not found in result", result, containsInAnyOrder( sourceFile, sourceFile2 ) ); - assertTrue( "expected stale source file not found in result", result.contains( sourceFile2 ) ); } - // test 5. + @Test public void testWithDefaultConstructorShouldFindOneStaleSourcesWithStaleTargetAndOmitUpToDateSource() throws Exception { @@ -207,12 +215,12 @@ public void testWithDefaultConstructorShouldFindOneStaleSourcesWithStaleTargetAn Set result = scanner.getIncludedSources( base, base ); - assertEquals( "wrong number of stale sources returned.", 1, result.size() ); + assertThat( "wrong number of stale sources returned.", result.size(), is( 1 ) ); - assertTrue( "expected stale source file not found in result", result.contains( sourceFile ) ); + assertThat( "expected stale source file not found in result", result, contains( sourceFile ) ); } - // test 6. + @Test public void testConstructedWithMsecsShouldReturnOneSourceFileOfTwoDueToLastMod() throws Exception { @@ -255,14 +263,12 @@ public void testConstructedWithMsecsShouldReturnOneSourceFileOfTwoDueToLastMod() Set result = scanner.getIncludedSources( base, base ); - assertEquals( "wrong number of stale sources returned.", 1, result.size() ); - - assertTrue( "expected stale source file not found in result", result.contains( sourceFile2 ) ); + assertThat( "wrong number of stale sources returned.", result.size(), is( 1 ) ); - assertFalse( "expected stale source file not found in result", result.contains( sourceFile ) ); + assertThat( "expected stale source file not found in result", result, contains( sourceFile2 ) ); } - // test 7. + @Test public void testConstructedWithMsecsIncludesAndExcludesShouldReturnOneSourceFileOfThreeDueToIncludePattern() throws Exception { @@ -318,16 +324,12 @@ public void testConstructedWithMsecsIncludesAndExcludesShouldReturnOneSourceFile Set result = scanner.getIncludedSources( base, base ); - assertEquals( "wrong number of stale sources returned.", 1, result.size() ); - - assertFalse( "expected stale source file not found in result", result.contains( sourceFile ) ); - - assertFalse( "unexpected stale source file found in result", result.contains( sourceFile2 ) ); + assertThat( "wrong number of stale sources returned.", result.size(), is( 1 ) ); - assertTrue( "unexpected stale source file found in result", result.contains( sourceFile3 ) ); + assertThat( "expected stale source file not found in result", result, contains( sourceFile3 ) ); } - // test 8. + @Test public void testConstructedWithMsecsIncludesAndExcludesShouldReturnTwoSourceFilesOfThreeDueToExcludePattern() throws Exception { @@ -383,16 +385,13 @@ public void testConstructedWithMsecsIncludesAndExcludesShouldReturnTwoSourceFile Set result = scanner.getIncludedSources( base, base ); - assertEquals( "wrong number of stale sources returned.", 2, result.size() ); + assertThat( "wrong number of stale sources returned.", result.size(), is( 2 ) ); - assertFalse( "unexpected stale source file found in result", result.contains( sourceFile ) ); + assertThat( "expected stale source file not found in result", result, containsInAnyOrder( sourceFile2, sourceFile3 ) ); - assertTrue( "expected stale source not file found in result", result.contains( sourceFile2 ) ); - - assertTrue( "expected stale source not file found in result", result.contains( sourceFile3 ) ); } - // test 9. + @Test public void testSingleFileSourceMapping() throws Exception { @@ -420,9 +419,9 @@ public void testSingleFileSourceMapping() Set result = scanner.getIncludedSources( src, target ); - assertEquals( 1, result.size() ); + assertThat( result.size(), is( 1 ) ); - assertTrue( result.contains( fooCs ) ); + assertThat( result, contains( fooCs ) ); // ---------------------------------------------------------------------- // Add another source file @@ -436,11 +435,11 @@ public void testSingleFileSourceMapping() result = scanner.getIncludedSources( src, target ); - assertEquals( 2, result.size() ); + assertThat( result.size(), is( 2 ) ); + + assertThat( result, containsInAnyOrder( fooCs, barCs ) ); - assertTrue( result.contains( fooCs ) ); - assertTrue( result.contains( barCs ) ); // ---------------------------------------------------------------------- // Now add the result file @@ -454,7 +453,8 @@ public void testSingleFileSourceMapping() result = scanner.getIncludedSources( src, target ); - assertEquals( 0, result.size() ); + assertThat( result, empty() ); + // ---------------------------------------------------------------------- // Make Application.exe older than the Foo.cs @@ -464,9 +464,9 @@ public void testSingleFileSourceMapping() result = scanner.getIncludedSources( src, target ); - assertEquals( 1, result.size() ); + assertThat( result.size(), is( 1 ) ); - assertTrue( result.contains( fooCs ) ); + assertThat( result, contains( fooCs ) ); } } diff --git a/plexus-compiler-api/src/test/java/org/codehaus/plexus/compiler/util/scan/mapping/SuffixMappingTest.java b/plexus-compiler-api/src/test/java/org/codehaus/plexus/compiler/util/scan/mapping/SuffixMappingTest.java index cdab5047..72a5d494 100644 --- a/plexus-compiler-api/src/test/java/org/codehaus/plexus/compiler/util/scan/mapping/SuffixMappingTest.java +++ b/plexus-compiler-api/src/test/java/org/codehaus/plexus/compiler/util/scan/mapping/SuffixMappingTest.java @@ -16,21 +16,25 @@ * limitations under the License. */ -import junit.framework.TestCase; -import org.codehaus.plexus.compiler.util.scan.InclusionScanException; +import org.junit.jupiter.api.Test; import java.io.File; import java.util.HashSet; import java.util.Set; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.is; + /** * @author jdcasey */ public class SuffixMappingTest - extends TestCase { + + @Test public void testShouldReturnSingleClassFileForSingleJavaFile() - throws InclusionScanException { String base = "path/to/file"; @@ -40,13 +44,13 @@ public void testShouldReturnSingleClassFileForSingleJavaFile() Set results = mapping.getTargetFiles( basedir, base + ".java" ); - assertEquals( "Returned wrong number of target files.", 1, results.size() ); + assertThat( "Returned wrong number of target files.", results.size(), is( 1 ) ); - assertEquals( "Target file is wrong.", new File( basedir, base + ".class" ), results.iterator().next() ); + assertThat( "Target file is wrong.", results.iterator().next(), is( new File( basedir, base + ".class" ) ) ); } + @Test public void testShouldNotReturnClassFileWhenSourceFileHasWrongSuffix() - throws InclusionScanException { String base = "path/to/file"; @@ -56,11 +60,11 @@ public void testShouldNotReturnClassFileWhenSourceFileHasWrongSuffix() Set results = mapping.getTargetFiles( basedir, base + ".xml" ); - assertTrue( "Returned wrong number of target files.", results.isEmpty() ); + assertThat( "Returned wrong number of target files.", results, empty() ); } + @Test public void testShouldReturnOneClassFileAndOneXmlFileForSingleJavaFile() - throws InclusionScanException { String base = "path/to/file"; @@ -74,15 +78,15 @@ public void testShouldReturnOneClassFileAndOneXmlFileForSingleJavaFile() Set results = mapping.getTargetFiles( basedir, base + ".java" ); - assertEquals( "Returned wrong number of target files.", 2, results.size() ); + assertThat( "Returned wrong number of target files.", results.size(), is( 2 ) ); - assertTrue( "Targets do not contain class target.", results.contains( new File( basedir, base + ".class" ) ) ); + assertThat( "Targets do not contain class target.", results, + containsInAnyOrder( new File( basedir, base + ".class" ), new File( basedir, base + ".xml" ) ) ); - assertTrue( "Targets do not contain class target.", results.contains( new File( basedir, base + ".xml" ) ) ); } + @Test public void testShouldReturnNoTargetFilesWhenSourceFileHasWrongSuffix() - throws InclusionScanException { String base = "path/to/file"; @@ -96,11 +100,12 @@ public void testShouldReturnNoTargetFilesWhenSourceFileHasWrongSuffix() Set results = mapping.getTargetFiles( basedir, base + ".apt" ); - assertTrue( "Returned wrong number of target files.", results.isEmpty() ); + assertThat( "Returned wrong number of target files.", results, empty() ); } + @Test public void testSingleTargetMapper() - throws InclusionScanException + throws Exception { String base = "path/to/file"; @@ -110,10 +115,10 @@ public void testSingleTargetMapper() Set results = mapping.getTargetFiles( basedir, base + ".apt" ); - assertTrue( results.isEmpty() ); + assertThat( results, empty() ); results = mapping.getTargetFiles( basedir, base + ".cs" ); - assertEquals( 1, results.size() ); + assertThat( results.size(), is( 1 ) ); } } diff --git a/plexus-compiler-manager/pom.xml b/plexus-compiler-manager/pom.xml index 40799b25..534bbfa4 100644 --- a/plexus-compiler-manager/pom.xml +++ b/plexus-compiler-manager/pom.xml @@ -21,5 +21,15 @@ org.codehaus.plexus plexus-component-annotations + + org.junit.jupiter + junit-jupiter-api + test + + + org.codehaus.plexus + plexus-testing + test + diff --git a/plexus-compiler-manager/src/test/java/org/codehaus/plexus/compiler/manager/CompilerManagerTest.java b/plexus-compiler-manager/src/test/java/org/codehaus/plexus/compiler/manager/CompilerManagerTest.java index 720f92e1..0eede05c 100644 --- a/plexus-compiler-manager/src/test/java/org/codehaus/plexus/compiler/manager/CompilerManagerTest.java +++ b/plexus-compiler-manager/src/test/java/org/codehaus/plexus/compiler/manager/CompilerManagerTest.java @@ -24,28 +24,25 @@ * SOFTWARE. */ -import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.testing.PlexusTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import javax.inject.Inject; /** * @author Trygve Laugstøl */ +@PlexusTest public class CompilerManagerTest - extends PlexusTestCase { + @Inject + private CompilerManager compilerManager; + + @Test public void testBasic() throws Exception { - CompilerManager compilerManager = (CompilerManager) lookup( CompilerManager.ROLE ); - - try - { - compilerManager.getCompiler( "foo" ); - - fail( "Expected NoSuchCompilerException" ); - } - catch ( NoSuchCompilerException e ) - { - // ignored - } + Assertions.assertThrows(NoSuchCompilerException.class, () -> compilerManager.getCompiler( "foo" )); } } diff --git a/plexus-compiler-test/pom.xml b/plexus-compiler-test/pom.xml index 3e931d96..145adbb8 100644 --- a/plexus-compiler-test/pom.xml +++ b/plexus-compiler-test/pom.xml @@ -25,17 +25,12 @@ org.codehaus.plexus plexus-testing - 1.1.0 + compile - org.assertj - assertj-core - 3.22.0 - - - org.apache.maven - maven-artifact-test - 2.0.10 + org.hamcrest + hamcrest + compile org.apache.maven diff --git a/plexus-compiler-test/src/main/java/org/codehaus/plexus/compiler/AbstractCompilerTckTest.java b/plexus-compiler-test/src/main/java/org/codehaus/plexus/compiler/AbstractCompilerTckTest.java index 38ce4e7e..2a6c8106 100644 --- a/plexus-compiler-test/src/main/java/org/codehaus/plexus/compiler/AbstractCompilerTckTest.java +++ b/plexus-compiler-test/src/main/java/org/codehaus/plexus/compiler/AbstractCompilerTckTest.java @@ -24,8 +24,6 @@ * SOFTWARE. */ -import static org.assertj.core.api.Assertions.assertThat; - import java.io.File; import java.io.IOException; import java.lang.reflect.Method; @@ -40,6 +38,11 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInfo; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; + /** * @author Trygve Laugstøl */ @@ -48,18 +51,13 @@ public abstract class AbstractCompilerTckTest { private static final String EOL = System.lineSeparator(); - private final String roleHint; + protected String roleHint; private TestInfo testInfo; @Inject private Map compilers; - protected AbstractCompilerTckTest( String roleHint ) - { - this.roleHint = roleHint; - } - @BeforeEach final void setup( TestInfo testInfo ) { @@ -90,15 +88,15 @@ public void testDeprecation() // // ---------------------------------------------------------------------- - assertThat( result.size() ).isEqualTo( 1 ); + assertThat( result.size(), is( 1 ) ); CompilerMessage error = result.get( 0 ); - assertThat( error.isError() ).isFalse(); + assertThat( error.isError(), is( false ) ); - assertThat( error.getMessage() ).contains( "Date" ); + assertThat( error.getMessage(), containsString( "Date" ) ); - assertThat( error.getMessage() ).contains( "deprecated" ); + assertThat( error.getMessage(), containsString( "deprecated" ) ); } @Test @@ -125,13 +123,13 @@ public void testWarning() // // ---------------------------------------------------------------------- - assertThat( result.size() ).isEqualTo( 1 ); + assertThat( result.size(), is( 1 ) ); CompilerMessage error = result.get( 0 ); - assertThat( error.isError() ).isFalse(); + assertThat( error.isError(), is( false ) ); - assertThat( error.getMessage() ).contains( "finally block does not complete normally" ); + assertThat( error.getMessage(), containsString( "finally block does not complete normally" ) ); } protected List compile( CompilerConfiguration configuration ) @@ -156,7 +154,7 @@ protected List compile( CompilerConfiguration configuration ) List result = getCompiler().performCompile( configuration ).getCompilerMessages(); - assertThat( result ).isNotNull(); + assertThat( result, notNullValue() ); return result; } @@ -182,7 +180,7 @@ protected void writeFileWithDeprecatedApi( File path, String className ) if ( !parent.exists() ) { - assertThat( parent.mkdirs() ).isTrue(); + assertThat( parent.mkdirs(), is( true ) ); } String source = "import java.util.Date;" + EOL + @@ -208,7 +206,7 @@ protected void writeFileWithWarning( File path, String className ) if ( !parent.exists() ) { - assertThat( parent.mkdirs() ).isTrue(); + assertThat( parent.mkdirs(), is( true ) ); } String source = "public class " + className + "" + EOL + diff --git a/plexus-compiler-test/src/main/java/org/codehaus/plexus/compiler/AbstractCompilerTest.java b/plexus-compiler-test/src/main/java/org/codehaus/plexus/compiler/AbstractCompilerTest.java index 93f93a7b..b9687038 100644 --- a/plexus-compiler-test/src/main/java/org/codehaus/plexus/compiler/AbstractCompilerTest.java +++ b/plexus-compiler-test/src/main/java/org/codehaus/plexus/compiler/AbstractCompilerTest.java @@ -24,8 +24,6 @@ * SOFTWARE. */ -import static org.assertj.core.api.Assertions.assertThat; - import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.handler.DefaultArtifactHandler; @@ -39,6 +37,9 @@ import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.ReaderFactory; import org.codehaus.plexus.util.StringUtils; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.hamcrest.io.FileMatchers; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -49,10 +50,14 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.TreeSet; +import java.util.stream.Collectors; import javax.inject.Inject; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.is; + /** * */ @@ -125,8 +130,8 @@ protected List getClasspath() File file = getLocalArtifactPath( "commons-lang", "commons-lang", "2.0", "jar" ); - assertThat( file.canRead() ).as( "test prerequisite: commons-lang library must be available in local repository, expected " - + file.getAbsolutePath() ).isTrue(); + assertThat("test prerequisite: commons-lang library must be available in local repository, expected ", + file, FileMatchers.aReadableFile()); cp.add( file.getAbsolutePath() ); @@ -143,7 +148,7 @@ public void testCompilingSources() throws Exception { List messages = new ArrayList<>(); - Collection files = new TreeSet<>(); + Collection files = new ArrayList<>(); for ( CompilerConfiguration compilerConfig : getCompilerConfigurations() ) { @@ -181,8 +186,9 @@ public void testCompilingSources() errors.add( error.getMessage() ); } - assertThat( numCompilerErrors ).as( "Wrong number of compilation errors (" + numCompilerErrors + "/" + expectedErrors // - + ") : " + displayLines( errors ) ).isEqualTo( expectedErrors ); + assertThat("Wrong number of compilation errors (" + numCompilerErrors + "/" + expectedErrors // + + ") : " + displayLines( errors ), + numCompilerErrors, is( expectedErrors ) ); } int expectedWarnings = expectedWarnings(); @@ -204,12 +210,12 @@ public void testCompilingSources() warnings.add( error.getMessage() ); } - assertThat( numCompilerWarnings ).as( "Wrong number (" + assertThat( "Wrong number (" + numCompilerWarnings + "/" + expectedWarnings + ") of compilation warnings: " - + displayLines( warnings ) ).isEqualTo( expectedWarnings ); + + displayLines( warnings ), numCompilerWarnings, is( expectedWarnings ) ); } - assertThat( files ).isEqualTo( new TreeSet<>( normalizePaths( expectedOutputFiles() ) ) ); + assertThat( files, containsInAnyOrder(normalizePaths(expectedOutputFiles()).toArray(new String[0]))); } protected String displayLines( List warnings) @@ -291,12 +297,9 @@ public String getSourceVersion() private List normalizePaths( Collection relativePaths ) { - List normalizedPaths = new ArrayList<>(); - for ( String relativePath : relativePaths ) - { - normalizedPaths.add( relativePath.replace( File.separatorChar, '/' ) ); - } - return normalizedPaths; + return relativePaths.stream() + .map( s -> s.replace( File.separatorChar, '/' ) ) + .collect(Collectors.toList()); } protected int compilerErrorCount( List messages ) diff --git a/plexus-compilers/plexus-compiler-csharp/pom.xml b/plexus-compilers/plexus-compiler-csharp/pom.xml index adcdedc6..bc60b549 100644 --- a/plexus-compilers/plexus-compiler-csharp/pom.xml +++ b/plexus-compilers/plexus-compiler-csharp/pom.xml @@ -22,5 +22,15 @@ org.codehaus.plexus plexus-utils + + org.junit.jupiter + junit-jupiter-api + test + + + org.hamcrest + hamcrest + test + diff --git a/plexus-compilers/plexus-compiler-csharp/src/test/java/org/codehaus/plexus/compiler/csharp/CSharpCompilerTest.java b/plexus-compilers/plexus-compiler-csharp/src/test/java/org/codehaus/plexus/compiler/csharp/CSharpCompilerTest.java index 3d353b40..8c9acfca 100644 --- a/plexus-compilers/plexus-compiler-csharp/src/test/java/org/codehaus/plexus/compiler/csharp/CSharpCompilerTest.java +++ b/plexus-compilers/plexus-compiler-csharp/src/test/java/org/codehaus/plexus/compiler/csharp/CSharpCompilerTest.java @@ -24,20 +24,26 @@ * SOFTWARE. */ -import junit.framework.TestCase; import org.codehaus.plexus.compiler.CompilerMessage; +import org.junit.jupiter.api.Test; import java.io.BufferedReader; import java.io.IOException; import java.io.StringReader; import java.util.List; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; + /** * @author Trygve Laugstøl */ public class CSharpCompilerTest - extends TestCase { + @Test public void testParser() throws IOException { @@ -49,32 +55,33 @@ public void testParser() error = DefaultCSharpCompilerParser.parseLine( "error CS2008: No files to compile were specified" ); - assertNotNull( error ); + assertThat(error, notNullValue()); + - assertEquals( "CS2008: No files to compile were specified", error.getMessage() ); + assertThat( error.getMessage(), is("CS2008: No files to compile were specified")); error = DefaultCSharpCompilerParser.parseLine( "Compilation failed: 1 error(s), 0 warnings" ); - assertNull( error ); + assertThat( error, nullValue() ); error = DefaultCSharpCompilerParser.parseLine( "Compilation succeeded - 2 warning(s)" ); - assertNull( error ); + assertThat( error, nullValue() ); error = DefaultCSharpCompilerParser.parseLine( "/home/trygvis/dev/com.myrealbox/trunk/mcs/nunit20/core/./TestRunnerThread.cs(29) error CS0246: Cannot find type 'NameValueCollection'" ); - assertNotNull( error ); + assertThat( error, notNullValue() ); - assertEquals( 29, error.getStartLine() ); + assertThat( error.getStartLine(), is(29)); - assertEquals( -1, error.getStartColumn() ); + assertThat( error.getStartColumn(), is(-1) ); - assertEquals( 29, error.getEndLine() ); + assertThat( error.getEndLine(), is(29) ); - assertEquals( -1, error.getEndColumn() ); + assertThat( error.getEndColumn(), is(-1) ); - assertEquals( "CS0246: Cannot find type 'NameValueCollection'", error.getMessage() ); + assertThat( error.getMessage(), is( "CS0246: Cannot find type 'NameValueCollection'" ) ); // ---------------------------------------------------------------------- // @@ -114,11 +121,12 @@ public void testParser() List messages = CSharpCompiler.parseCompilerOutput( new BufferedReader( new StringReader( input ) ) ); - assertNotNull( messages ); + assertThat( messages, notNullValue() ); - assertEquals( 14, messages.size() ); + assertThat( messages.size(), is(14) ); } + @Test public void testParserCscWin() throws Exception { @@ -175,17 +183,18 @@ public void testParserCscWin() List messagesWinCsc = CSharpCompiler.parseCompilerOutput( new BufferedReader( new StringReader( cscWin ) ) ); - assertNotNull( messagesWinCsc ); + assertThat( messagesWinCsc, notNullValue() ); - assertEquals( 24, messagesWinCsc.size() ); + assertThat( messagesWinCsc.size(), is(24) ); - assertTrue( "Check that the line number is not -1", - ( (CompilerMessage) messagesWinCsc.get( 0 ) ).getStartLine() != -1 ); - assertTrue( "Check that the column number is not -1", - ( (CompilerMessage) messagesWinCsc.get( 0 ) ).getStartColumn() != -1 ); + assertThat( "Check that the line number is not -1", + messagesWinCsc.get( 0 ).getStartLine(), not(-1) ); + assertThat( "Check that the column number is not -1", + messagesWinCsc.get( 0 ).getStartColumn(), not(-1) ); } + @Test public void testParserMonoWin() throws Exception { @@ -206,14 +215,14 @@ public void testParserMonoWin() List messagesMonoWin = CSharpCompiler.parseCompilerOutput( new BufferedReader( new StringReader( monoWin ) ) ); - assertNotNull( messagesMonoWin ); + assertThat( messagesMonoWin, notNullValue() ); - assertEquals( 5, messagesMonoWin.size() ); + assertThat( messagesMonoWin.size(), is(5) ); - assertTrue( "Check that the line number is not -1", - ( (CompilerMessage) messagesMonoWin.get( 0 ) ).getStartLine() != -1 ); - assertTrue( "Check that the column number is not -1", - ( (CompilerMessage) messagesMonoWin.get( 0 ) ).getStartColumn() != -1 ); + assertThat( "Check that the line number is not -1", + messagesMonoWin.get( 0 ).getStartLine(), not(-1) ); + assertThat( "Check that the column number is not -1", + messagesMonoWin.get( 0 ).getStartColumn(), not(-1) ); } diff --git a/plexus-compilers/plexus-compiler-eclipse/pom.xml b/plexus-compilers/plexus-compiler-eclipse/pom.xml index ab018a8e..113fb94f 100644 --- a/plexus-compilers/plexus-compiler-eclipse/pom.xml +++ b/plexus-compilers/plexus-compiler-eclipse/pom.xml @@ -32,11 +32,20 @@ plexus-component-annotations - org.assertj - assertj-core - 3.22.0 + org.junit.jupiter + junit-jupiter-api test + + org.hamcrest + hamcrest + test + + + org.codehaus.plexus + plexus-testing + compile + diff --git a/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerConfigurationTest.java b/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerConfigurationTest.java index 13c6333a..e14b0476 100644 --- a/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerConfigurationTest.java +++ b/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerConfigurationTest.java @@ -24,16 +24,21 @@ * SOFTWARE. */ -import junit.framework.TestCase; import org.codehaus.plexus.compiler.CompilerConfiguration; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.File; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.is; + public class EclipseCompilerConfigurationTest - extends TestCase { private static final String PROPERTIES_FILE_NAME = "src/test/resources".replace( "/", File.separator ) + File.separator @@ -42,70 +47,73 @@ public class EclipseCompilerConfigurationTest private CompilerConfiguration configuration; - @Override + @BeforeEach protected void setUp() { configuration = new CompilerConfiguration(); } + @Test public void testProcessCustomArgumentsWithMultipleAddExports() { configuration.addCompilerCustomArgument( "--add-exports", "FROM-MOD/package1=OTHER-MOD" ); configuration.addCompilerCustomArgument( "--add-exports", "FROM-MOD/package2=OTHER-MOD" ); List args = new ArrayList<>(); EclipseJavaCompiler.processCustomArguments( configuration, args ); - assertEquals( 4, args.size() ); - assertEquals( "--add-exports", args.get( 0 ) ); - assertEquals( "FROM-MOD/package1=OTHER-MOD", args.get( 1 ) ); - assertEquals( "--add-exports", args.get( 2 ) ); - assertEquals( "FROM-MOD/package2=OTHER-MOD", args.get( 3 ) ); + assertThat( args.size(), is(4) ); + assertThat( args, contains("--add-exports", "FROM-MOD/package1=OTHER-MOD", "--add-exports", "FROM-MOD/package2=OTHER-MOD")); +// assertThat( args.get( 0 ), is("--add-exports") ); +// assertThat( args.get( 1 ), is("FROM-MOD/package1=OTHER-MOD") ); +// assertThat( args.get( 2 ), is("--add-exports") ); +// assertThat( args.get( 3 ), is("FROM-MOD/package2=OTHER-MOD") ); } + @Test public void testProcessCustomArgumentsWithProceedOnError() { configuration.addCompilerCustomArgument( "-proceedOnError", null ); List args = new ArrayList<>(); EclipseJavaCompiler.processCustomArguments( configuration, args ); - assertEquals( 1, args.size() ); - assertEquals( "-proceedOnError:Fatal", args.get( 0 ) ); + assertThat( args.size(), is(1) ); + assertThat( args, contains("-proceedOnError:Fatal") ); } + @Test public void testProcessCustomArgumentsWithErrorsAsWarnings() { configuration.addCompilerCustomArgument( "errorsAsWarnings", null ); List args = new ArrayList<>(); final boolean errorsAsWarnings = EclipseJavaCompiler.processCustomArguments( configuration, args ); - assertTrue( errorsAsWarnings ); + assertThat( errorsAsWarnings, is(true) ); } + @Test public void testProcessCustomArgumentsWithErrorsAsWarningsAndMinus() { configuration.addCompilerCustomArgument( "-errorsAsWarnings", null ); List args = new ArrayList<>(); final boolean errorsAsWarnings = EclipseJavaCompiler.processCustomArguments( configuration, args ); - assertTrue( errorsAsWarnings ); + assertThat( errorsAsWarnings, is(true) ); } + @Test public void testProcessCustomArgumentsWithPropertiesAndNonExistingFile() { configuration.addCompilerCustomArgument( "-properties", "fooBar.txt" ); - try - { - EclipseJavaCompiler.processCustomArguments( configuration, Collections.emptyList() ); - fail( "IllegalArgumentException expected" ); - } catch ( IllegalArgumentException expected ) - { - assertEquals( "Properties file specified by -properties fooBar.txt does not exist", expected.getMessage() ); - } + IllegalArgumentException expected = + Assertions.assertThrows(IllegalArgumentException.class, + () -> EclipseJavaCompiler.processCustomArguments( configuration, Collections.emptyList() )); + assertThat( expected.getMessage(), + is( "Properties file specified by -properties fooBar.txt does not exist")); } + @Test public void testProcessCustomArgumentsWithPropertiesAndValidFile() { configuration.addCompilerCustomArgument( "-properties", PROPERTIES_FILE_NAME ); List args = new ArrayList<>(); EclipseJavaCompiler.processCustomArguments( configuration, args ); - assertEquals( 2, args.size() ); - assertEquals( "-properties", args.get( 0 ) ); - assertEquals( PROPERTIES_FILE_NAME, args.get( 1 ) ); + assertThat( args.size(), is(2)); + assertThat(args, contains("-properties", PROPERTIES_FILE_NAME)); } } diff --git a/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerDashedArgumentsTest.java b/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerDashedArgumentsTest.java index 8e9486e0..dc456488 100644 --- a/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerDashedArgumentsTest.java +++ b/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerDashedArgumentsTest.java @@ -24,26 +24,39 @@ * SOFTWARE. */ -import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.compiler.Compiler; import org.codehaus.plexus.compiler.CompilerConfiguration; +import org.codehaus.plexus.testing.PlexusTest; import org.codehaus.plexus.util.FileUtils; -import org.junit.Assert; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import javax.inject.Inject; +import javax.inject.Named; import java.io.File; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; +import static org.codehaus.plexus.testing.PlexusExtension.getBasedir; + + /** * @author Frits Jalvingh * Created on 22-4-18. */ -public class EclipseCompilerDashedArgumentsTest extends PlexusTestCase { +@PlexusTest +public class EclipseCompilerDashedArgumentsTest { public static final String BAD_DOUBLEDASH_OPTION = "--grubbelparkplace"; + @Inject + @Named("eclipse") + Compiler compiler; + private CompilerConfiguration getConfig() throws Exception { String sourceDir = getBasedir() + "/src/test-input/src/main"; @@ -80,21 +93,16 @@ private CompilerConfiguration getConfig() throws Exception { * This also tests that con-compile errors are shown properly, as the error caused by * the invalid option is not part of the error output but part of the data sent to stdout/stderr. */ + @Test public void testDoubleDashOptionsArePassedWithTwoDashes() throws Exception { - Compiler compiler = (Compiler) lookup( Compiler.ROLE, "eclipse" ); CompilerConfiguration config = getConfig(); config.addCompilerCustomArgument(BAD_DOUBLEDASH_OPTION, "b0rk3d"); - try - { - compiler.performCompile(config); - Assert.fail("Expected an exception to be thrown"); - } catch(EcjFailureException x) { - String ecjOutput = x.getEcjOutput(); - Assert.assertTrue("The output should report the failure with two dashes: " + ecjOutput - , ecjOutput.contains(BAD_DOUBLEDASH_OPTION) && ! ecjOutput.contains("-" + BAD_DOUBLEDASH_OPTION) - ); - } + EcjFailureException x = Assertions.assertThrows(EcjFailureException.class, () -> compiler.performCompile(config)); + + MatcherAssert.assertThat(x.getEcjOutput(), Matchers.containsString(BAD_DOUBLEDASH_OPTION)); + MatcherAssert.assertThat(x.getEcjOutput(), Matchers.not(Matchers.containsString("-" + BAD_DOUBLEDASH_OPTION))); + } } diff --git a/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerErrorsAsWarningsTest.java b/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerErrorsAsWarningsTest.java index c3a538ca..af0f44ab 100644 --- a/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerErrorsAsWarningsTest.java +++ b/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerErrorsAsWarningsTest.java @@ -43,14 +43,13 @@ protected int expectedWarnings() @Override protected Collection expectedOutputFiles() { - return Arrays.asList( new String[] { - "org/codehaus/foo/Deprecation.class", - "org/codehaus/foo/ExternalDeps.class", - "org/codehaus/foo/Person.class", - "org/codehaus/foo/ReservedWord.class", - //"org/codehaus/foo/Bad.class", // This one has no class file generated as it's one big issue - //"org/codehaus/foo/UnknownSymbol.class", - //"org/codehaus/foo/RightClassname.class" - }); + return Arrays.asList("org/codehaus/foo/Deprecation.class", + "org/codehaus/foo/ExternalDeps.class", + "org/codehaus/foo/Person.class", + "org/codehaus/foo/ReservedWord.class" + //"org/codehaus/foo/Bad.class", // This one has no class file generated as it's one big issue + //"org/codehaus/foo/UnknownSymbol.class", + //"org/codehaus/foo/RightClassname.class" + ); } } diff --git a/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerFailOnWarningsTest.java b/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerFailOnWarningsTest.java index b2f7f330..96756f58 100644 --- a/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerFailOnWarningsTest.java +++ b/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerFailOnWarningsTest.java @@ -35,11 +35,9 @@ protected int expectedWarnings() @Override protected Collection expectedOutputFiles() { - return Arrays.asList( new String[] { - "org/codehaus/foo/Deprecation.class", - "org/codehaus/foo/ExternalDeps.class", - "org/codehaus/foo/Person.class", - "org/codehaus/foo/ReservedWord.class" - }); + return Arrays.asList("org/codehaus/foo/Deprecation.class", + "org/codehaus/foo/ExternalDeps.class", + "org/codehaus/foo/Person.class", + "org/codehaus/foo/ReservedWord.class"); } } diff --git a/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerTckTest.java b/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerTckTest.java index c1999e0b..567a183c 100644 --- a/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerTckTest.java +++ b/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerTckTest.java @@ -34,6 +34,7 @@ public class EclipseCompilerTckTest { public EclipseCompilerTckTest() { - super( "eclipse" ); + this.roleHint = "eclipse"; + } } diff --git a/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerTest.java b/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerTest.java index ebcdee08..df224d94 100644 --- a/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerTest.java +++ b/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerTest.java @@ -29,12 +29,15 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.assertThat; + import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.Arrays; import java.util.Collection; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.startsWith; + /** * @author Jason van Zyl */ @@ -44,7 +47,6 @@ public class EclipseCompilerTest @BeforeEach public void setUp() - throws Exception { setCompilerDebug( true ); setCompilerDeprecationWarnings( true ); @@ -71,8 +73,8 @@ protected int expectedWarnings() @Override protected Collection expectedOutputFiles() { - return Arrays.asList( new String[] { "org/codehaus/foo/Deprecation.class", "org/codehaus/foo/ExternalDeps.class", - "org/codehaus/foo/Person.class", "org/codehaus/foo/ReservedWord.class" } ); + return Arrays.asList("org/codehaus/foo/Deprecation.class", "org/codehaus/foo/ExternalDeps.class", + "org/codehaus/foo/Person.class", "org/codehaus/foo/ReservedWord.class"); } // The test is fairly meaningless as we can not validate anything @@ -89,7 +91,6 @@ public void testCustomArgument() @Test public void testInitializeWarningsForPropertiesArgument() - throws Exception { CompilerConfiguration compilerConfig = createMinimalCompilerConfig(); @@ -97,7 +98,7 @@ public void testInitializeWarningsForPropertiesArgument() IllegalArgumentException e = assertThrows( IllegalArgumentException.class, () -> getCompiler().performCompile( compilerConfig ) ); - assertThat( e.getMessage() ).as( "Message must start with 'Properties file'" ).startsWith( "Properties file" ); + assertThat( "Message must start with 'Properties file'" , e.getMessage(), startsWith( "Properties file" )); } private CompilerConfiguration createMinimalCompilerConfig() diff --git a/plexus-compilers/plexus-compiler-j2objc/pom.xml b/plexus-compilers/plexus-compiler-j2objc/pom.xml index 60b13f96..31c9fd76 100644 --- a/plexus-compilers/plexus-compiler-j2objc/pom.xml +++ b/plexus-compilers/plexus-compiler-j2objc/pom.xml @@ -22,6 +22,16 @@ org.codehaus.plexus plexus-component-annotations + + org.junit.jupiter + junit-jupiter-api + test + + + org.hamcrest + hamcrest + test + diff --git a/plexus-compilers/plexus-compiler-j2objc/src/test/java/org/codehaus/plexus/compiler/j2objc/J2ObjCCompilerTest.java b/plexus-compilers/plexus-compiler-j2objc/src/test/java/org/codehaus/plexus/compiler/j2objc/J2ObjCCompilerTest.java index 386bda66..0e3f55bd 100644 --- a/plexus-compilers/plexus-compiler-j2objc/src/test/java/org/codehaus/plexus/compiler/j2objc/J2ObjCCompilerTest.java +++ b/plexus-compilers/plexus-compiler-j2objc/src/test/java/org/codehaus/plexus/compiler/j2objc/J2ObjCCompilerTest.java @@ -24,27 +24,27 @@ * SOFTWARE. */ -import org.junit.Assert; -import junit.framework.TestCase; +import org.hamcrest.io.FileMatchers; import org.codehaus.plexus.compiler.CompilerConfiguration; -import org.codehaus.plexus.compiler.CompilerException; +import org.junit.jupiter.api.Test; import java.io.File; -import java.io.IOException; import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import static org.hamcrest.MatcherAssert.assertThat; + /** * j2objc must be in the PATH * @author lmaitre */ public class J2ObjCCompilerTest - extends TestCase { + @Test public void testJ2ObjCCompiler() - throws IOException + throws Exception { J2ObjCCompiler comp = new J2ObjCCompiler(); Map customCompilerArguments = new HashMap<>(); @@ -57,18 +57,12 @@ public void testJ2ObjCCompiler() cc.setFork( true ); cc.setVerbose( true ); cc.setCustomCompilerArgumentsAsMap( customCompilerArguments ); - try - { - comp.performCompile( cc ); - File f = new File( "target/generated/objective-c/de/test/App.h" ); - Assert.assertTrue("file not exists:" + f, f.exists() ); - f = new File( "target/generated/objective-c/de/test/App.m" ); - Assert.assertTrue("file not exists:" + f, f.exists() ); - } - catch ( CompilerException ce ) - { - fail( "An exception has occured: " + ce.getMessage() ); - } + + comp.performCompile( cc ); + File f = new File( "target/generated/objective-c/de/test/App.h" ); + assertThat("file not exists:" + f, f, FileMatchers.anExistingFile()); + f = new File( "target/generated/objective-c/de/test/App.m" ); + assertThat("file not exists:" + f, f, FileMatchers.anExistingFile()); } } diff --git a/plexus-compilers/plexus-compiler-javac/pom.xml b/plexus-compilers/plexus-compiler-javac/pom.xml index 820c5153..7f0638de 100644 --- a/plexus-compilers/plexus-compiler-javac/pom.xml +++ b/plexus-compilers/plexus-compiler-javac/pom.xml @@ -23,9 +23,13 @@ plexus-component-annotations - org.assertj - assertj-core - 3.22.0 + org.junit.jupiter + junit-jupiter-api + test + + + org.hamcrest + hamcrest test diff --git a/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/AbstractJavacCompilerTest.java b/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/AbstractJavacCompilerTest.java index f233fdf7..d90ba447 100644 --- a/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/AbstractJavacCompilerTest.java +++ b/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/AbstractJavacCompilerTest.java @@ -27,6 +27,7 @@ import org.codehaus.plexus.compiler.AbstractCompilerTest; import org.codehaus.plexus.compiler.CompilerConfiguration; import org.codehaus.plexus.util.StringUtils; +import org.hamcrest.Matchers; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -38,7 +39,8 @@ import java.util.List; import java.util.Map; -import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; /** * @author Jason van Zyl @@ -50,11 +52,9 @@ public abstract class AbstractJavacCompilerTest @BeforeEach public void setUp() - throws Exception { setCompilerDebug( true ); setCompilerDeprecationWarnings( true ); - } @Override @@ -177,7 +177,7 @@ protected Collection expectedOutputFiles() "org/codehaus/foo/Person.class", "org/codehaus/foo/ReservedWord.class" } ); } - public void internalTest(CompilerConfiguration compilerConfiguration, List expectedArguments) { + protected void internalTest(CompilerConfiguration compilerConfiguration, List expectedArguments) { internalTest(compilerConfiguration, expectedArguments, new String[0]); } @@ -185,11 +185,12 @@ public void internalTest(CompilerConfiguration compilerConfiguration, ListTrygve Laugstøl */ public class ErrorMessageParserTest - extends TestCase { private static final String EOL = System.getProperty( "line.separator" ); + @Test public void testDeprecationMessage() throws Exception { @@ -54,21 +60,22 @@ public void testDeprecationMessage() CompilerMessage compilerError = JavacCompiler.parseModernError( 0, error ); - assertNotNull( compilerError ); + assertThat( compilerError, notNullValue() ); - assertFalse( compilerError.isError() ); + assertThat( compilerError.isError(), is( false)); - assertEquals( "Date(java.lang.String) in java.util.Date has been deprecated", compilerError.getMessage() ); + assertThat( compilerError.getMessage(), is("Date(java.lang.String) in java.util.Date has been deprecated") ); - assertEquals( 63, compilerError.getStartColumn() ); + assertThat( compilerError.getStartColumn(), is( 63 ) ); - assertEquals( 66, compilerError.getEndColumn() ); + assertThat( compilerError.getEndColumn(), is( 66 ) ); - assertEquals( 1, compilerError.getStartLine() ); + assertThat( compilerError.getStartLine(), is( 1 ) ); - assertEquals( 1, compilerError.getEndLine() ); + assertThat( compilerError.getEndLine(), is (1 ) ); } + @Test public void testWarningMessage() { String error = @@ -78,21 +85,22 @@ public void testWarningMessage() CompilerMessage compilerError = JavacCompiler.parseModernError( 0, error ); - assertNotNull( compilerError ); + assertThat( compilerError, notNullValue() ); - assertFalse( compilerError.isError() ); + assertThat( compilerError.isError(), is( false ) ); - assertEquals( "finally clause cannot complete normally", compilerError.getMessage() ); + assertThat( compilerError.getMessage(), is( "finally clause cannot complete normally" ) ); - assertEquals( 26, compilerError.getStartColumn() ); + assertThat( compilerError.getStartColumn(), is(26) ); - assertEquals( 27, compilerError.getEndColumn() ); + assertThat( compilerError.getEndColumn(), is(27) ); - assertEquals( 8, compilerError.getStartLine() ); + assertThat( compilerError.getStartLine(), is(8) ); - assertEquals( 8, compilerError.getEndLine() ); + assertThat( compilerError.getEndLine(), is(8) ); } + @Test public void testErrorMessage() { String error = "Foo.java:7: not a statement" + EOL + @@ -101,21 +109,22 @@ public void testErrorMessage() CompilerMessage compilerError = JavacCompiler.parseModernError( 1, error ); - assertNotNull( compilerError ); + assertThat( compilerError, notNullValue() ); - assertTrue( compilerError.isError() ); + assertThat( compilerError.isError(), is( true ) ); - assertEquals( "not a statement", compilerError.getMessage() ); + assertThat( compilerError.getMessage(), is("not a statement") ); - assertEquals( 9, compilerError.getStartColumn() ); + assertThat( compilerError.getStartColumn(), is(9) ); - assertEquals( 11, compilerError.getEndColumn() ); + assertThat( compilerError.getEndColumn(), is(11) ); - assertEquals( 7, compilerError.getStartLine() ); + assertThat( compilerError.getStartLine(), is(7) ); - assertEquals( 7, compilerError.getEndLine() ); + assertThat( compilerError.getEndLine(), is(7) ); } + @Test public void testUnknownSymbolError() { String error = "./org/codehaus/foo/UnknownSymbol.java:7: cannot find symbol" + EOL + @@ -126,23 +135,24 @@ public void testUnknownSymbolError() CompilerMessage compilerError = JavacCompiler.parseModernError( 1, error ); - assertNotNull( compilerError ); + assertThat( compilerError, notNullValue() ); - assertTrue( compilerError.isError() ); + assertThat( compilerError.isError(), is( true ) ); - assertEquals( "cannot find symbol" + EOL + - "symbol : method foo()" + EOL + - "location: class org.codehaus.foo.UnknownSymbol", compilerError.getMessage() ); + assertThat( compilerError.getMessage(), is("cannot find symbol" + EOL + + "symbol : method foo()" + EOL + + "location: class org.codehaus.foo.UnknownSymbol") ); - assertEquals( 8, compilerError.getStartColumn() ); + assertThat( compilerError.getStartColumn(), is(8) ); - assertEquals( 14, compilerError.getEndColumn() ); + assertThat( compilerError.getEndColumn(), is(14) ); - assertEquals( 7, compilerError.getStartLine() ); + assertThat( compilerError.getStartLine(), is(7) ); - assertEquals( 7, compilerError.getEndLine() ); + assertThat( compilerError.getEndLine(), is(7) ); } + @Test public void testTwoErrors() throws IOException { @@ -159,9 +169,10 @@ public void testTwoErrors() List messages = JavacCompiler.parseModernStream( 1, new BufferedReader( new StringReader( errors ) ) ); - assertEquals( 2, messages.size() ); + assertThat( messages.size(), is(2) ); } + @Test public void testAnotherTwoErrors() throws IOException { @@ -178,9 +189,10 @@ public void testAnotherTwoErrors() List messages = JavacCompiler.parseModernStream( 1, new BufferedReader( new StringReader( errors ) ) ); - assertEquals( 2, messages.size() ); + assertThat( messages.size(), is(2) ); } + @Test public void testAssertError() throws IOException { @@ -195,9 +207,10 @@ public void testAssertError() List messages = JavacCompiler.parseModernStream( 1, new BufferedReader( new StringReader( errors ) ) ); - assertEquals( 1, messages.size() ); + assertThat( messages.size(), is(1) ); } + @Test public void testLocalizedWarningNotTreatedAsError() throws IOException { @@ -211,10 +224,11 @@ public void testLocalizedWarningNotTreatedAsError() List messages = JavacCompiler.parseModernStream( 0, new BufferedReader( new StringReader( errors ) ) ); - assertEquals( 1, messages.size() ); - assertFalse( ( (CompilerMessage) messages.get( 0 ) ).isError() ); + assertThat( messages.size(), is(1) ); + assertThat( messages.get( 0 ).isError(), is(false) ); } + @Test public void testUnixFileNames() { String error = "/my/prj/src/main/java/test/prj/App.java:11: not a statement" + EOL + @@ -223,10 +237,10 @@ public void testUnixFileNames() CompilerMessage compilerError = JavacCompiler.parseModernError( 1, error ); - assertEquals( "/my/prj/src/main/java/test/prj/App.java:[11,45] not a statement", - String.valueOf( compilerError ) ); + assertThat( String.valueOf( compilerError ), is("/my/prj/src/main/java/test/prj/App.java:[11,45] not a statement")); } + @Test public void testWindowsDriveLettersMCOMPILER140() { String error = @@ -237,9 +251,8 @@ public void testWindowsDriveLettersMCOMPILER140() CompilerMessage compilerError = JavacCompiler.parseModernError( 1, error ); - assertEquals( - "c:\\Documents and Settings\\My Self\\Documents\\prj\\src\\main\\java\\test\\prj\\App.java:[11,45] not a statement", - String.valueOf( compilerError ) ); + assertThat( String.valueOf( compilerError ), + is("c:\\Documents and Settings\\My Self\\Documents\\prj\\src\\main\\java\\test\\prj\\App.java:[11,45] not a statement") ); } /** @@ -247,6 +260,7 @@ public void testWindowsDriveLettersMCOMPILER140() * * @throws Exception */ + @Test public void testCRLF_windows() throws Exception { @@ -623,7 +637,7 @@ public void testCRLF_windows() "4 warnings" + CRLF; List compilerMessages = JavacCompiler.parseModernStream( 0, new BufferedReader( new StringReader( errors ) ) ); - assertEquals( "count", 187, compilerMessages.size() ); + assertThat( "count", compilerMessages.size(), is(187) ); List compilerErrors = new ArrayList<>( 3 ); for ( CompilerMessage message : compilerMessages ) { if ( message.getKind() != CompilerMessage.Kind.OTHER ) { @@ -634,34 +648,35 @@ public void testCRLF_windows() assertEquivalent(new CompilerMessage("[options] bootstrap class path not set in conjunction with -source " + "1.6", CompilerMessage.Kind.WARNING), compilerErrors.get(0)); CompilerMessage error1 = compilerErrors.get( 1 ); - assertEquals( "file", - "C:\\commander\\pre\\ec\\ec-http\\src\\main\\java\\com\\electriccloud\\http\\HttpUtil.java", - error1.getFile() ); - assertEquals( "message", - "[deprecation] ThreadSafeClientConnManager in org.apache.http.impl.conn.tsccm has been deprecated", - error1.getMessage() ); - assertEquals( "line", 31, error1.getStartLine() ); - assertEquals( "column", 38, error1.getStartColumn() ); + assertThat( "file", + error1.getFile(), + is ("C:\\commander\\pre\\ec\\ec-http\\src\\main\\java\\com\\electriccloud\\http\\HttpUtil.java")); + assertThat( "message", + error1.getMessage(), + is("[deprecation] ThreadSafeClientConnManager in org.apache.http.impl.conn.tsccm has been deprecated")); + assertThat( "line", error1.getStartLine(), is(31) ); + assertThat( "column", error1.getStartColumn(), is(38) ); CompilerMessage error2 = compilerErrors.get( 2 ); - assertEquals( "file", - "C:\\commander\\pre\\ec\\ec-http\\src\\main\\java\\com\\electriccloud\\http\\HttpUtil.java", - error2.getFile() ); - assertEquals( "message", - "[deprecation] ThreadSafeClientConnManager in org.apache.http.impl.conn.tsccm has been deprecated", - error2.getMessage() ); - assertEquals( "line", 151, error2.getStartLine() ); - assertEquals( "column", 8, error2.getStartColumn() ); + assertThat( "file", + error2.getFile(), + is("C:\\commander\\pre\\ec\\ec-http\\src\\main\\java\\com\\electriccloud\\http\\HttpUtil.java")); + assertThat( "message", + error2.getMessage(), + is("[deprecation] ThreadSafeClientConnManager in org.apache.http.impl.conn.tsccm has been deprecated")); + assertThat( "line", error2.getStartLine(), is(151) ); + assertThat( "column", error2.getStartColumn() , is(8)); CompilerMessage error3 = compilerErrors.get( 3 ); - assertEquals( "file", - "C:\\commander\\pre\\ec\\ec-http\\src\\main\\java\\com\\electriccloud\\http\\HttpUtil.java", - error3.getFile() ); - assertEquals( "message", - "[deprecation] ThreadSafeClientConnManager in org.apache.http.impl.conn.tsccm has been deprecated", - error3.getMessage() ); - assertEquals( "line", 152, error3.getStartLine() ); - assertEquals( "column", 16, error3.getStartColumn() ); + assertThat( "file", + error3.getFile(), + is("C:\\commander\\pre\\ec\\ec-http\\src\\main\\java\\com\\electriccloud\\http\\HttpUtil.java")); + assertThat( "message", + error3.getMessage(), + is("[deprecation] ThreadSafeClientConnManager in org.apache.http.impl.conn.tsccm has been deprecated")); + assertThat( "line", error3.getStartLine(), is(152) ); + assertThat( "column", error3.getStartColumn(), is(16) ); } + @Test public void testJava6Error() throws Exception { String out = "Error.java:3: cannot find symbol" + EOL + @@ -678,41 +693,42 @@ public void testJava6Error() throws Exception List compilerErrors = JavacCompiler.parseModernStream( 1, new BufferedReader( new StringReader( out ) )); - assertNotNull( compilerErrors ); + assertThat( compilerErrors, notNullValue() ); CompilerMessage message1 = compilerErrors.get( 0 ); - assertTrue( message1.isError() ); + assertThat( message1.isError(), is(true) ); - assertEquals( "cannot find symbol" + EOL + - "symbol : class Properties" + EOL + - "location: class Error", message1.getMessage() ); + assertThat( message1.getMessage(), is ("cannot find symbol" + EOL + + "symbol : class Properties" + EOL + + "location: class Error") ); - assertEquals( 16, message1.getStartColumn() ); + assertThat( message1.getStartColumn(), is(16) ); - assertEquals( 26, message1.getEndColumn() ); + assertThat( message1.getEndColumn(), is(26) ); - assertEquals( 3, message1.getStartLine() ); + assertThat( message1.getStartLine(), is(3) ); - assertEquals( 3, message1.getEndLine() ); + assertThat( message1.getEndLine(), is(3) ); CompilerMessage message2 = compilerErrors.get( 1 ); - assertTrue( message2.isError() ); + assertThat( message2.isError(), is(true) ); - assertEquals( "cannot find symbol" + EOL + - "symbol : class Properties" + EOL + - "location: class Error", message2.getMessage() ); + assertThat( message2.getMessage(), is("cannot find symbol" + EOL + + "symbol : class Properties" + EOL + + "location: class Error") ); - assertEquals( 35, message2.getStartColumn() ); + assertThat( message2.getStartColumn(), is(35) ); - assertEquals( 48, message2.getEndColumn() ); + assertThat( message2.getEndColumn(), is(48) ); - assertEquals( 3, message2.getStartLine() ); + assertThat( message2.getStartLine(), is(3) ); - assertEquals( 3, message2.getEndLine() ); + assertThat( message2.getEndLine(), is(3) ); } - + + @Test public void testJava7Error() throws Exception { String out = "Error.java:3: error: cannot find symbol" + EOL + @@ -729,41 +745,42 @@ public void testJava7Error() throws Exception List compilerErrors = JavacCompiler.parseModernStream( 1, new BufferedReader( new StringReader( out ) )); - assertNotNull( compilerErrors ); + assertThat( compilerErrors, notNullValue() ); CompilerMessage message1 = compilerErrors.get( 0 ); + + assertThat( message1.isError(), is(true) ); - assertTrue( message1.isError() ); - - assertEquals( "error: cannot find symbol" + EOL + - " symbol: class Properties" + EOL + - " location: class Error", message1.getMessage() ); + assertThat( message1.getMessage(), is("error: cannot find symbol" + EOL + + " symbol: class Properties" + EOL + + " location: class Error") ); - assertEquals( 16, message1.getStartColumn() ); + assertThat( message1.getStartColumn(), is(16) ); - assertEquals( 26, message1.getEndColumn() ); + assertThat( message1.getEndColumn(), is(26) ); - assertEquals( 3, message1.getStartLine() ); + assertThat( message1.getStartLine(), is(3) ); - assertEquals( 3, message1.getEndLine() ); + assertThat( message1.getEndLine(), is(3) ); CompilerMessage message2 = compilerErrors.get( 1 ); - assertTrue( message2.isError() ); + assertThat( message2.isError(), is(true) ); - assertEquals( "error: cannot find symbol" + EOL + - " symbol: class Properties" + EOL + - " location: class Error", message2.getMessage() ); + assertThat( message2.getMessage(), is("error: cannot find symbol" + EOL + + " symbol: class Properties" + EOL + + " location: class Error") ); - assertEquals( 35, message2.getStartColumn() ); + assertThat( message2.getStartColumn(), is(35) ); - assertEquals( 48, message2.getEndColumn() ); + assertThat( message2.getEndColumn(), is(48) ); - assertEquals( 3, message2.getStartLine() ); + assertThat( message2.getStartLine(), is(3) ); - assertEquals( 3, message2.getEndLine() ); + assertThat( message2.getEndLine(), is(3) ); } - + + @Test public void testBugParade() throws Exception { String out = "An exception has occurred in the compiler (1.7.0_80). " @@ -773,12 +790,13 @@ public void testBugParade() throws Exception List compilerErrors = JavacCompiler.parseModernStream( 4, new BufferedReader( new StringReader( out ) )); - assertNotNull( compilerErrors ); + assertThat( compilerErrors, notNullValue() ); - assertEquals( 1, compilerErrors.size() ); + assertThat( compilerErrors.size(), is(1) ); } - public final void testNonAnchoredWarning() throws IOException { + @Test + public void testNonAnchoredWarning() throws IOException { final String error = "warning: [options] bootstrap class path not set in conjunction with -source 1.6" + EOL + "1 warning" + EOL; @@ -787,15 +805,16 @@ public final void testNonAnchoredWarning() throws IOException { StringReader( error))); - assertNotNull(compilerErrors); - assertEquals(1, compilerErrors.size()); + assertThat(compilerErrors, notNullValue()); + assertThat(compilerErrors.size(), is(1)); assertEquivalent( new CompilerMessage( "[options] bootstrap class path not set in conjunction with -source 1.6", CompilerMessage.Kind.WARNING), compilerErrors.get(0)); } - public final void testAnchoredWarning() throws IOException { + @Test + public void testAnchoredWarning() throws IOException { final String error = "C:\\repo\\src\\it\\includes-output-when-compiler-forked\\src\\main" + "\\java\\MyClass.java:23: warning: [divzero] division by zero" + EOL + @@ -806,15 +825,16 @@ public final void testAnchoredWarning() throws IOException { final List compilerErrors = JavacCompiler.parseModernStream(0, new BufferedReader(new StringReader(error))); - assertNotNull(compilerErrors); - assertEquals(1, compilerErrors.size()); + assertThat(compilerErrors, notNullValue()); + assertThat(compilerErrors.size(), is(1)); assertEquivalent( new CompilerMessage("C:\\repo\\src\\it\\includes-output-when-compiler-forked\\src\\main\\java\\MyClass" + ".java", CompilerMessage.Kind.WARNING, 23, 27, 23, 30, "[divzero] division by zero"), compilerErrors.get(0)); } - public final void testMixedWarnings() throws IOException { + @Test + public void testMixedWarnings() throws IOException { final String error = "warning: [options] bootstrap class path not set in conjunction with -source 1.6" + EOL + "C:\\repo\\src\\it\\includes-output-when-compiler-forked\\src\\main\\java" + @@ -826,8 +846,8 @@ public final void testMixedWarnings() throws IOException { final List compilerErrors = JavacCompiler.parseModernStream(0, new BufferedReader(new StringReader(error))); - assertNotNull(compilerErrors); - assertEquals(2, compilerErrors.size()); + assertThat(compilerErrors, notNullValue()); + assertThat(compilerErrors.size(), is(2)); assertEquivalent( new CompilerMessage( "[options] bootstrap class path not set in conjunction with -source 1.6", CompilerMessage.Kind.WARNING), @@ -838,8 +858,9 @@ public final void testMixedWarnings() throws IOException { compilerErrors.get(1)); } - public final void testIssue37() throws IOException { - final String error = + @Test + public void testIssue37() throws IOException { + String error = "warning: [path] bad path element \"d:\\maven_repo\\.m2\\repository\\org\\ow2\\asm\\asm-xml\\5.0.3\\asm-5.0.3.jar\": no such file or directory" + EOL + "warning: [path] bad path element \"d:\\maven_repo\\.m2\\repository\\org\\ow2\\asm\\asm-xml\\5.0.3\\asm-util-5.0.3.jar\": no such file or directory" + EOL + "warning: [options] bootstrap class path not set in conjunction with -source 1.7" + EOL + @@ -873,11 +894,11 @@ public final void testIssue37() throws IOException { "\tat jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57)" + EOL + "\tat jdk.compiler/com.sun.tools.javac.Main.main(Main.java:43)"; - final List compilerErrors = + List compilerErrors = JavacCompiler.parseModernStream(0, new BufferedReader(new StringReader(error))); - assertNotNull( compilerErrors ); - assertEquals(4, compilerErrors.size()); + assertThat( compilerErrors, notNullValue()); + assertThat(compilerErrors.size(), is(4)); assertEquivalent(new CompilerMessage("[path] bad path element \"d:\\maven_repo\\" + ".m2\\repository\\org\\ow2\\asm\\asm-xml\\5.0.3\\asm-5.0.3.jar\": no such file or directory", @@ -887,13 +908,14 @@ public final void testIssue37() throws IOException { assertEquivalent(new CompilerMessage("[options] bootstrap class path not set in conjunction with -source 1.7", CompilerMessage.Kind.WARNING), compilerErrors.get(2)); - final CompilerMessage finalMessage = compilerErrors.get(3); - assertEquals(CompilerMessage.Kind.ERROR, finalMessage.getKind()); - assertTrue("Starts correctly", finalMessage.getMessage().startsWith("An exception has occurred in the compiler")); - assertTrue("continues through end of output", finalMessage.getMessage().endsWith("\tat jdk.compiler/com.sun" + + CompilerMessage finalMessage = compilerErrors.get(3); + assertThat( finalMessage.getKind(), is(CompilerMessage.Kind.ERROR)); + assertThat("Starts correctly", finalMessage.getMessage(), startsWith("An exception has occurred in the compiler")); + assertThat("continues through end of output", finalMessage.getMessage(), endsWith("\tat jdk.compiler/com.sun" + ".tools.javac.Main.main(Main.java:43)" + EOL)); } + @Test public void testJvmError() throws Exception { String out = "Error occurred during initialization of boot layer" + EOL + @@ -901,11 +923,12 @@ public void testJvmError() throws Exception List compilerErrors = JavacCompiler.parseModernStream( 1, new BufferedReader( new StringReader( out ) )); - assertNotNull( compilerErrors ); + assertThat( compilerErrors, notNullValue()); - assertEquals( 1, compilerErrors.size() ); + assertThat( compilerErrors.size(), is(1) ); } + @Test public void testBadSourceFileError() throws Exception { String out = "/MTOOLCHAINS-19/src/main/java/ch/pecunifex/x/Cls1.java:12: error: cannot access Cls2\n" + @@ -917,14 +940,15 @@ public void testBadSourceFileError() throws Exception List compilerErrors = JavacCompiler.parseModernStream( 1, new BufferedReader( new StringReader( out ) )); - assertNotNull( compilerErrors ); + assertThat( compilerErrors, notNullValue() ); - assertEquals( 1, compilerErrors.size() ); + assertThat( compilerErrors.size(), is(1)); - final CompilerMessage message = compilerErrors.get( 0 ); + CompilerMessage message = compilerErrors.get( 0 ); validateBadSourceFile(message); } + @Test public void testWarningFollowedByBadSourceFileError() throws Exception { String out = "/MTOOLCHAINS-19/src/main/java/ch/pecunifex/x/Cls1.java:3: warning: FontDesignMetrics is internal proprietary API and may be removed in a future release\n" + @@ -939,33 +963,37 @@ public void testWarningFollowedByBadSourceFileError() throws Exception List compilerErrors = JavacCompiler.parseModernStream( 1, new BufferedReader( new StringReader( out ) )); - assertNotNull( compilerErrors ); + assertThat( compilerErrors, notNullValue()); - assertEquals( 2, compilerErrors.size() ); + assertThat( compilerErrors, hasSize(2) ); - final CompilerMessage firstMessage = compilerErrors.get( 0 ); - assertEquals( "Is a Warning", CompilerMessage.Kind.WARNING, firstMessage.getKind() ); - assertEquals( "On Correct File","/MTOOLCHAINS-19/src/main/java/ch/pecunifex/x/Cls1.java", firstMessage.getFile() ); - assertEquals( "Internal API Warning", "FontDesignMetrics is internal proprietary API and may be removed in a future release", firstMessage.getMessage() ); + CompilerMessage firstMessage = compilerErrors.get( 0 ); + assertThat( "Is a Warning", firstMessage.getKind(), + is(CompilerMessage.Kind.WARNING) ); + assertThat( "On Correct File",firstMessage.getFile(), + is("/MTOOLCHAINS-19/src/main/java/ch/pecunifex/x/Cls1.java") ); + assertThat( "Internal API Warning", + firstMessage.getMessage(), + is("FontDesignMetrics is internal proprietary API and may be removed in a future release")); - final CompilerMessage secondMessage = compilerErrors.get( 1 ); + CompilerMessage secondMessage = compilerErrors.get( 1 ); validateBadSourceFile(secondMessage); } private void validateBadSourceFile(CompilerMessage message) { - assertEquals( "Is an Error", CompilerMessage.Kind.ERROR, message.getKind() ); - assertEquals( "On Correct File","/MTOOLCHAINS-19/src/main/java/ch/pecunifex/x/Cls1.java", message.getFile() ); - assertTrue( "Message starts with access Error", message.getMessage().startsWith("error: cannot access Cls2") ); + assertThat( "Is an Error", message.getKind(), is(CompilerMessage.Kind.ERROR) ); + assertThat( "On Correct File",message.getFile(), is("/MTOOLCHAINS-19/src/main/java/ch/pecunifex/x/Cls1.java") ); + assertThat( "Message starts with access Error", message.getMessage(), startsWith("error: cannot access Cls2") ); } private static void assertEquivalent(CompilerMessage expected, CompilerMessage actual){ - assertEquals("Message did not match", expected.getMessage(), actual.getMessage()); - assertEquals("Kind did not match", expected.getKind(), actual.getKind()); - assertEquals("File did not match", expected.getFile(), actual.getFile()); - assertEquals( "Start line did not match", expected.getStartLine(), actual.getStartLine()); - assertEquals( "Start column did not match", expected.getStartColumn(), actual.getStartColumn()); - assertEquals("End line did not match", expected.getEndLine(), actual.getEndLine()); - assertEquals("End column did not match", expected.getEndColumn(), actual.getEndColumn()); + assertThat("Message did not match",actual.getMessage(), is( expected.getMessage())); + assertThat("Kind did not match", actual.getKind(), is(expected.getKind())); + assertThat("File did not match", actual.getFile(), is(expected.getFile())); + assertThat( "Start line did not match", actual.getStartLine(), is(expected.getStartLine())); + assertThat( "Start column did not match", actual.getStartColumn(), is(expected.getStartColumn())); + assertThat("End line did not match", actual.getEndLine(), is(expected.getEndLine())); + assertThat("End column did not match", actual.getEndColumn(), is(expected.getEndColumn())); } } diff --git a/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/JavacCompilerTest.java b/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/JavacCompilerTest.java index b36ee9f0..1830ef69 100644 --- a/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/JavacCompilerTest.java +++ b/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/JavacCompilerTest.java @@ -29,7 +29,6 @@ public class JavacCompilerTest { @BeforeEach public void setUp() - throws Exception { super.setUp(); setForceJavacCompilerUse( true ); diff --git a/pom.xml b/pom.xml index 2cbb5998..0ef6d1e1 100644 --- a/pom.xml +++ b/pom.xml @@ -49,6 +49,7 @@ 5.8.2 1.9.7.M3 2.10.0 + false @@ -89,6 +90,16 @@ test ${jupiter.version} + + org.codehaus.plexus + plexus-testing + 1.1.0 + + + org.hamcrest + hamcrest + 2.2 + @@ -193,16 +204,6 @@ - - - - org.codehaus.mojo - cobertura-maven-plugin - 2.7 - - - -