diff --git a/plexus-java/pom.xml b/plexus-java/pom.xml index 070999a..0313067 100644 --- a/plexus-java/pom.xml +++ b/plexus-java/pom.xml @@ -28,28 +28,20 @@ 1 true - - - org.hamcrest - hamcrest - 2.2 - test - - org.hamcrest - hamcrest-library - 2.2 + org.junit.jupiter + junit-jupiter test - junit - junit - 4.13.2 + org.mockito + mockito-core + 4.11.0 test org.mockito - mockito-core + mockito-junit-jupiter 4.11.0 test @@ -59,6 +51,12 @@ 6.0.0 test + + org.assertj + assertj-core + 3.24.2 + test + diff --git a/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/AbstractFilenameModuleNameExtractorTest.java b/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/AbstractFilenameModuleNameExtractorTest.java index 1db8b8c..76c8736 100644 --- a/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/AbstractFilenameModuleNameExtractorTest.java +++ b/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/AbstractFilenameModuleNameExtractorTest.java @@ -21,43 +21,35 @@ import java.nio.file.Paths; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.CoreMatchers.startsWith; -import static org.junit.Assert.assertEquals; -import static org.junit.Assume.assumeThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; public abstract class AbstractFilenameModuleNameExtractorTest { protected abstract ModuleNameExtractor getExtractor(); - @BeforeClass - public static void assume() { - assumeThat("Requires at least Java 9", System.getProperty("java.version"), not(startsWith("1."))); - } - @Test - public void testJarWithoutManifest() throws Exception { + void testJarWithoutManifest() throws Exception { String name = getExtractor().extract(Paths.get("src/test/resources/jar.empty/plexus-java-1.0.0-SNAPSHOT.jar")); assertEquals("plexus.java", name); } @Test - public void testJarWithManifest() throws Exception { + void testJarWithManifest() throws Exception { String name = getExtractor() .extract(Paths.get("src/test/resources/jar.manifest.with/plexus-java-1.0.0-SNAPSHOT.jar")); assertEquals("org.codehaus.plexus.languages.java", name); } @Test - public void testJarUnsupported() throws Exception { + void testJarUnsupported() throws Exception { String name = getExtractor().extract(Paths.get("src/test/resources/jar.unsupported/jdom-1.0.jar")); - assertEquals(null, name); + assertNull(name); } @Test - public void testJarWithSpacesInPath() throws Exception { + void testJarWithSpacesInPath() throws Exception { String name = getExtractor() .extract(Paths.get("src/test/resources/jar with spaces in path/plexus-java-1.0.0-SNAPSHOT.jar")); assertEquals("org.codehaus.plexus.languages.java", name); diff --git a/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/BinaryModuleInfoParserTest.java b/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/BinaryModuleInfoParserTest.java index f7aa257..5ed2f0d 100644 --- a/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/BinaryModuleInfoParserTest.java +++ b/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/BinaryModuleInfoParserTest.java @@ -33,28 +33,29 @@ import org.codehaus.plexus.languages.java.jpms.JavaModuleDescriptor.JavaProvides; import org.codehaus.plexus.languages.java.jpms.JavaModuleDescriptor.JavaRequires; import org.codehaus.plexus.languages.java.version.JavaVersion; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; -public class BinaryModuleInfoParserTest { - private BinaryModuleInfoParser parser = new BinaryModuleInfoParser(); +class BinaryModuleInfoParserTest { + private final BinaryModuleInfoParser parser = new BinaryModuleInfoParser(); @Test - public void testJarDescriptor() throws Exception { + void testJarDescriptor() throws Exception { JavaModuleDescriptor descriptor = parser.getModuleDescriptor(Paths.get("src/test/resources/jar.descriptor/asm-6.0_BETA.jar")); assertNotNull(descriptor); - assertEquals("org.objectweb.asm", descriptor.name()); - assertEquals(false, descriptor.isAutomatic()); + assertThat(descriptor.name()).isEqualTo("org.objectweb.asm"); + assertFalse(descriptor.isAutomatic()); - assertEquals(1, descriptor.requires().size()); + assertThat(descriptor.requires()).hasSize(1); assertEquals("java.base", descriptor.requires().iterator().next().name()); Set expectedExports = JavaModuleDescriptor.newAutomaticModule("_") @@ -66,17 +67,17 @@ public void testJarDescriptor() throws Exception { } @Test - public void testMultiReleaseJarDescriptor() throws Exception { + void testMultiReleaseJarDescriptor() throws Exception { JavaModuleDescriptor descriptor = parser.getModuleDescriptor( Paths.get("src/test/resources/jar.mr.descriptor/jloadr-1.0-SNAPSHOT.jar"), JavaVersion.parse("17")); assertNotNull(descriptor); assertEquals("de.adito.jloadr", descriptor.name()); - assertEquals(false, descriptor.isAutomatic()); + assertFalse(descriptor.isAutomatic()); } @Test - public void testIncompleteMultiReleaseJarDescriptor() throws Exception { + void testIncompleteMultiReleaseJarDescriptor() throws Exception { // this jar is missing the Multi-Release: true entry in the Manifest JavaModuleDescriptor descriptor = parser.getModuleDescriptor( Paths.get("src/test/resources/jar.mr.incomplete.descriptor/jloadr-1.0-SNAPSHOT.jar")); @@ -85,7 +86,7 @@ public void testIncompleteMultiReleaseJarDescriptor() throws Exception { } @Test - public void testClassicJar() throws Exception { + void testClassicJar() throws Exception { JavaModuleDescriptor descriptor = parser.getModuleDescriptor(Paths.get("src/test/resources/jar.empty/plexus-java-1.0.0-SNAPSHOT.jar")); @@ -93,15 +94,15 @@ public void testClassicJar() throws Exception { } @Test - public void testOutputDirectoryDescriptor() throws Exception { + void testOutputDirectoryDescriptor() throws Exception { JavaModuleDescriptor descriptor = parser.getModuleDescriptor(Paths.get("src/test/resources/dir.descriptor/out")); assertNotNull(descriptor); assertEquals("org.codehaus.plexus.languages.java.demo", descriptor.name()); - assertEquals(false, descriptor.isAutomatic()); + assertFalse(descriptor.isAutomatic()); - assertEquals(3, descriptor.requires().size()); + assertThat(descriptor.requires()).hasSize(3); Set expectedRequires = JavaModuleDescriptor.newAutomaticModule("_") .requires("java.base") @@ -113,19 +114,21 @@ public void testOutputDirectoryDescriptor() throws Exception { assertEquals(expectedRequires, descriptor.requires()); } - @Test(expected = NoSuchFileException.class) - public void testClassicOutputDirectory() throws Exception { - parser.getModuleDescriptor(Paths.get("src/test/resources/dir.empty/out")); + @Test + void testClassicOutputDirectory() { + assertThrows( + NoSuchFileException.class, + () -> parser.getModuleDescriptor(Paths.get("src/test/resources/dir.empty/out"))); } @Test - public void testJModDescriptor() throws Exception { + void testJModDescriptor() throws Exception { JavaModuleDescriptor descriptor = parser.getModuleDescriptor( Paths.get("src/test/resources/jmod.descriptor/first-jmod-1.0-SNAPSHOT.jmod")); assertNotNull(descriptor); assertEquals("com.corporate.project", descriptor.name()); - assertEquals(false, descriptor.isAutomatic()); + assertFalse(descriptor.isAutomatic()); assertEquals(1, descriptor.requires().size()); assertEquals("java.base", descriptor.requires().iterator().next().name()); @@ -135,13 +138,14 @@ public void testJModDescriptor() throws Exception { "com.corporate.project", descriptor.exports().iterator().next().source()); } - @Test(expected = IOException.class) - public void testInvalidFile() throws Exception { - parser.getModuleDescriptor(Paths.get("src/test/resources/nonjar/pom.xml")); + @Test + void testInvalidFile() { + assertThrows( + IOException.class, () -> parser.getModuleDescriptor(Paths.get("src/test/resources/nonjar/pom.xml"))); } @Test - public void testUses() throws Exception { + void testUses() throws Exception { try (InputStream is = Files.newInputStream(Paths.get("src/test/resources/dir.descriptor.uses/out/module-info.class"))) { JavaModuleDescriptor descriptor = parser.parse(is); @@ -157,7 +161,7 @@ public void testUses() throws Exception { } @Test - public void testProvides() throws Exception { + void testProvides() throws Exception { JavaModuleDescriptor descriptor = parser.getModuleDescriptor(Paths.get("src/test/resources/jar.service/threeten-extra-1.4.jar")); @@ -182,13 +186,13 @@ public void testProvides() throws Exception { } @Test - public void testRequires() throws Exception { + void testRequires() throws Exception { try (InputStream is = Files.newInputStream(Paths.get("src/test/resources/dir.descriptor.requires/out/module-info.class"))) { JavaModuleDescriptor descriptor = parser.parse(is); assertNotNull(descriptor); - assertThat(descriptor.requires().size(), is(5)); + assertThat(descriptor.requires()).hasSize(5); Set expectedRequires = JavaModuleDescriptor.newAutomaticModule("_") .requires("java.base") @@ -196,7 +200,7 @@ public void testRequires() throws Exception { .requires(Collections.singleton(JavaRequires.JavaModifier.STATIC), "mod_r_s") .requires(Collections.singleton(JavaRequires.JavaModifier.TRANSITIVE), "mod_r_t") .requires( - new HashSet(Arrays.asList( + new HashSet<>(Arrays.asList( JavaRequires.JavaModifier.STATIC, JavaRequires.JavaModifier.TRANSITIVE)), "mod_r_s_t") .build() diff --git a/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/CmdModuleNameExtractorTest.java b/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/CmdModuleNameExtractorTest.java index e0536c1..6527f47 100644 --- a/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/CmdModuleNameExtractorTest.java +++ b/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/CmdModuleNameExtractorTest.java @@ -21,15 +21,15 @@ import java.nio.file.Path; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; -public class CmdModuleNameExtractorTest { +class CmdModuleNameExtractorTest { @Test - public void testMethodCount() throws Exception { + void testMethodCount() throws Exception { // ensure that both implementations are in sync - assertEquals(2, CmdModuleNameExtractor.class.getDeclaredMethods().length); + assertThat(CmdModuleNameExtractor.class.getDeclaredMethods().length).isEqualTo(2); // if these don't exist, a NoSuchMethodException is thrown CmdModuleNameExtractor.class.getDeclaredMethod("main", String[].class); diff --git a/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/LocationManagerIT.java b/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/LocationManagerIT.java index ee243b2..934eb2c 100644 --- a/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/LocationManagerIT.java +++ b/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/LocationManagerIT.java @@ -24,17 +24,16 @@ import java.util.Arrays; import java.util.Collections; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnJre; +import org.junit.jupiter.api.condition.JRE; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.CoreMatchers.startsWith; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assume.assumeThat; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -44,8 +43,9 @@ * * @author Robert Scholte */ -@RunWith(org.mockito.junit.MockitoJUnitRunner.class) -public class LocationManagerIT { +@DisabledOnJre(value = JRE.JAVA_8, disabledReason = "Requires Java 9+ Module System") +@ExtendWith(MockitoExtension.class) +class LocationManagerIT { @Mock private BinaryModuleInfoParser asmParser; @@ -56,13 +56,8 @@ public class LocationManagerIT { final Path mockModuleInfoJava = Paths.get("src/test/resources/mock/module-info.java"); - @BeforeClass - public static void assume() { - assumeThat("Requires at least Java 9", System.getProperty("java.version"), not(startsWith("1."))); - } - - @Before - public void onSetup() { + @BeforeEach + void onSetup() { locationManager = new LocationManager(qdoxParser) { @Override ModuleInfoParser getBinaryModuleInfoParser(Path jdkHome) { @@ -72,7 +67,7 @@ ModuleInfoParser getBinaryModuleInfoParser(Path jdkHome) { } @Test - public void testManifestWithoutReflectRequires() throws Exception { + void testManifestWithoutReflectRequires() throws Exception { Path abc = Paths.get("src/test/resources/manifest.without/out"); JavaModuleDescriptor descriptor = JavaModuleDescriptor.newModule("base").requires("any").build(); @@ -82,15 +77,15 @@ public void testManifestWithoutReflectRequires() throws Exception { ResolvePathsResult result = locationManager.resolvePaths(request); - assertThat(result.getPathExceptions().size(), is(0)); - assertThat(result.getMainModuleDescriptor(), is(descriptor)); - assertThat(result.getPathElements().size(), is(1)); - assertThat(result.getModulepathElements().size(), is(0)); - assertThat(result.getClasspathElements().size(), is(1)); + assertThat(result.getPathExceptions()).hasSize(0); + assertThat(result.getMainModuleDescriptor()).isEqualTo(descriptor); + assertThat(result.getPathElements()).hasSize(1); + assertThat(result.getModulepathElements()).hasSize(0); + assertThat(result.getClasspathElements()).hasSize(1); } @Test - public void testEmptyWithReflectRequires() throws Exception { + void testEmptyWithReflectRequires() throws Exception { Path abc = Paths.get("src/test/resources/empty/out"); JavaModuleDescriptor descriptor = JavaModuleDescriptor.newModule("base").requires("a.b.c").build(); @@ -100,34 +95,32 @@ public void testEmptyWithReflectRequires() throws Exception { ResolvePathsResult result = locationManager.resolvePaths(request); - assertThat(result.getPathExceptions().size(), is(0)); - assertThat(result.getMainModuleDescriptor(), is(descriptor)); - assertThat(result.getPathElements().size(), is(1)); - assertThat(result.getModulepathElements().size(), is(0)); - assertThat(result.getClasspathElements().size(), is(1)); + assertThat(result.getPathExceptions()).hasSize(0); + assertThat(result.getMainModuleDescriptor()).isEqualTo(descriptor); + assertThat(result.getPathElements()).hasSize(1); + assertThat(result.getModulepathElements()).hasSize(0); + assertThat(result.getClasspathElements()).hasSize(1); } - @Test(expected = RuntimeException.class) - public void testResolvePathWithException() throws Exception { - assumeThat("Requires at least Java 9", System.getProperty("java.version"), not(startsWith("1."))); - - Path p = Paths.get("src/test/resources/jar.empty.invalid.name/101-1.0.0-SNAPSHOT.jar"); - ResolvePathRequest request = ResolvePathRequest.ofPath(p); + @Test + void testResolvePathWithException() { + assertThrows(RuntimeException.class, () -> { + Path p = Paths.get("src/test/resources/jar.empty.invalid.name/101-1.0.0-SNAPSHOT.jar"); + ResolvePathRequest request = ResolvePathRequest.ofPath(p); - locationManager.resolvePath(request); + locationManager.resolvePath(request); + }); } @Test - public void testClassicJarNameStartsWithNumber() throws Exception { - assumeThat("Requires at least Java 9", System.getProperty("java.version"), not(startsWith("1."))); - + void testClassicJarNameStartsWithNumber() throws Exception { Path p = Paths.get("src/test/resources/jar.empty.invalid.name/101-1.0.0-SNAPSHOT.jar"); ResolvePathsRequest request = ResolvePathsRequest.ofPaths(Arrays.asList(p)).setMainModuleDescriptor(mockModuleInfoJava); ResolvePathsResult result = locationManager.resolvePaths(request); - assertThat(result.getPathExceptions().size(), is(1)); - assertThat(result.getClasspathElements().size(), is(1)); + assertThat(result.getPathExceptions()).hasSize(1); + assertThat(result.getClasspathElements()).hasSize(1); } } diff --git a/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/LocationManagerTest.java b/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/LocationManagerTest.java index 09de41a..acd825d 100644 --- a/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/LocationManagerTest.java +++ b/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/LocationManagerTest.java @@ -27,31 +27,27 @@ import java.util.HashSet; import org.codehaus.plexus.languages.java.jpms.JavaModuleDescriptor.JavaRequires.JavaModifier; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.hamcrest.MatcherAssert.assertThat; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -@RunWith(org.mockito.junit.MockitoJUnitRunner.class) -public class LocationManagerTest { - @Mock +class LocationManagerTest { private BinaryModuleInfoParser asmParser; - @Mock private SourceModuleInfoParser qdoxParser; private LocationManager locationManager; final Path mockModuleInfoJava = Paths.get("src/test/resources/mock/module-info.java"); - @Before - public void onSetup() { + @BeforeEach + void onSetup() { + asmParser = mock(BinaryModuleInfoParser.class); + qdoxParser = mock(SourceModuleInfoParser.class); locationManager = new LocationManager(qdoxParser) { @Override ModuleInfoParser getBinaryModuleInfoParser(Path jdkHome) { @@ -61,18 +57,18 @@ ModuleInfoParser getBinaryModuleInfoParser(Path jdkHome) { } @Test - public void testNoPaths() throws Exception { + void testNoPaths() throws Exception { ResolvePathsResult result = locationManager.resolvePaths(ResolvePathsRequest.ofFiles(Collections.emptyList())); - assertThat(result.getMainModuleDescriptor(), nullValue(JavaModuleDescriptor.class)); - assertThat(result.getPathElements().size(), is(0)); - assertThat(result.getModulepathElements().size(), is(0)); - assertThat(result.getClasspathElements().size(), is(0)); - assertThat(result.getPathExceptions().size(), is(0)); + assertThat(result.getMainModuleDescriptor()).isNull(); + assertThat(result.getPathElements()).hasSize(0); + assertThat(result.getModulepathElements()).hasSize(0); + assertThat(result.getClasspathElements()).hasSize(0); + assertThat(result.getPathExceptions()).hasSize(0); } @Test - public void testWithUnknownRequires() throws Exception { + void testWithUnknownRequires() throws Exception { JavaModuleDescriptor descriptor = JavaModuleDescriptor.newModule("base") .requires("java.base") .requires("jdk.net") @@ -83,15 +79,15 @@ public void testWithUnknownRequires() throws Exception { ResolvePathsResult result = locationManager.resolvePaths(request); - assertThat(result.getMainModuleDescriptor(), is(descriptor)); - assertThat(result.getPathElements().size(), is(0)); - assertThat(result.getModulepathElements().size(), is(0)); - assertThat(result.getClasspathElements().size(), is(0)); - assertThat(result.getPathExceptions().size(), is(0)); + assertThat(result.getMainModuleDescriptor()).isEqualTo(descriptor); + assertThat(result.getPathElements()).hasSize(0); + assertThat(result.getModulepathElements()).hasSize(0); + assertThat(result.getClasspathElements()).hasSize(0); + assertThat(result.getPathExceptions()).hasSize(0); } @Test - public void testManifestWithReflectRequires() throws Exception { + void testManifestWithReflectRequires() throws Exception { Path abc = Paths.get("src/test/resources/dir.manifest.with/out"); JavaModuleDescriptor descriptor = JavaModuleDescriptor.newModule("base") .requires("auto.by.manifest") @@ -102,16 +98,16 @@ public void testManifestWithReflectRequires() throws Exception { ResolvePathsResult result = locationManager.resolvePaths(request); - assertThat(result.getMainModuleDescriptor(), is(descriptor)); - assertThat(result.getPathElements().size(), is(1)); - assertThat(result.getModulepathElements().size(), is(1)); - assertThat(result.getModulepathElements().get(abc), is(ModuleNameSource.MANIFEST)); - assertThat(result.getClasspathElements().size(), is(0)); - assertThat(result.getPathExceptions().size(), is(0)); + assertThat(result.getMainModuleDescriptor()).isEqualTo(descriptor); + assertThat(result.getPathElements()).hasSize(1); + assertThat(result.getModulepathElements()).hasSize(1); + assertThat(result.getModulepathElements().get(abc)).isEqualTo(ModuleNameSource.MANIFEST); + assertThat(result.getClasspathElements()).hasSize(0); + assertThat(result.getPathExceptions()).hasSize(0); } @Test - public void testDirDescriptorWithReflectRequires() throws Exception { + void testDirDescriptorWithReflectRequires() throws Exception { Path abc = Paths.get("src/test/resources/dir.descriptor/out"); JavaModuleDescriptor descriptor = JavaModuleDescriptor.newModule("base") .requires("dir.descriptor") @@ -125,16 +121,16 @@ public void testDirDescriptorWithReflectRequires() throws Exception { ResolvePathsResult result = locationManager.resolvePaths(request); - assertThat(result.getMainModuleDescriptor(), is(descriptor)); - assertThat(result.getPathElements().size(), is(1)); - assertThat(result.getModulepathElements().size(), is(1)); - assertThat(result.getModulepathElements().get(abc), is(ModuleNameSource.MODULEDESCRIPTOR)); - assertThat(result.getClasspathElements().size(), is(0)); - assertThat(result.getPathExceptions().size(), is(0)); + assertThat(result.getMainModuleDescriptor()).isEqualTo(descriptor); + assertThat(result.getPathElements()).hasSize(1); + assertThat(result.getModulepathElements()).hasSize(1); + assertThat(result.getModulepathElements().get(abc)).isEqualTo(ModuleNameSource.MODULEDESCRIPTOR); + assertThat(result.getClasspathElements()).hasSize(0); + assertThat(result.getPathExceptions()).hasSize(0); } @Test - public void testJarWithAsmRequires() throws Exception { + void testJarWithAsmRequires() throws Exception { Path abc = Paths.get("src/test/resources/jar.descriptor/asm-6.0_BETA.jar"); JavaModuleDescriptor descriptor = JavaModuleDescriptor.newModule("base") .requires("org.objectweb.asm") @@ -147,17 +143,16 @@ public void testJarWithAsmRequires() throws Exception { .thenReturn(JavaModuleDescriptor.newModule("org.objectweb.asm").build()); ResolvePathsResult result = locationManager.resolvePaths(request); - - assertThat(result.getMainModuleDescriptor(), is(descriptor)); - assertThat(result.getPathElements().size(), is(1)); - assertThat(result.getModulepathElements().size(), is(1)); - assertThat(result.getModulepathElements().get(abc), is(ModuleNameSource.MODULEDESCRIPTOR)); - assertThat(result.getClasspathElements().size(), is(0)); - assertThat(result.getPathExceptions().size(), is(0)); + assertThat(result.getMainModuleDescriptor()).isEqualTo(descriptor); + assertThat(result.getPathElements()).hasSize(1); + assertThat(result.getModulepathElements()).hasSize(1); + assertThat(result.getModulepathElements().get(abc)).isEqualTo(ModuleNameSource.MODULEDESCRIPTOR); + assertThat(result.getClasspathElements()).hasSize(0); + assertThat(result.getPathExceptions()).hasSize(0); } @Test - public void testIdenticalModuleNames() throws Exception { + void testIdenticalModuleNames() throws Exception { Path pj1 = Paths.get("src/test/resources/jar.empty/plexus-java-1.0.0-SNAPSHOT.jar"); Path pj2 = Paths.get("src/test/resources/jar.empty.2/plexus-java-2.0.0-SNAPSHOT.jar"); JavaModuleDescriptor descriptor = @@ -174,18 +169,16 @@ public void testIdenticalModuleNames() throws Exception { JavaModuleDescriptor.newAutomaticModule("plexus.java").build()); ResolvePathsResult result = locationManager.resolvePaths(request); - - assertThat(result.getMainModuleDescriptor(), is(descriptor)); - assertThat(result.getPathElements().size(), is(2)); - assertThat(result.getModulepathElements().size(), is(1)); - assertThat(result.getModulepathElements().containsKey(pj1), is(true)); - assertThat(result.getModulepathElements().containsKey(pj2), is(false)); - assertThat(result.getClasspathElements().size(), is(0)); - assertThat(result.getPathExceptions().size(), is(0)); + assertThat(result.getMainModuleDescriptor()).isEqualTo(descriptor); + assertThat(result.getPathElements()).hasSize(2); + assertThat(result.getModulepathElements()).containsOnlyKeys(pj1); + assertThat(result.getModulepathElements()).doesNotContainKey(pj2); + assertThat(result.getClasspathElements()).hasSize(0); + assertThat(result.getPathExceptions()).hasSize(0); } @Test - public void testNonJar() throws Exception { + void testNonJar() throws Exception { Path p = Paths.get("src/test/resources/nonjar/pom.xml"); ResolvePathsRequest request = @@ -193,11 +186,11 @@ public void testNonJar() throws Exception { ResolvePathsResult result = locationManager.resolvePaths(request); - assertThat(result.getPathExceptions().size(), is(1)); + assertThat(result.getPathExceptions()).hasSize(1); } @Test - public void testAdditionalModules() throws Exception { + void testAdditionalModules() throws Exception { Path p = Paths.get("src/test/resources/mock/jar0.jar"); JavaModuleDescriptor descriptor = JavaModuleDescriptor.newModule("base").build(); @@ -211,16 +204,15 @@ public void testAdditionalModules() throws Exception { JavaModuleDescriptor.newAutomaticModule("plexus.java").build()); ResolvePathsResult result = locationManager.resolvePaths(request); - - assertThat(result.getMainModuleDescriptor(), is(descriptor)); - assertThat(result.getPathElements().size(), is(1)); - assertThat(result.getModulepathElements().size(), is(1)); - assertThat(result.getClasspathElements().size(), is(0)); - assertThat(result.getPathExceptions().size(), is(0)); + assertThat(result.getMainModuleDescriptor()).isEqualTo(descriptor); + assertThat(result.getPathElements()).hasSize(1); + assertThat(result.getModulepathElements()).hasSize(1); + assertThat(result.getClasspathElements()).hasSize(0); + assertThat(result.getPathExceptions()).hasSize(0); } @Test - public void testResolvePath() throws Exception { + void testResolvePath() throws Exception { Path abc = Paths.get("src/test/resources/mock/jar0.jar"); ResolvePathRequest request = ResolvePathRequest.ofPath(abc); @@ -229,14 +221,13 @@ public void testResolvePath() throws Exception { ResolvePathResult result = locationManager.resolvePath(request); - assertThat( - result.getModuleDescriptor(), - is(JavaModuleDescriptor.newModule("org.objectweb.asm").build())); - assertThat(result.getModuleNameSource(), is(ModuleNameSource.MODULEDESCRIPTOR)); + assertThat(result.getModuleDescriptor()) + .isEqualTo(JavaModuleDescriptor.newModule("org.objectweb.asm").build()); + assertThat(result.getModuleNameSource()).isEqualTo(ModuleNameSource.MODULEDESCRIPTOR); } @Test - public void testNoMatchingProviders() throws Exception { + void testNoMatchingProviders() throws Exception { Path abc = Paths.get("src/test/resources/mock/module-info.java"); // some file called module-info.java Path def = Paths.get("src/test/resources/mock/jar0.jar"); // any existing file ResolvePathsRequest request = @@ -250,14 +241,14 @@ public void testNoMatchingProviders() throws Exception { .build()); ResolvePathsResult result = locationManager.resolvePaths(request); - assertThat(result.getPathElements().size(), is(1)); - assertThat(result.getModulepathElements().size(), is(0)); - assertThat(result.getClasspathElements().size(), is(1)); - assertThat(result.getPathExceptions().size(), is(0)); + assertThat(result.getPathElements()).hasSize(1); + assertThat(result.getModulepathElements()).hasSize(0); + assertThat(result.getClasspathElements()).hasSize(1); + assertThat(result.getPathExceptions()).hasSize(0); } @Test - public void testMainModuleDescriptorWithProviders() throws Exception { + void testMainModuleDescriptorWithProviders() throws Exception { Path abc = Paths.get("src/test/resources/mock/module-info.java"); // some file called module-info.java Path def = Paths.get("src/test/resources/mock/jar0.jar"); // any existing file ResolvePathsRequest request = @@ -271,14 +262,14 @@ public void testMainModuleDescriptorWithProviders() throws Exception { .build()); ResolvePathsResult result = locationManager.resolvePaths(request); - assertThat(result.getPathElements().size(), is(1)); - assertThat(result.getModulepathElements().size(), is(1)); - assertThat(result.getClasspathElements().size(), is(0)); - assertThat(result.getPathExceptions().size(), is(0)); + assertThat(result.getPathElements()).hasSize(1); + assertThat(result.getModulepathElements()).hasSize(1); + assertThat(result.getClasspathElements()).hasSize(0); + assertThat(result.getPathExceptions()).hasSize(0); } @Test - public void testMainModuleDescriptorWithProvidersDontIncludeProviders() throws Exception { + void testMainModuleDescriptorWithProvidersDontIncludeProviders() throws Exception { Path abc = Paths.get("src/test/resources/mock/module-info.java"); // some file called module-info.java Path def = Paths.get("src/test/resources/mock/jar0.jar"); // any existing file ResolvePathsRequest request = ResolvePathsRequest.ofPaths(def).setMainModuleDescriptor(abc); @@ -291,14 +282,14 @@ public void testMainModuleDescriptorWithProvidersDontIncludeProviders() throws E .build()); ResolvePathsResult result = locationManager.resolvePaths(request); - assertThat(result.getPathElements().size(), is(1)); - assertThat(result.getModulepathElements().size(), is(0)); - assertThat(result.getClasspathElements().size(), is(1)); - assertThat(result.getPathExceptions().size(), is(0)); + assertThat(result.getPathElements()).hasSize(1); + assertThat(result.getModulepathElements()).hasSize(0); + assertThat(result.getClasspathElements()).hasSize(1); + assertThat(result.getPathExceptions()).hasSize(0); } @Test - public void testTransitiveProviders() throws Exception { + void testTransitiveProviders() throws Exception { Path abc = Paths.get("src/test/resources/mock/module-info.java"); // some file called module-info.java Path def = Paths.get("src/test/resources/mock/jar0.jar"); // any existing file Path ghi = Paths.get("src/test/resources/mock/jar1.jar"); // any existing file @@ -317,14 +308,14 @@ public void testTransitiveProviders() throws Exception { .thenReturn(JavaModuleDescriptor.newModule("ghi").uses("tool").build()); ResolvePathsResult result = locationManager.resolvePaths(request); - assertThat(result.getPathElements().size(), is(2)); - assertThat(result.getModulepathElements().size(), is(2)); - assertThat(result.getClasspathElements().size(), is(0)); - assertThat(result.getPathExceptions().size(), is(0)); + assertThat(result.getPathElements()).hasSize(2); + assertThat(result.getModulepathElements()).hasSize(2); + assertThat(result.getClasspathElements()).hasSize(0); + assertThat(result.getPathExceptions()).hasSize(0); } @Test - public void testDontIncludeProviders() throws Exception { + void testDontIncludeProviders() throws Exception { Path abc = Paths.get("src/test/resources/mock/module-info.java"); // some file called module-info.java Path def = Paths.get("src/test/resources/mock/jar0.jar"); // any existing file Path ghi = Paths.get("src/test/resources/mock/jar1.jar"); // any existing file @@ -342,14 +333,14 @@ public void testDontIncludeProviders() throws Exception { .thenReturn(JavaModuleDescriptor.newModule("ghi").uses("tool").build()); ResolvePathsResult result = locationManager.resolvePaths(request); - assertThat(result.getPathElements().size(), is(2)); - assertThat(result.getModulepathElements().size(), is(1)); - assertThat(result.getClasspathElements().size(), is(1)); - assertThat(result.getPathExceptions().size(), is(0)); + assertThat(result.getPathElements()).hasSize(2); + assertThat(result.getModulepathElements()).hasSize(1); + assertThat(result.getClasspathElements()).hasSize(1); + assertThat(result.getPathExceptions()).hasSize(0); } @Test - public void testAllowAdditionalModulesWithoutMainDescriptor() throws Exception { + void testAllowAdditionalModulesWithoutMainDescriptor() throws Exception { Path def = Paths.get("src/test/resources/mock/jar0.jar"); // any existing file Path ghi = Paths.get("src/test/resources/mock/jar1.jar"); // any existing file ResolvePathsRequest request = @@ -361,15 +352,14 @@ public void testAllowAdditionalModulesWithoutMainDescriptor() throws Exception { .thenReturn(JavaModuleDescriptor.newModule("ghi").build()); ResolvePathsResult result = locationManager.resolvePaths(request); - - assertThat(result.getPathElements().size(), is(2)); - assertThat(result.getModulepathElements().size(), is(1)); - assertThat(result.getClasspathElements().size(), is(1)); - assertThat(result.getPathExceptions().size(), is(0)); + assertThat(result.getPathElements()).hasSize(2); + assertThat(result.getModulepathElements()).hasSize(1); + assertThat(result.getClasspathElements()).hasSize(1); + assertThat(result.getPathExceptions()).hasSize(0); } @Test - public void testReuseModuleDescriptor() throws Exception { + void testReuseModuleDescriptor() throws Exception { Path def = Paths.get("src/test/resources/mock/jar0.jar"); ResolvePathRequest request1 = ResolvePathRequest.ofPath(def); @@ -383,30 +373,30 @@ public void testReuseModuleDescriptor() throws Exception { ResolvePathsResult result2 = locationManager.resolvePaths(request2); - assertThat(result1.getModuleDescriptor(), is(result2.getMainModuleDescriptor())); + assertThat(result1.getModuleDescriptor()).isEqualTo(result2.getMainModuleDescriptor()); } @Test - public void testParseModuleDescriptor() throws Exception { + void testParseModuleDescriptor() throws Exception { Path descriptorPath = Paths.get("src/test/resources/src.dir/module-info.java"); when(qdoxParser.fromSourcePath(descriptorPath)) .thenReturn(JavaModuleDescriptor.newModule("a.b.c").build()); ResolvePathResult result = locationManager.parseModuleDescriptor(descriptorPath); - assertThat(result.getModuleNameSource(), is(ModuleNameSource.MODULEDESCRIPTOR)); - assertThat(result.getModuleDescriptor().name(), is("a.b.c")); + assertThat(result.getModuleNameSource()).isEqualTo(ModuleNameSource.MODULEDESCRIPTOR); + assertThat(result.getModuleDescriptor().name()).isEqualTo("a.b.c"); locationManager.parseModuleDescriptor(descriptorPath.toFile()); - assertThat(result.getModuleNameSource(), is(ModuleNameSource.MODULEDESCRIPTOR)); - assertThat(result.getModuleDescriptor().name(), is("a.b.c")); + assertThat(result.getModuleNameSource()).isEqualTo(ModuleNameSource.MODULEDESCRIPTOR); + assertThat(result.getModuleDescriptor().name()).isEqualTo("a.b.c"); locationManager.parseModuleDescriptor(descriptorPath.toString()); - assertThat(result.getModuleNameSource(), is(ModuleNameSource.MODULEDESCRIPTOR)); - assertThat(result.getModuleDescriptor().name(), is("a.b.c")); + assertThat(result.getModuleNameSource()).isEqualTo(ModuleNameSource.MODULEDESCRIPTOR); + assertThat(result.getModuleDescriptor().name()).isEqualTo("a.b.c"); } @Test - public void testTransitiveStatic() throws Exception { + void testTransitiveStatic() throws Exception { Path moduleA = Paths.get("src/test/resources/mock/module-info.java"); // some file called module-info.java Path moduleB = Paths.get("src/test/resources/mock/jar0.jar"); // any existing file Path moduleC = Paths.get("src/test/resources/mock/jar1.jar"); // any existing file @@ -425,14 +415,14 @@ public void testTransitiveStatic() throws Exception { .thenReturn(JavaModuleDescriptor.newModule("moduleC").build()); ResolvePathsResult result = locationManager.resolvePaths(request); - assertThat(result.getPathElements().size(), is(2)); - assertThat(result.getModulepathElements().size(), is(1)); - assertThat(result.getClasspathElements().size(), is(1)); - assertThat(result.getPathExceptions().size(), is(0)); + assertThat(result.getPathElements()).hasSize(2); + assertThat(result.getModulepathElements()).hasSize(1); + assertThat(result.getClasspathElements()).hasSize(1); + assertThat(result.getPathExceptions()).hasSize(0); } @Test - public void testDirectStatic() throws Exception { + void testDirectStatic() throws Exception { Path moduleA = Paths.get("src/test/resources/mock/module-info.java"); // some file called module-info.java Path moduleB = Paths.get("src/test/resources/mock/jar0.jar"); // any existing file Path moduleC = Paths.get("src/test/resources/mock/jar1.jar"); // any existing file @@ -456,20 +446,14 @@ public void testDirectStatic() throws Exception { .thenReturn(JavaModuleDescriptor.newModule("moduleD").build()); ResolvePathsResult result = locationManager.resolvePaths(request); - assertThat(result.getPathElements().size(), is(3)); - assertThat( - "content: " + result.getModulepathElements(), - result.getModulepathElements().size(), - is(2)); - assertThat(result.getModulepathElements().containsKey(moduleB), is(true)); - assertThat(result.getModulepathElements().containsKey(moduleD), is(true)); - assertThat(result.getClasspathElements().size(), is(1)); - assertThat(result.getClasspathElements().contains(moduleC), is(true)); - assertThat(result.getPathExceptions().size(), is(0)); + assertThat(result.getPathElements()).hasSize(3); + assertThat(result.getModulepathElements()).containsOnlyKeys(moduleB, moduleD); + assertThat(result.getClasspathElements()).containsOnly(moduleC); + assertThat(result.getPathExceptions()).hasSize(0); } @Test - public void testDuplicateModule() throws Exception { + void testDuplicateModule() throws Exception { Path moduleA = Paths.get("src/test/resources/mock/module-info.java"); // some file called module-info.java Path moduleB = Paths.get("src/test/resources/mock/jar0.jar"); // any existing file Path moduleC = Paths.get("src/test/resources/mock/jar1.jar"); // any existing file @@ -487,16 +471,15 @@ public void testDuplicateModule() throws Exception { .thenReturn(JavaModuleDescriptor.newModule("anonymous").build()); ResolvePathsResult result = locationManager.resolvePaths(request); - assertThat(result.getPathElements().size(), is(2)); - assertThat(result.getModulepathElements().size(), is(1)); - assertThat(result.getModulepathElements().containsKey(moduleB), is(true)); + assertThat(result.getPathElements()).hasSize(2); + assertThat(result.getModulepathElements()).containsOnlyKeys(moduleB); // with current default the duplicate will be ignored - assertThat(result.getClasspathElements().size(), is(0)); - assertThat(result.getPathExceptions().size(), is(0)); + assertThat(result.getClasspathElements()).hasSize(0); + assertThat(result.getPathExceptions()).hasSize(0); } @Test - public void testStaticTransitive() throws Exception { + void testStaticTransitive() throws Exception { Path moduleA = Paths.get("src/test/resources/mock/module-info.java"); // some file called module-info.java Path moduleB = Paths.get("src/test/resources/mock/jar0.jar"); // any existing file Path moduleC = Paths.get("src/test/resources/mock/jar1.jar"); // any existing file @@ -520,23 +503,17 @@ public void testStaticTransitive() throws Exception { .thenReturn(JavaModuleDescriptor.newModule("moduleD").build()); ResolvePathsResult result = locationManager.resolvePaths(request); - assertThat(result.getPathElements().size(), is(3)); - assertThat( - "modulepathelements:" + result.getModulepathElements(), - result.getModulepathElements().size(), - is(2)); - assertThat(result.getModulepathElements().containsKey(moduleB), is(true)); - assertThat(result.getModulepathElements().containsKey(moduleC), is(true)); - assertThat(result.getClasspathElements().size(), is(1)); - assertThat(result.getClasspathElements().contains(moduleD), is(true)); - assertThat(result.getPathExceptions().size(), is(0)); + assertThat(result.getPathElements()).hasSize(3); + assertThat(result.getModulepathElements()).containsOnlyKeys(moduleB, moduleC); + assertThat(result.getClasspathElements()).containsOnly(moduleD); + assertThat(result.getPathExceptions()).hasSize(0); } - @Test /** - * test case for https://issues.apache.org/jira/browse/MCOMPILER-481 + * test case for MCOMPILER-481 */ - public void includeDeeperRequiresStatic() throws Exception { + @Test + void includeDeeperRequiresStatic() throws Exception { Path moduleA = Paths.get("src/test/resources/mock/module-info.java"); // some file called module-info.java Path moduleB = Paths.get("src/test/resources/mock/jar0.jar"); // any existing file Path moduleC = Paths.get("src/test/resources/mock/jar1.jar"); // any existing file @@ -555,19 +532,14 @@ public void includeDeeperRequiresStatic() throws Exception { .thenReturn(JavaModuleDescriptor.newModule("moduleC").build()); ResolvePathsResult result = locationManager.resolvePaths(request); - assertThat( - "modulepathelements:" + result.getModulepathElements(), - result.getModulepathElements().size(), - is(2)); - assertThat(result.getModulepathElements().containsKey(moduleB), is(true)); - assertThat(result.getModulepathElements().containsKey(moduleC), is(true)); + assertThat(result.getModulepathElements()).containsOnlyKeys(moduleB, moduleC); } - @Test /** - * test case for https://issues.apache.org/jira/browse/MCOMPILER-482 + * test case for MCOMPILER-482 */ - public void includeDeeperRequiresStaticTransitive() throws Exception { + @Test + void includeDeeperRequiresStaticTransitive() throws Exception { Path moduleA = Paths.get("src/test/resources/mock/module-info.java"); // some file called module-info.java core Path moduleB = Paths.get("src/test/resources/mock/jar0.jar"); // any existing file Path moduleC = Paths.get("src/test/resources/mock/jar1.jar"); // any existing file @@ -592,12 +564,6 @@ public void includeDeeperRequiresStaticTransitive() throws Exception { .thenReturn(JavaModuleDescriptor.newModule("moduleD").build()); ResolvePathsResult result = locationManager.resolvePaths(request); - assertThat( - "modulepathelements:" + result.getModulepathElements(), - result.getModulepathElements().size(), - is(3)); - assertThat(result.getModulepathElements().containsKey(moduleB), is(true)); - assertThat(result.getModulepathElements().containsKey(moduleC), is(true)); - assertThat(result.getModulepathElements().containsKey(moduleD), is(true)); + assertThat(result.getModulepathElements()).containsOnlyKeys(moduleB, moduleC, moduleD); } } diff --git a/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/MainClassModuleNameExtractorTest.java b/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/MainClassModuleNameExtractorTest.java index 57d2b1a..f3d3662 100644 --- a/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/MainClassModuleNameExtractorTest.java +++ b/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/MainClassModuleNameExtractorTest.java @@ -24,11 +24,15 @@ import java.nio.file.Paths; import java.util.Collections; +import org.junit.jupiter.api.condition.DisabledOnJre; +import org.junit.jupiter.api.condition.JRE; + +@DisabledOnJre(value = JRE.JAVA_8, disabledReason = "Requires Java 9+ Module System") public class MainClassModuleNameExtractorTest extends AbstractFilenameModuleNameExtractorTest { @Override protected ModuleNameExtractor getExtractor() { return new ModuleNameExtractor() { - MainClassModuleNameExtractor extractor = + final MainClassModuleNameExtractor extractor = new MainClassModuleNameExtractor(Paths.get(System.getProperty("java.home"))); @Override diff --git a/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/ManifestModuleNameExtractorTest.java b/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/ManifestModuleNameExtractorTest.java index 35e21d6..7360585 100644 --- a/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/ManifestModuleNameExtractorTest.java +++ b/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/ManifestModuleNameExtractorTest.java @@ -20,38 +20,38 @@ */ import java.nio.file.Paths; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; -public class ManifestModuleNameExtractorTest { +class ManifestModuleNameExtractorTest { private ManifestModuleNameExtractor extractor = new ManifestModuleNameExtractor(); @Test - public void testNoManifestInJar() throws Exception { + void testNoManifestInJar() throws Exception { assertNull(extractor.extract(Paths.get("src/test/resources/jar.name/plexus-java-1.0.0-SNAPSHOT.jar"))); } @Test - public void testManifestInJar() throws Exception { + void testManifestInJar() throws Exception { assertEquals( "org.codehaus.plexus.languages.java", extractor.extract(Paths.get("src/test/resources/jar.manifest.with/plexus-java-1.0.0-SNAPSHOT.jar"))); } @Test - public void testNoManifestInDir() throws Exception { + void testNoManifestInDir() throws Exception { assertNull(extractor.extract(Paths.get("src/test/resources/empty/out"))); } @Test - public void testEmptyManifestInDir() throws Exception { + void testEmptyManifestInDir() throws Exception { assertNull(extractor.extract(Paths.get("src/test/resources/manifest.without/out"))); } @Test - public void testManifestInDir() throws Exception { + void testManifestInDir() throws Exception { assertEquals("auto.by.manifest", extractor.extract(Paths.get("src/test/resources/dir.manifest.with/out"))); } } diff --git a/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/SourceModuleInfoParserTest.java b/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/SourceModuleInfoParserTest.java index ef85a95..eecd015 100644 --- a/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/SourceModuleInfoParserTest.java +++ b/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/SourceModuleInfoParserTest.java @@ -28,18 +28,18 @@ import org.codehaus.plexus.languages.java.jpms.JavaModuleDescriptor.JavaExports; import org.codehaus.plexus.languages.java.jpms.JavaModuleDescriptor.JavaProvides; import org.codehaus.plexus.languages.java.jpms.JavaModuleDescriptor.JavaRequires; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class SourceModuleInfoParserTest { - private SourceModuleInfoParser parser = new SourceModuleInfoParser(); +class SourceModuleInfoParserTest { + private final SourceModuleInfoParser parser = new SourceModuleInfoParser(); @Test - public void test() throws Exception { + void test() throws Exception { JavaModuleDescriptor moduleDescriptor = parser.fromSourcePath(Paths.get("src/test/resources/src.dir/module-info.java")); assertEquals("a.b.c", moduleDescriptor.name()); diff --git a/plexus-java/src/test/java/org/codehaus/plexus/languages/java/version/JavaVersionTest.java b/plexus-java/src/test/java/org/codehaus/plexus/languages/java/version/JavaVersionTest.java index 3e1cbd0..de1db99 100644 --- a/plexus-java/src/test/java/org/codehaus/plexus/languages/java/version/JavaVersionTest.java +++ b/plexus-java/src/test/java/org/codehaus/plexus/languages/java/version/JavaVersionTest.java @@ -19,68 +19,79 @@ * under the License. */ -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /* * Parsing is lazy, only triggered when comparing */ -public class JavaVersionTest { +class JavaVersionTest { @Test - public void testParse() throws Exception { - assertTrue(JavaVersion.parse("1.4").compareTo(JavaVersion.parse("1.4.2")) < 0); - assertTrue(JavaVersion.parse("1.4").compareTo(JavaVersion.parse("1.5")) < 0); - assertTrue(JavaVersion.parse("1.8").compareTo(JavaVersion.parse("9")) < 0); - - assertTrue(JavaVersion.parse("1.4").compareTo(JavaVersion.parse("1.4")) == 0); - assertTrue(JavaVersion.parse("1.4.2").compareTo(JavaVersion.parse("1.4.2")) == 0); - assertTrue(JavaVersion.parse("9").compareTo(JavaVersion.parse("9")) == 0); - - assertTrue(JavaVersion.parse("1.4.2").compareTo(JavaVersion.parse("1.4")) > 0); - assertTrue(JavaVersion.parse("1.5").compareTo(JavaVersion.parse("1.4")) > 0); - assertTrue(JavaVersion.parse("9").compareTo(JavaVersion.parse("1.8")) > 0); + void testParse() { + assertThat(JavaVersion.parse("1.4").compareTo(JavaVersion.parse("1.4.2"))) + .isLessThan(0); + assertThat(JavaVersion.parse("1.4").compareTo(JavaVersion.parse("1.5"))).isLessThan(0); + assertThat(JavaVersion.parse("1.8").compareTo(JavaVersion.parse("9"))).isLessThan(0); + + assertThat(JavaVersion.parse("1.4").compareTo(JavaVersion.parse("1.4"))).isEqualTo(0); + assertThat(JavaVersion.parse("1.4.2").compareTo(JavaVersion.parse("1.4.2"))) + .isEqualTo(0); + assertThat(JavaVersion.parse("9").compareTo(JavaVersion.parse("9"))).isEqualTo(0); + + assertThat(JavaVersion.parse("1.4.2").compareTo(JavaVersion.parse("1.4"))) + .isGreaterThan(0); + assertThat(JavaVersion.parse("1.5").compareTo(JavaVersion.parse("1.4"))).isGreaterThan(0); + assertThat(JavaVersion.parse("9").compareTo(JavaVersion.parse("1.8"))).isGreaterThan(0); } @Test - public void testVersionNamingExamples() { + void testVersionNamingExamples() { // All GA (FCS) versions are ordered based on the standard dot-notation. For example: 1.3.0 < 1.3.0_01 < 1.3.1 < // 1.3.1_01. // Source: http://www.oracle.com/technetwork/java/javase/versioning-naming-139433.html - assertTrue(JavaVersion.parse("1.3.0").compareTo(JavaVersion.parse("1.3.0_01")) < 0); - assertTrue(JavaVersion.parse("1.3.0_01").compareTo(JavaVersion.parse("1.3.1")) < 0); - assertTrue(JavaVersion.parse("1.3.1").compareTo(JavaVersion.parse("1.3.1_01")) < 0); + assertThat(JavaVersion.parse("1.3.0").compareTo(JavaVersion.parse("1.3.0_01"))) + .isLessThan(0); + assertThat(JavaVersion.parse("1.3.0_01").compareTo(JavaVersion.parse("1.3.1"))) + .isLessThan(0); + assertThat(JavaVersion.parse("1.3.1").compareTo(JavaVersion.parse("1.3.1_01"))) + .isLessThan(0); - assertTrue(JavaVersion.parse("1.3.0").compareTo(JavaVersion.parse("1.3.0-b24")) < 0); + assertThat(JavaVersion.parse("1.3.0").compareTo(JavaVersion.parse("1.3.0-b24"))) + .isLessThan(0); } @Test - public void testJEP223Short() { + void testJEP223Short() { // http://openjdk.java.net/jeps/223 - assertTrue(JavaVersion.parse("9-ea").compareTo(JavaVersion.parse("9")) < 0); - assertTrue(JavaVersion.parse("9").compareTo(JavaVersion.parse("9.0.1")) < 0); - assertTrue(JavaVersion.parse("9.0.1").compareTo(JavaVersion.parse("9.0.2")) < 0); - assertTrue(JavaVersion.parse("9.0.2").compareTo(JavaVersion.parse("9.1.2")) < 0); - assertTrue(JavaVersion.parse("9.1.2").compareTo(JavaVersion.parse("9.1.3")) < 0); - assertTrue(JavaVersion.parse("9.1.3").compareTo(JavaVersion.parse("9.1.4")) < 0); - assertTrue(JavaVersion.parse("9.1.4").compareTo(JavaVersion.parse("9.2.4")) < 0); + assertThat(JavaVersion.parse("9-ea").compareTo(JavaVersion.parse("9"))).isLessThan(0); + assertThat(JavaVersion.parse("9").compareTo(JavaVersion.parse("9.0.1"))).isLessThan(0); + assertThat(JavaVersion.parse("9.0.1").compareTo(JavaVersion.parse("9.0.2"))) + .isLessThan(0); + assertThat(JavaVersion.parse("9.0.2").compareTo(JavaVersion.parse("9.1.2"))) + .isLessThan(0); + assertThat(JavaVersion.parse("9.1.2").compareTo(JavaVersion.parse("9.1.3"))) + .isLessThan(0); + assertThat(JavaVersion.parse("9.1.3").compareTo(JavaVersion.parse("9.1.4"))) + .isLessThan(0); + assertThat(JavaVersion.parse("9.1.4").compareTo(JavaVersion.parse("9.2.4"))) + .isLessThan(0); } @Test - public void testIsAtLeastString() { + void testIsAtLeastString() { JavaVersion base = JavaVersion.parse("7"); assertTrue(base.isAtLeast("7")); assertFalse(base.isAtLeast("8")); } @Test - public void testIsAtLeastVersion() { + void testIsAtLeastVersion() { // e.g. can I use the module-path, which is supported since java 9 JavaVersion j9 = JavaVersion.parse("9"); assertFalse(JavaVersion.parse("8").isAtLeast(j9)); @@ -88,14 +99,14 @@ public void testIsAtLeastVersion() { } @Test - public void testIsBeforeString() { + void testIsBeforeString() { JavaVersion base = JavaVersion.parse("7"); assertFalse(base.isBefore("7")); assertTrue(base.isBefore("8")); } @Test - public void testIsBeforeStringVersion() { + void testIsBeforeStringVersion() { // e.g. can I use -XX:MaxPermSize, which has been removed in Java 9 JavaVersion j9 = JavaVersion.parse("9"); assertTrue(JavaVersion.parse("8").isBefore(j9)); @@ -103,19 +114,19 @@ public void testIsBeforeStringVersion() { } @Test - public void testEquals() { + void testEquals() { JavaVersion seven = JavaVersion.parse("7"); JavaVersion other = JavaVersion.parse("7"); - assertEquals(seven, seven); + assertThat(seven).isEqualTo(seven); assertEquals(seven, other); - assertNotEquals(seven, null); + assertNotEquals(null, seven); assertNotEquals(seven, new Object()); assertNotEquals(seven, JavaVersion.parse("8")); } @Test - public void testHascode() { + void testHascode() { JavaVersion seven = JavaVersion.parse("7"); JavaVersion other = JavaVersion.parse("7"); @@ -123,39 +134,36 @@ public void testHascode() { } @Test - public void testToString() { + void testToString() { assertEquals("7", JavaVersion.parse("7").toString()); - assertEquals( - "Raw version should not be parsed", - "!@#$%^&*()", - JavaVersion.parse("!@#$%^&*()").toString()); + assertEquals("!@#$%^&*()", JavaVersion.parse("!@#$%^&*()").toString(), "Raw version should not be parsed"); } @Test - public void testAsMajor() { + void testAsMajor() { assertEquals(JavaVersion.parse("2"), JavaVersion.parse("1.2").asMajor()); assertEquals(JavaVersion.parse("5.0"), JavaVersion.parse("5.0").asMajor()); // only shift one time - assertEquals(JavaVersion.parse("1.1.2").asMajor().asMajor().toString(), "1.2"); + assertEquals("1.2", JavaVersion.parse("1.1.2").asMajor().asMajor().toString()); } @Test - public void testAsMajorEquals() { + void testAsMajorEquals() { JavaVersion version = JavaVersion.parse("1.2"); assertEquals(version, version.asMajor()); } @Test - public void testValueWithGroups() { - assertThat(JavaVersion.parse("1").getValue(1), is("1")); - assertThat(JavaVersion.parse("1").getValue(2), is("1.0")); - assertThat(JavaVersion.parse("1").getValue(3), is("1.0.0")); - assertThat(JavaVersion.parse("2.1").getValue(1), is("2")); - assertThat(JavaVersion.parse("2.1").getValue(2), is("2.1")); - assertThat(JavaVersion.parse("2.1").getValue(3), is("2.1.0")); - assertThat(JavaVersion.parse("3.2.1").getValue(1), is("3")); - assertThat(JavaVersion.parse("3.2.1").getValue(2), is("3.2")); - assertThat(JavaVersion.parse("3.2.1").getValue(3), is("3.2.1")); + void testValueWithGroups() { + assertThat(JavaVersion.parse("1").getValue(1)).isEqualTo("1"); + assertThat(JavaVersion.parse("1").getValue(2)).isEqualTo("1.0"); + assertThat(JavaVersion.parse("1").getValue(3)).isEqualTo("1.0.0"); + assertThat(JavaVersion.parse("2.1").getValue(1)).isEqualTo("2"); + assertThat(JavaVersion.parse("2.1").getValue(2)).isEqualTo("2.1"); + assertThat(JavaVersion.parse("2.1").getValue(3)).isEqualTo("2.1.0"); + assertThat(JavaVersion.parse("3.2.1").getValue(1)).isEqualTo("3"); + assertThat(JavaVersion.parse("3.2.1").getValue(2)).isEqualTo("3.2"); + assertThat(JavaVersion.parse("3.2.1").getValue(3)).isEqualTo("3.2.1"); } } diff --git a/pom.xml b/pom.xml index f09f4db..2ddc848 100644 --- a/pom.xml +++ b/pom.xml @@ -37,6 +37,7 @@ + 5.10.0 scm:git:https://github.com/codehaus-plexus/plexus-languages.git 2023-01-01T19:06:16Z