diff --git a/pom.xml b/pom.xml index f3f7b44c..0b98e5e9 100644 --- a/pom.xml +++ b/pom.xml @@ -272,8 +272,8 @@ org.mockito - mockito-testng - 0.4.31 + mockito-junit-jupiter + 4.11.0 org.simplify4u @@ -281,9 +281,14 @@ 2.3.0 - org.testng - testng - 7.4.0 + org.junit.jupiter + junit-jupiter-api + 5.9.1 + + + org.junit.jupiter + junit-jupiter-params + 5.9.1 @@ -418,7 +423,7 @@ org.mockito - mockito-testng + mockito-junit-jupiter test @@ -427,8 +432,13 @@ test - org.testng - testng + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-params test diff --git a/src/test/java/org/simplify4u/plugins/AbstractPGPMojoTest.java b/src/test/java/org/simplify4u/plugins/AbstractPGPMojoTest.java index b87fb125..572e9507 100644 --- a/src/test/java/org/simplify4u/plugins/AbstractPGPMojoTest.java +++ b/src/test/java/org/simplify4u/plugins/AbstractPGPMojoTest.java @@ -26,17 +26,17 @@ import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; -import org.mockito.testng.MockitoTestNGListener; +import org.mockito.junit.jupiter.MockitoExtension; import org.simplify4u.plugins.keyserver.PGPKeysCache; import org.slf4j.Logger; -import org.testng.annotations.Listeners; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; -@Listeners(MockitoTestNGListener.class) -public class AbstractPGPMojoTest { +@ExtendWith(MockitoExtension.class) +class AbstractPGPMojoTest { static class TestMojo extends AbstractPGPMojo { diff --git a/src/test/java/org/simplify4u/plugins/ArtifactResolverTest.java b/src/test/java/org/simplify4u/plugins/ArtifactResolverTest.java index 25a425ca..94c4847d 100644 --- a/src/test/java/org/simplify4u/plugins/ArtifactResolverTest.java +++ b/src/test/java/org/simplify4u/plugins/ArtifactResolverTest.java @@ -46,18 +46,19 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.repository.RepositorySystem; import org.assertj.core.api.Condition; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.stubbing.Answer; -import org.mockito.testng.MockitoTestNGListener; import org.simplify4u.plugins.ArtifactResolver.Configuration; import org.simplify4u.plugins.skipfilters.CompositeSkipper; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Listeners; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; -@Listeners(MockitoTestNGListener.class) -public class ArtifactResolverTest { +@ExtendWith(MockitoExtension.class) +class ArtifactResolverTest { private static final Condition IS_JAR_TYPE = new Condition<>(a -> "jar".equals(a.getType()), "is jar type"); private static final Condition IS_POM_TYPE = new Condition<>(a -> "pom".equals(a.getType()), "is pom type"); @@ -76,7 +77,7 @@ public class ArtifactResolverTest { private ArtifactResolver resolver; - @BeforeMethod + @BeforeEach void setup() { when(session.getLocalRepository()).thenReturn(localRepository); when(session.getCurrentProject()).thenReturn(project); @@ -86,7 +87,7 @@ void setup() { } @Test - public void testConstructArtifactResolverWithNull() { + void testConstructArtifactResolverWithNull() { reset(session, project); @@ -107,7 +108,7 @@ public void testConstructArtifactResolverWithNull() { } @Test - public void testResolveProjectArtifactsEmpty() throws MojoExecutionException { + void testResolveProjectArtifactsEmpty() throws MojoExecutionException { // given Configuration config = new Configuration(new CompositeSkipper(emptyList()), @@ -121,7 +122,7 @@ public void testResolveProjectArtifactsEmpty() throws MojoExecutionException { } @Test - public void testResolveProjectArtifactsWithoutPoms() throws MojoExecutionException { + void testResolveProjectArtifactsWithoutPoms() throws MojoExecutionException { // given when(repositorySystem.resolve(isA(ArtifactResolutionRequest.class))).thenAnswer((Answer) invocation -> { @@ -147,7 +148,7 @@ public void testResolveProjectArtifactsWithoutPoms() throws MojoExecutionExcepti } @Test - public void testResolveProjectArtifactsWithPoms() throws MojoExecutionException { + void testResolveProjectArtifactsWithPoms() throws MojoExecutionException { // given when(repositorySystem.resolve(isA(ArtifactResolutionRequest.class))).thenAnswer((Answer) invocation -> { @@ -179,7 +180,7 @@ public void testResolveProjectArtifactsWithPoms() throws MojoExecutionException } @Test - public void testResolveSignaturesEmpty() throws MojoExecutionException { + void testResolveSignaturesEmpty() throws MojoExecutionException { // when Map resolved = resolver.resolveSignatures(emptyList()); @@ -189,7 +190,7 @@ public void testResolveSignaturesEmpty() throws MojoExecutionException { } @Test - public void testResolveSignaturesResolved() throws MojoExecutionException { + void testResolveSignaturesResolved() throws MojoExecutionException { // given when(repositorySystem.resolve(isA(ArtifactResolutionRequest.class))).thenAnswer((Answer) invocation -> { @@ -223,7 +224,7 @@ public void testResolveSignaturesResolved() throws MojoExecutionException { } @Test - public void testResolveSignaturesUnresolvedNone() throws MojoExecutionException { + void testResolveSignaturesUnresolvedNone() throws MojoExecutionException { // given when(repositorySystem.resolve(isA(ArtifactResolutionRequest.class))).thenAnswer((Answer) invocation -> { Artifact artifact = invocation.getArgument(0).getArtifact(); @@ -247,8 +248,9 @@ public void testResolveSignaturesUnresolvedNone() throws MojoExecutionException assertThat(resolved).hasSize(1); } - @Test(dataProvider = "verify-plugin-dependencies-combos") - public void testEnablingValidatingPluginDependenciesEnablesPlugins(boolean verifyPlugins, + @ParameterizedTest + @MethodSource("providerVerifyPluginDependenciesCombos") + void testEnablingValidatingPluginDependenciesEnablesPlugins(boolean verifyPlugins, boolean verifyPluginDependencies, boolean pluginsEnabled, boolean pluginDependenciesEnabled) { Configuration config = new Configuration(new CompositeSkipper(), new CompositeSkipper(), @@ -258,8 +260,7 @@ public void testEnablingValidatingPluginDependenciesEnablesPlugins(boolean verif assertThat(config.verifyPlugins).isEqualTo(pluginsEnabled); } - @DataProvider(name = "verify-plugin-dependencies-combos") - public Object[][] providerVerifyPluginDependenciesCombos() { + public static Object[][] providerVerifyPluginDependenciesCombos() { return new Object[][]{ {false, false, false, false}, {false, true, true, true}, diff --git a/src/test/java/org/simplify4u/plugins/PGPMojoExceptionTest.java b/src/test/java/org/simplify4u/plugins/PGPMojoExceptionTest.java index 1309bbf2..f06a6b42 100644 --- a/src/test/java/org/simplify4u/plugins/PGPMojoExceptionTest.java +++ b/src/test/java/org/simplify4u/plugins/PGPMojoExceptionTest.java @@ -17,9 +17,9 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; -public class PGPMojoExceptionTest { +class PGPMojoExceptionTest { @Test void emptyMessage() { diff --git a/src/test/java/org/simplify4u/plugins/ShowMojoTest.java b/src/test/java/org/simplify4u/plugins/ShowMojoTest.java index 5c99f525..e23c9af0 100644 --- a/src/test/java/org/simplify4u/plugins/ShowMojoTest.java +++ b/src/test/java/org/simplify4u/plugins/ShowMojoTest.java @@ -36,18 +36,19 @@ import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.repository.RepositorySystem; import org.bouncycastle.openpgp.PGPException; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.testng.MockitoTestNGListener; +import org.mockito.junit.jupiter.MockitoExtension; import org.simplify4u.plugins.keyserver.PGPKeysCache; import org.simplify4u.plugins.pgp.SignatureCheckResult; import org.simplify4u.plugins.pgp.SignatureStatus; import org.simplify4u.plugins.pgp.SignatureUtils; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Listeners; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; -@Listeners(MockitoTestNGListener.class) +@ExtendWith(MockitoExtension.class) public class ShowMojoTest { @Mock @@ -74,12 +75,12 @@ void shouldReturnMojoName() { assertThat(mojo.getMojoName()).isEqualTo(ShowMojo.MOJO_NAME); } - @DataProvider - public static Object[] invalidArtifactNames() { - return new Object[]{null, "test", "test:test", "test:test:1.0:type:class:class"}; + public static String[] invalidArtifactNames() { + return new String[]{null, "test", "test:test", "test:test:1.0:type:class:class"}; } - @Test(dataProvider = "invalidArtifactNames") + @ParameterizedTest + @MethodSource("invalidArtifactNames") void shouldThrowExceptionForInvalidArtifact(String artifact) { //given diff --git a/src/test/java/org/simplify4u/plugins/ValidationChecksumTest.java b/src/test/java/org/simplify4u/plugins/ValidationChecksumTest.java index c30508e0..9fe5f079 100644 --- a/src/test/java/org/simplify4u/plugins/ValidationChecksumTest.java +++ b/src/test/java/org/simplify4u/plugins/ValidationChecksumTest.java @@ -24,26 +24,26 @@ import static java.util.Arrays.asList; import static java.util.Collections.emptyList; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatCode; +import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import org.apache.maven.artifact.Artifact; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.simplify4u.plugins.ValidationChecksum.Builder; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; -public class ValidationChecksumTest { +class ValidationChecksumTest { private File checksumdirectory = null; - @BeforeMethod - public void setUp() throws IOException { + @BeforeEach + void setUp() throws IOException { this.checksumdirectory = Files.createTempDirectory("ValidationChecksumTest").toFile(); } - @AfterMethod - public void tearDown() throws IOException { + @AfterEach + void tearDown() throws IOException { Files.walk(checksumdirectory.toPath()) .sorted(Comparator.reverseOrder()) .map(Path::toFile) @@ -51,25 +51,25 @@ public void tearDown() throws IOException { } @Test - public void testValidationChecksumBuilderNullFile() { - new ValidationChecksum.Builder().destination(null).artifacts(emptyList()).build(); + void testValidationChecksumBuilderNullFile() { + assertDoesNotThrow(() -> new ValidationChecksum.Builder().destination(null).artifacts(emptyList()).build()); } @Test - public void testValidationChecksumBuilderArtifactsNull() { + void testValidationChecksumBuilderArtifactsNull() { final Builder builder = new ValidationChecksum.Builder().destination(checksumdirectory); assertThatCode(() -> builder.artifacts(null)) .isExactlyInstanceOf(NullPointerException.class); } @Test - public void testValidationChecksumBuilderArtifactsNotProvided() { + void testValidationChecksumBuilderArtifactsNotProvided() { final Builder builder = new ValidationChecksum.Builder().destination(checksumdirectory); assertThatCode(builder::build).isExactlyInstanceOf(IllegalStateException.class); } @Test - public void testValidationChecksumBuilderChecksumEmptyCollection() { + void testValidationChecksumBuilderChecksumEmptyCollection() { final Builder builder = new ValidationChecksum.Builder().destination(checksumdirectory); final ValidationChecksum checksum = builder.artifacts(emptyList()).build(); assertThat(checksum).isNotNull(); @@ -77,7 +77,7 @@ public void testValidationChecksumBuilderChecksumEmptyCollection() { } @Test - public void testValidationChecksumBuilderChecksumArtifactsNullFails() { + void testValidationChecksumBuilderChecksumArtifactsNullFails() { final Artifact a1 = TestArtifactBuilder.testArtifact() .groupId("org.apache.maven.plugins") @@ -104,7 +104,7 @@ public void testValidationChecksumBuilderChecksumArtifactsNullFails() { } @Test - public void testValidationChecksumBuilderChecksumArtifactsRepeatedly() { + void testValidationChecksumBuilderChecksumArtifactsRepeatedly() { final Builder builder = new ValidationChecksum.Builder().destination(checksumdirectory); final Artifact a1 = TestArtifactBuilder.testArtifact() .groupId("org.apache.maven.plugins").artifactId("maven-compiler-plugin") @@ -125,7 +125,7 @@ public void testValidationChecksumBuilderChecksumArtifactsRepeatedly() { } @Test - public void testValidationChecksumBuilderChecksumArtifactsDeterministicOrder() { + void testValidationChecksumBuilderChecksumArtifactsDeterministicOrder() { final Builder builder = new ValidationChecksum.Builder().destination(checksumdirectory); final Artifact a1 = TestArtifactBuilder.testArtifact() .groupId("org.apache.maven.plugins").artifactId("maven-compiler-plugin") @@ -146,7 +146,7 @@ public void testValidationChecksumBuilderChecksumArtifactsDeterministicOrder() { } @Test - public void testValidationChecksumBuilderChecksumArtifactsDisabled() { + void testValidationChecksumBuilderChecksumArtifactsDisabled() { final Builder builder = new ValidationChecksum.Builder().destination(checksumdirectory); final Artifact a1 = TestArtifactBuilder.testArtifact() .groupId("org.apache.maven.plugins").artifactId("maven-compiler-plugin") diff --git a/src/test/java/org/simplify4u/plugins/keyserver/KeyServerClientSettingsTest.java b/src/test/java/org/simplify4u/plugins/keyserver/KeyServerClientSettingsTest.java index 842832d7..e88c23ab 100644 --- a/src/test/java/org/simplify4u/plugins/keyserver/KeyServerClientSettingsTest.java +++ b/src/test/java/org/simplify4u/plugins/keyserver/KeyServerClientSettingsTest.java @@ -29,16 +29,16 @@ import org.apache.maven.execution.MavenSession; import org.apache.maven.settings.Proxy; import org.apache.maven.settings.Settings; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.testng.MockitoTestNGListener; -import org.testng.annotations.Listeners; -import org.testng.annotations.Test; +import org.mockito.junit.jupiter.MockitoExtension; /** * test on methods in the mojo itself */ -@Listeners(MockitoTestNGListener.class) -public class KeyServerClientSettingsTest { +@ExtendWith(MockitoExtension.class) +class KeyServerClientSettingsTest { @Mock private MavenSession mavenSession; @@ -51,7 +51,7 @@ public class KeyServerClientSettingsTest { * */ @Test - public void testIfProxyDeterminationWorksUsingIDs() { + void testIfProxyDeterminationWorksUsingIDs() { List proxies = Arrays.asList( makeMavenProxy(null, null, "p1", true), @@ -79,7 +79,7 @@ public void testIfProxyDeterminationWorksUsingIDs() { * */ @Test - public void testIfProxyDeterminationWorksUsinFirstActive() { + void testIfProxyDeterminationWorksUsinFirstActive() { when(mavenSession.getSettings()).thenReturn(settings); when(settings.getActiveProxy()).thenReturn(makeMavenProxy("p5")); diff --git a/src/test/java/org/simplify4u/plugins/keyserver/PGPKeysCacheTest.java b/src/test/java/org/simplify4u/plugins/keyserver/PGPKeysCacheTest.java index 8f1f2c6f..e53db8ec 100644 --- a/src/test/java/org/simplify4u/plugins/keyserver/PGPKeysCacheTest.java +++ b/src/test/java/org/simplify4u/plugins/keyserver/PGPKeysCacheTest.java @@ -46,10 +46,15 @@ import com.google.common.io.MoreFiles; import com.google.common.io.RecursiveDeleteOption; import org.bouncycastle.openpgp.PGPPublicKeyRing; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; -import org.mockito.testng.MockitoTestNGListener; +import org.mockito.junit.jupiter.MockitoExtension; import org.simplify4u.plugins.keyserver.PGPKeysCache.KeyServerList; import org.simplify4u.plugins.keyserver.PGPKeysCache.KeyServerListFallback; import org.simplify4u.plugins.keyserver.PGPKeysCache.KeyServerListLoadBalance; @@ -57,14 +62,10 @@ import org.simplify4u.plugins.pgp.KeyId; import org.simplify4u.plugins.pgp.KeyId.KeyIdLong; import org.slf4j.Logger; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Listeners; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; -@Listeners(MockitoTestNGListener.class) -public class PGPKeysCacheTest { +@ExtendWith(MockitoExtension.class) +class PGPKeysCacheTest { public static final KeyId KEY_ID_1 = KeyId.from(1L); @@ -107,18 +108,18 @@ private List prepareKeyServerClientWithNotFound() throws IO return Collections.singletonList(keysServerClient); } - @BeforeMethod + @BeforeEach void setup() throws IOException { cachePath = Files.createTempDirectory("cache-path-test"); } - @AfterMethod + @AfterEach void cleanup() throws IOException { MoreFiles.deleteRecursively(cachePath, RecursiveDeleteOption.ALLOW_INSECURE); } @Test - public void emptyCacheDirShouldBeCreated() throws IOException { + void emptyCacheDirShouldBeCreated() throws IOException { File emptyCachePath = new File(cachePath.toFile(), "empty"); @@ -136,7 +137,7 @@ public void emptyCacheDirShouldBeCreated() throws IOException { } @Test - public void fileAsCacheDirThrowException() throws IOException { + void fileAsCacheDirThrowException() throws IOException { File fileAsCachePath = new File(cachePath.toFile(), "file.tmp"); MoreFiles.touch(fileAsCachePath.toPath()); @@ -155,7 +156,7 @@ public void fileAsCacheDirThrowException() throws IOException { } @Test - public void getKeyFromCache() throws IOException { + void getKeyFromCache() throws IOException { List keysServerClients = prepareKeyServerClient(); @@ -188,7 +189,7 @@ public void getKeyFromCache() throws IOException { } @Test - public void notFoundKeyFromCache() throws IOException { + void notFoundKeyFromCache() throws IOException { List keysServerClients = prepareKeyServerClientWithNotFound(); KeyCacheSettings cacheSettings = KeyCacheSettings.builder() @@ -218,7 +219,7 @@ public void notFoundKeyFromCache() throws IOException { } @Test - public void notFoundKeyCacheShouldBeEvicted() throws IOException { + void notFoundKeyCacheShouldBeEvicted() throws IOException { List keysServerClients = prepareKeyServerClientWithNotFound(); KeyCacheSettings cacheSettings = KeyCacheSettings.builder() @@ -258,7 +259,7 @@ public void notFoundKeyCacheShouldBeEvicted() throws IOException { } @Test - public void notFoundCacheEmptyFileShouldNotBreakProcessing() throws IOException { + void notFoundCacheEmptyFileShouldNotBreakProcessing() throws IOException { List keysServerClients = prepareKeyServerClientWithNotFound(); @@ -291,7 +292,7 @@ public void notFoundCacheEmptyFileShouldNotBreakProcessing() throws IOException } @Test - public void brokenKeyInCache() throws IOException { + void brokenKeyInCache() throws IOException { KeyCacheSettings cacheSettings = KeyCacheSettings.builder() .cachePath(cachePath.toFile()) @@ -319,7 +320,7 @@ public void brokenKeyInCache() throws IOException { } @Test - public void nonExistingKeyInRingThrowException() throws IOException { + void nonExistingKeyInRingThrowException() throws IOException { List keysServerClients = prepareKeyServerClient(); @@ -335,8 +336,7 @@ public void nonExistingKeyInRingThrowException() throws IOException { .hasMessageStartingWith("Can't find public key 0x0000001234567890 in download file:"); } - @DataProvider(name = "serverListTestData") - public Object[][] serverListTestData() { + public static Object[][] serverListTestData() { PGPKeysServerClient client1 = mock(PGPKeysServerClient.class); PGPKeysServerClient client2 = mock(PGPKeysServerClient.class); @@ -349,8 +349,9 @@ public Object[][] serverListTestData() { }; } - @Test(dataProvider = "serverListTestData") - public void createKeyServerListReturnCorrectImplementation( + @ParameterizedTest + @MethodSource("serverListTestData") + void createKeyServerListReturnCorrectImplementation( List serverList, boolean loadBalance, Class aClass) { KeyServerList keyServerList = PGPKeysCache.createKeyServerList(serverList, loadBalance); @@ -359,7 +360,7 @@ public void createKeyServerListReturnCorrectImplementation( } @Test - public void listOneUseFirstServerForCorrectExecute() throws IOException { + void listOneUseFirstServerForCorrectExecute() throws IOException { PGPKeysServerClient client1 = mock(PGPKeysServerClient.class); PGPKeysServerClient client2 = mock(PGPKeysServerClient.class); @@ -386,7 +387,7 @@ public void listOneUseFirstServerForCorrectExecute() throws IOException { } @Test - public void listOneThrowsExceptionForFailedExecute() throws IOException { + void listOneThrowsExceptionForFailedExecute() throws IOException { PGPKeysServerClient client1 = mock(PGPKeysServerClient.class); PGPKeysServerClient client2 = mock(PGPKeysServerClient.class); @@ -409,7 +410,7 @@ public void listOneThrowsExceptionForFailedExecute() throws IOException { } @Test - public void fallbackOnlyUseFirstServerForCorrectExecute() throws IOException { + void fallbackOnlyUseFirstServerForCorrectExecute() throws IOException { PGPKeysServerClient client1 = mock(PGPKeysServerClient.class); PGPKeysServerClient client2 = mock(PGPKeysServerClient.class); @@ -436,7 +437,7 @@ public void fallbackOnlyUseFirstServerForCorrectExecute() throws IOException { } @Test - public void loadBalanceIterateByAllServer() throws IOException { + void loadBalanceIterateByAllServer() throws IOException { PGPKeysServerClient client1 = mock(PGPKeysServerClient.class); PGPKeysServerClient client2 = mock(PGPKeysServerClient.class); @@ -466,8 +467,7 @@ public void loadBalanceIterateByAllServer() throws IOException { verifyNoMoreInteractions(client1); } - @DataProvider(name = "keyServerListWithFallBack") - public Object[][] keyServerListWithFallBack() { + public static Object[][] keyServerListWithFallBack() { return new Object[][]{ {new KeyServerListFallback()}, @@ -475,8 +475,9 @@ public Object[][] keyServerListWithFallBack() { }; } - @Test(dataProvider = "keyServerListWithFallBack") - public void useSecondServerForFailedExecute(KeyServerList keyServerList) throws IOException { + @ParameterizedTest + @MethodSource("keyServerListWithFallBack") + void useSecondServerForFailedExecute(KeyServerList keyServerList) throws IOException { PGPKeysServerClient client1 = mock(PGPKeysServerClient.class); PGPKeysServerClient client2 = mock(PGPKeysServerClient.class); @@ -508,8 +509,9 @@ public void useSecondServerForFailedExecute(KeyServerList keyServerList) throws verifyNoMoreInteractions(client2); } - @Test(dataProvider = "keyServerListWithFallBack") - public void throwsExceptionForAllFailedExecute(KeyServerList keyServerList) throws IOException { + @ParameterizedTest + @MethodSource("keyServerListWithFallBack") + void throwsExceptionForAllFailedExecute(KeyServerList keyServerList) throws IOException { PGPKeysServerClient client1 = mock(PGPKeysServerClient.class); PGPKeysServerClient client2 = mock(PGPKeysServerClient.class); @@ -539,8 +541,9 @@ public void throwsExceptionForAllFailedExecute(KeyServerList keyServerList) thro verifyNoMoreInteractions(client2); } - @Test(dataProvider = "keyServerListWithFallBack") - public void throwsPGPKeyNotFoundWhenKeyNotFoundOnLastServer(KeyServerList keyServerList) throws IOException { + @ParameterizedTest + @MethodSource("keyServerListWithFallBack") + void throwsPGPKeyNotFoundWhenKeyNotFoundOnLastServer(KeyServerList keyServerList) throws IOException { PGPKeysServerClient client1 = mock(PGPKeysServerClient.class); PGPKeysServerClient client2 = mock(PGPKeysServerClient.class); @@ -569,8 +572,9 @@ public void throwsPGPKeyNotFoundWhenKeyNotFoundOnLastServer(KeyServerList keySer verifyNoMoreInteractions(client2); } - @Test(dataProvider = "keyServerListWithFallBack") - public void throwsPGPKeyNotFoundWhenKeyNotFoundOnFirstServer(KeyServerList keyServerList) throws IOException { + @ParameterizedTest + @MethodSource("keyServerListWithFallBack") + void throwsPGPKeyNotFoundWhenKeyNotFoundOnFirstServer(KeyServerList keyServerList) throws IOException { PGPKeysServerClient client1 = mock(PGPKeysServerClient.class); PGPKeysServerClient client2 = mock(PGPKeysServerClient.class); diff --git a/src/test/java/org/simplify4u/plugins/keyserver/PGPKeysServerClientTest.java b/src/test/java/org/simplify4u/plugins/keyserver/PGPKeysServerClientTest.java index 1c6bdac0..22f0229a 100644 --- a/src/test/java/org/simplify4u/plugins/keyserver/PGPKeysServerClientTest.java +++ b/src/test/java/org/simplify4u/plugins/keyserver/PGPKeysServerClientTest.java @@ -42,16 +42,17 @@ import org.apache.maven.execution.MavenSession; import org.apache.maven.settings.Proxy; import org.apache.maven.settings.Settings; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.mockito.testng.MockitoTestNGListener; +import org.mockito.junit.jupiter.MockitoExtension; import org.simplify4u.plugins.pgp.KeyId; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Listeners; -import org.testng.annotations.Test; -@Listeners(MockitoTestNGListener.class) -public class PGPKeysServerClientTest { +@ExtendWith(MockitoExtension.class) +class PGPKeysServerClientTest { @Mock Settings settings; @@ -62,16 +63,16 @@ public class PGPKeysServerClientTest { @Mock HttpClientBuilder clientBuilder; - @DataProvider(name = "proxy") - public static Object[][] emptyProxy() { - return new Object[][]{ - {makeMavenProxy("", "")}, - {makeMavenProxy(null, null)}, - {null}}; + public static Proxy[] proxy() { + return new Proxy[] { + makeMavenProxy("", ""), + makeMavenProxy(null, null), + null}; } - @Test(dataProvider = "proxy") - public void emptyProxyNotConfigureClient(Proxy proxy) throws URISyntaxException, IOException { + @ParameterizedTest + @MethodSource("proxy") + void emptyProxyNotConfigureClient(Proxy proxy) throws URISyntaxException, IOException { runProxyConfig(proxy); verify(clientBuilder).setDefaultRequestConfig(any()); @@ -79,7 +80,7 @@ public void emptyProxyNotConfigureClient(Proxy proxy) throws URISyntaxException, } @Test - public void mavenProxyShouldConfigureClient() { + void mavenProxyShouldConfigureClient() { runProxyConfig(makeMavenProxy("user", "userPass")); @@ -116,7 +117,7 @@ private void runProxyConfig(Proxy proxy) { } @Test - public void offLineModeShouldThrowIOException() throws URISyntaxException { + void offLineModeShouldThrowIOException() throws URISyntaxException { URI uri = new URI("https://localhost/"); @@ -134,14 +135,14 @@ public void offLineModeShouldThrowIOException() throws URISyntaxException { } @Test - public void unsupportedProtocolShouldThrowIOException() throws IOException { + void unsupportedProtocolShouldThrowIOException() throws IOException { assertThatThrownBy(() -> PGPKeysServerClient.getClient("abc://loclahost", null)) .isExactlyInstanceOf(IOException.class) .hasMessage("Unsupported protocol: abc"); } @Test - public void serverResponse404() throws URISyntaxException, IOException { + void serverResponse404() throws URISyntaxException, IOException { when(mavenSession.getSettings()).thenReturn(settings); @@ -168,7 +169,7 @@ public void serverResponse404() throws URISyntaxException, IOException { } @Test - public void serverIOException() throws URISyntaxException, IOException { + void serverIOException() throws URISyntaxException, IOException { when(mavenSession.getSettings()).thenReturn(settings); diff --git a/src/test/java/org/simplify4u/plugins/keyserver/RoundRobinRouterPlanerTest.java b/src/test/java/org/simplify4u/plugins/keyserver/RoundRobinRouterPlanerTest.java index 697514b8..8e501b7d 100644 --- a/src/test/java/org/simplify4u/plugins/keyserver/RoundRobinRouterPlanerTest.java +++ b/src/test/java/org/simplify4u/plugins/keyserver/RoundRobinRouterPlanerTest.java @@ -29,15 +29,15 @@ import org.apache.http.HttpException; import org.apache.http.HttpHost; import org.apache.http.conn.routing.HttpRoute; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.testng.MockitoTestNGListener; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Listeners; -import org.testng.annotations.Test; +import org.mockito.junit.jupiter.MockitoExtension; +import org.junit.jupiter.api.Test; -@Listeners(MockitoTestNGListener.class) -public class RoundRobinRouterPlanerTest { +@ExtendWith(MockitoExtension.class) +class RoundRobinRouterPlanerTest { private static final InetAddress[] EXPECTED_ADDRESSES = Try.of(() -> new InetAddress[]{ InetAddress.getByName("127.0.0.1"), @@ -53,13 +53,13 @@ public class RoundRobinRouterPlanerTest { @InjectMocks private RoundRobinRouterPlaner routerPlaner; - @BeforeMethod + @BeforeEach void setup() throws Throwable { when(resolver.apply(anyString())).thenReturn(EXPECTED_ADDRESSES); } @Test - public void shouldReturnTheSameAddressForSequentialCall() throws HttpException { + void shouldReturnTheSameAddressForSequentialCall() throws HttpException { HttpHost httpHost = new HttpHost(TEST_HOST); @@ -74,7 +74,7 @@ public void shouldReturnTheSameAddressForSequentialCall() throws HttpException { } @Test - public void shouldReturnNextAddressAfterError() throws UnknownHostException, HttpException { + void shouldReturnNextAddressAfterError() throws UnknownHostException, HttpException { HttpHost httpHost = new HttpHost(TEST_HOST); diff --git a/src/test/java/org/simplify4u/plugins/keysmap/ArtifactPatternTest.java b/src/test/java/org/simplify4u/plugins/keysmap/ArtifactPatternTest.java index 7a54e484..21910113 100644 --- a/src/test/java/org/simplify4u/plugins/keysmap/ArtifactPatternTest.java +++ b/src/test/java/org/simplify4u/plugins/keysmap/ArtifactPatternTest.java @@ -21,16 +21,16 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.api.Test; /** * @author Slawomir Jaranowski. */ public class ArtifactPatternTest { - @DataProvider(name = "lists") - public Object[][] artifactsList() { + public static Object[][] lists() { return new Object[][]{ {"Test.Group:tesT:*", testArtifact().build(), true}, {"test.group:test:*", testArtifact().version("1.0.0.M5").build(), true}, @@ -108,15 +108,16 @@ public Object[][] artifactsList() { }; } - @Test(dataProvider = "lists") - public void testMatchArtifact(String pattern, Artifact artifact, boolean match) { + @ParameterizedTest + @MethodSource("lists") + void testMatchArtifact(String pattern, Artifact artifact, boolean match) { ArtifactPattern artifactPattern = new ArtifactPattern(pattern); assertThat(artifactPattern.isMatch(new ArtifactData(artifact))).isEqualTo(match); } @Test - public void asteriskInVersionThrowException() { + void asteriskInVersionThrowException() { assertThatCode(() -> new ArtifactPattern("test.group:test:1.0.*")) .isExactlyInstanceOf(IllegalArgumentException.class) @@ -126,7 +127,7 @@ public void asteriskInVersionThrowException() { } @Test - public void wrongVersionThrowException() { + void wrongVersionThrowException() { assertThatCode(() -> new ArtifactPattern("test.group:test:[1.0.0")) .isExactlyInstanceOf(IllegalArgumentException.class) @@ -136,7 +137,7 @@ public void wrongVersionThrowException() { } @Test - public void twoInstanceWithTheSamePatternShouldBeEqual() { + void twoInstanceWithTheSamePatternShouldBeEqual() { ArtifactPattern artifactPattern1 = new ArtifactPattern("test.group.*:test*"); ArtifactPattern artifactPattern2 = new ArtifactPattern("test.group.*:test*"); diff --git a/src/test/java/org/simplify4u/plugins/keysmap/KeyItemAnyKeyTest.java b/src/test/java/org/simplify4u/plugins/keysmap/KeyItemAnyKeyTest.java index 07e7cb15..af47a77d 100644 --- a/src/test/java/org/simplify4u/plugins/keysmap/KeyItemAnyKeyTest.java +++ b/src/test/java/org/simplify4u/plugins/keysmap/KeyItemAnyKeyTest.java @@ -16,12 +16,12 @@ package org.simplify4u.plugins.keysmap; import org.assertj.core.api.Assertions; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; -public class KeyItemAnyKeyTest { +class KeyItemAnyKeyTest { @Test - public void twoInstanceShouldBeEqual() { + void twoInstanceShouldBeEqual() { KeyItemAnyKey keyItemAnyKey1 = new KeyItemAnyKey(); KeyItemAnyKey keyItemAnyKey2 = new KeyItemAnyKey(); diff --git a/src/test/java/org/simplify4u/plugins/keysmap/KeyItemBrokenSigTest.java b/src/test/java/org/simplify4u/plugins/keysmap/KeyItemBrokenSigTest.java index bae7fecb..a04ebbbe 100644 --- a/src/test/java/org/simplify4u/plugins/keysmap/KeyItemBrokenSigTest.java +++ b/src/test/java/org/simplify4u/plugins/keysmap/KeyItemBrokenSigTest.java @@ -16,12 +16,12 @@ package org.simplify4u.plugins.keysmap; import org.assertj.core.api.Assertions; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; -public class KeyItemBrokenSigTest { +class KeyItemBrokenSigTest { @Test - public void twoInstanceShouldBeEqual() { + void twoInstanceShouldBeEqual() { KeyItemBrokenSig keyItemBrokenSig1 = new KeyItemBrokenSig(); KeyItemBrokenSig keyItemBrokenSig2 = new KeyItemBrokenSig(); diff --git a/src/test/java/org/simplify4u/plugins/keysmap/KeyItemFingerprintTest.java b/src/test/java/org/simplify4u/plugins/keysmap/KeyItemFingerprintTest.java index 8dfd2766..86689e26 100644 --- a/src/test/java/org/simplify4u/plugins/keysmap/KeyItemFingerprintTest.java +++ b/src/test/java/org/simplify4u/plugins/keysmap/KeyItemFingerprintTest.java @@ -19,9 +19,9 @@ import static org.simplify4u.plugins.TestUtils.aKeyInfo; import org.simplify4u.plugins.pgp.KeyInfo; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; -public class KeyItemFingerprintTest { +class KeyItemFingerprintTest { private static final String FINGERPRINT_1 = "0x9ABC DEF0 1234 5678 9ABC DEF0 1234 5678 9ABC DEF0"; private static final String FINGERPRINT_2 = "0x9ABC DEF0 1234 5678 9ABC DEF0 1234 5678 9ABC 0000"; diff --git a/src/test/java/org/simplify4u/plugins/keysmap/KeyItemNoKeyTest.java b/src/test/java/org/simplify4u/plugins/keysmap/KeyItemNoKeyTest.java index 601158c6..3e92edbc 100644 --- a/src/test/java/org/simplify4u/plugins/keysmap/KeyItemNoKeyTest.java +++ b/src/test/java/org/simplify4u/plugins/keysmap/KeyItemNoKeyTest.java @@ -16,12 +16,12 @@ package org.simplify4u.plugins.keysmap; import org.assertj.core.api.Assertions; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; -public class KeyItemNoKeyTest { +class KeyItemNoKeyTest { @Test - public void twoInstanceShouldBeEqual() { + void twoInstanceShouldBeEqual() { KeyItemNoKey keyItemNoKey1 = new KeyItemNoKey(); KeyItemNoKey keyItemNoKey2 = new KeyItemNoKey(); diff --git a/src/test/java/org/simplify4u/plugins/keysmap/KeyItemNoSigTest.java b/src/test/java/org/simplify4u/plugins/keysmap/KeyItemNoSigTest.java index 4bc210c5..c8c4bc07 100644 --- a/src/test/java/org/simplify4u/plugins/keysmap/KeyItemNoSigTest.java +++ b/src/test/java/org/simplify4u/plugins/keysmap/KeyItemNoSigTest.java @@ -16,12 +16,12 @@ package org.simplify4u.plugins.keysmap; import org.assertj.core.api.Assertions; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; -public class KeyItemNoSigTest { +class KeyItemNoSigTest { @Test - public void twoInstanceShouldBeEqual() { + void twoInstanceShouldBeEqual() { KeyItemNoSig keyItemNoSig1 = new KeyItemNoSig(); KeyItemNoSig keyItemNoSig2 = new KeyItemNoSig(); diff --git a/src/test/java/org/simplify4u/plugins/keysmap/KeyItemsTest.java b/src/test/java/org/simplify4u/plugins/keysmap/KeyItemsTest.java index 638f7749..d66d1cca 100644 --- a/src/test/java/org/simplify4u/plugins/keysmap/KeyItemsTest.java +++ b/src/test/java/org/simplify4u/plugins/keysmap/KeyItemsTest.java @@ -24,18 +24,18 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import org.bouncycastle.openpgp.PGPException; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.simplify4u.plugins.pgp.KeyFingerprint; import org.simplify4u.plugins.pgp.KeyInfo; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; /** * @author Slawomir Jaranowski. */ -public class KeyItemsTest { +class KeyItemsTest { - @DataProvider(name = "keys") - public Object[][] keys() { + public static Object[][] keys() { return new Object[][]{ {"*", "0x123456789abcdef0", true}, {"", "0x123456789abcdef0", false}, @@ -55,8 +55,9 @@ public Object[][] keys() { }; } - @Test(dataProvider = "keys") - public void testIsKeyMatch(String strKeys, String key, boolean match) throws Exception { + @ParameterizedTest + @MethodSource("keys") + void testIsKeyMatch(String strKeys, String key, boolean match) throws Exception { KeyItems keyItems = new KeyItems().addKeys(strKeys, null); assertThat(keyItems.isKeyMatch(aKeyInfo(key))).as("isKeyMatch").isEqualTo(match); @@ -67,7 +68,7 @@ private KeyInfo aKeyInfo(String fingerprint) { } @Test - public void nullKeyShouldThrowsException() { + void nullKeyShouldThrowsException() { // given KeysMapContext keysMapContext = new KeysMapContext("test.map"); KeyItems keyItems = new KeyItems(); @@ -79,7 +80,7 @@ public void nullKeyShouldThrowsException() { } @Test - public void invalidKeyShouldThrowsException() { + void invalidKeyShouldThrowsException() { // given KeyItems keyItems = new KeyItems(); @@ -91,21 +92,21 @@ public void invalidKeyShouldThrowsException() { @Test - public void testIsNoSignature() { + void testIsNoSignature() { KeyItems keyItems = new KeyItems().addKeys("", null); assertThat(keyItems.isNoSignature()).isTrue(); } @Test - public void testIsNoSignatureIncorrect() { + void testIsNoSignatureIncorrect() { KeyItems keyItems = new KeyItems().addKeys("0x123456789abcdef0", null); assertThat(keyItems.isNoSignature()).isFalse(); } @Test - public void testSubKeyMach() throws IOException, PGPException { + void testSubKeyMach() throws IOException, PGPException { KeyInfo keyInfo = KeyInfo.builder() .fingerprint(new KeyFingerprint("0x1234567890123456789012345678901234567890")) @@ -119,7 +120,7 @@ public void testSubKeyMach() throws IOException, PGPException { } @Test - public void oddHexStringShouldThrowException() { + void oddHexStringShouldThrowException() { // given KeyItems keyItems = new KeyItems(); @@ -130,7 +131,7 @@ public void oddHexStringShouldThrowException() { } @Test - public void invalidHexStringShouldThrowException() { + void invalidHexStringShouldThrowException() { // given KeyItems keyItems = new KeyItems(); @@ -141,7 +142,7 @@ public void invalidHexStringShouldThrowException() { } @Test - public void onlyIncludedValuesShouldBePreserved() { + void onlyIncludedValuesShouldBePreserved() { KeysMapContext keysMapContext = new KeysMapContext("test.map"); KeyItems keyItems = new KeyItems().addKeys("noSig, badSig, noKey, 0x123456789abcdef0", keysMapContext); @@ -159,7 +160,7 @@ public void onlyIncludedValuesShouldBePreserved() { } @Test - public void includedAnyValuesShouldDoNothing() { + void includedAnyValuesShouldDoNothing() { KeysMapContext keysMapContext = new KeysMapContext("test.map"); KeyItems keyItems = new KeyItems().addKeys("noSig, badSig, noKey, 0x123456789abcdef0", keysMapContext); @@ -177,7 +178,7 @@ public void includedAnyValuesShouldDoNothing() { } @Test - public void emptyIncludedValuesRemoveAllItems() { + void emptyIncludedValuesRemoveAllItems() { KeysMapContext keysMapContext = new KeysMapContext("test.map"); KeyItems keyItems = new KeyItems().addKeys("noSig, badSig, noKey, 0x123456789abcdef0", keysMapContext); @@ -189,7 +190,7 @@ public void emptyIncludedValuesRemoveAllItems() { } @Test - public void excludedValuesShouldBeRemoved() { + void excludedValuesShouldBeRemoved() { KeysMapContext keysMapContext = new KeysMapContext("test.map"); KeyItems keyItems = new KeyItems().addKeys("noSig, badSig, noKey, 0x123456789abcdef0", keysMapContext); @@ -207,7 +208,7 @@ public void excludedValuesShouldBeRemoved() { } @Test - public void emptyExcludedValuesDoNothing() { + void emptyExcludedValuesDoNothing() { KeysMapContext keysMapContext = new KeysMapContext("test.map"); KeyItems keyItems = new KeyItems().addKeys("noSig, badSig, noKey, 0x123456789abcdef0", keysMapContext); diff --git a/src/test/java/org/simplify4u/plugins/keysmap/KeysMapMultiTest.java b/src/test/java/org/simplify4u/plugins/keysmap/KeysMapMultiTest.java index b1cb58bf..f04f54cf 100644 --- a/src/test/java/org/simplify4u/plugins/keysmap/KeysMapMultiTest.java +++ b/src/test/java/org/simplify4u/plugins/keysmap/KeysMapMultiTest.java @@ -26,18 +26,19 @@ import org.apache.maven.artifact.Artifact; import org.codehaus.plexus.resource.ResourceManager; import org.codehaus.plexus.resource.loader.ResourceNotFoundException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.testng.MockitoTestNGListener; +import org.mockito.junit.jupiter.MockitoExtension; import org.simplify4u.plugins.pgp.KeyFingerprint; import org.simplify4u.plugins.pgp.KeyInfo; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Listeners; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; -@Listeners(MockitoTestNGListener.class) -public class KeysMapMultiTest { +@ExtendWith(MockitoExtension.class) +class KeysMapMultiTest { @Mock private ResourceManager resourceManager; @@ -45,14 +46,14 @@ public class KeysMapMultiTest { @InjectMocks private KeysMap keysMap; - @BeforeMethod - public void setup() throws ResourceNotFoundException { + @BeforeEach + void setup() throws ResourceNotFoundException { doAnswer(invocation -> getClass().getResourceAsStream(invocation.getArgument(0))) .when(resourceManager).getResourceAsInputStream(anyString()); } @Test - public void loadMultipleKeysMapShouldContainsAllItems() throws ResourceNotFoundException, IOException { + void loadMultipleKeysMapShouldContainsAllItems() throws ResourceNotFoundException, IOException { keysMap.load(aKeysMapLocationConfig("/keysMapMulti1.list")); keysMap.load(aKeysMapLocationConfig("/keysMapMulti2.list")); @@ -60,7 +61,6 @@ public void loadMultipleKeysMapShouldContainsAllItems() throws ResourceNotFoundE assertThat(keysMap.size()).isEqualTo(9); } - @DataProvider public static Object[][] artifactWithKeyToTest() { return new Object[][]{ {testArtifact().build(), @@ -95,8 +95,9 @@ public static Object[][] artifactWithKeyToTest() { }; } - @Test(dataProvider = "artifactWithKeyToTest") - public void keyShouldBeValid(Artifact artifact, KeyFingerprint keyFingerprint) + @ParameterizedTest + @MethodSource("artifactWithKeyToTest") + void keyShouldBeValid(Artifact artifact, KeyFingerprint keyFingerprint) throws ResourceNotFoundException, IOException { KeyInfo key = KeyInfo.builder().fingerprint(keyFingerprint).build(); @@ -107,7 +108,6 @@ public void keyShouldBeValid(Artifact artifact, KeyFingerprint keyFingerprint) assertThat(keysMap.isValidKey(artifact, key)).isTrue(); } - @DataProvider public static Object[][] artifactWithNoSig() { return new Object[][]{ {testArtifact().groupId("test.group-no-sig").artifactId("no-sig").build()}, @@ -117,8 +117,9 @@ public static Object[][] artifactWithNoSig() { } - @Test(dataProvider = "artifactWithNoSig") - public void noSigShouldBeFound(Artifact artifact) throws ResourceNotFoundException, IOException { + @ParameterizedTest + @MethodSource("artifactWithNoSig") + void noSigShouldBeFound(Artifact artifact) throws ResourceNotFoundException, IOException { keysMap.load(aKeysMapLocationConfig("/keysMapMulti1.list")); keysMap.load(aKeysMapLocationConfig("/keysMapMulti2.list")); @@ -126,7 +127,7 @@ public void noSigShouldBeFound(Artifact artifact) throws ResourceNotFoundExcepti } @Test - public void badSigShouldBeFound() throws ResourceNotFoundException, IOException { + void badSigShouldBeFound() throws ResourceNotFoundException, IOException { keysMap.load(aKeysMapLocationConfig("/keysMapMulti1.list")); keysMap.load(aKeysMapLocationConfig("/keysMapMulti2.list")); diff --git a/src/test/java/org/simplify4u/plugins/keysmap/KeysMapTest.java b/src/test/java/org/simplify4u/plugins/keysmap/KeysMapTest.java index 0907345b..a7ad81ff 100644 --- a/src/test/java/org/simplify4u/plugins/keysmap/KeysMapTest.java +++ b/src/test/java/org/simplify4u/plugins/keysmap/KeysMapTest.java @@ -31,18 +31,18 @@ import static org.simplify4u.plugins.TestUtils.aKeysMapLocationConfig; import org.codehaus.plexus.resource.ResourceManager; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.testng.MockitoTestNGListener; +import org.mockito.junit.jupiter.MockitoExtension; import org.slf4j.Logger; -import org.testng.annotations.Listeners; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; /** * @author Slawomir Jaranowski. */ -@Listeners(MockitoTestNGListener.class) -public class KeysMapTest { +@ExtendWith(MockitoExtension.class) +class KeysMapTest { @Mock private ResourceManager resourceManager; @@ -57,12 +57,12 @@ public class KeysMapTest { private KeysMap keysMap; @Test - public void isComponentSet() { + void isComponentSet() { assertThat(keysMap).isNotNull(); } @Test - public void nullLocationTest() throws Exception { + void nullLocationTest() throws Exception { assertThatThrownBy(() -> keysMap.load(null)) .isExactlyInstanceOf(NullPointerException.class); @@ -72,7 +72,7 @@ public void nullLocationTest() throws Exception { } @Test - public void emptyLocationTest() throws Exception { + void emptyLocationTest() throws Exception { keysMap.load(aKeysMapLocationConfig("")); verifyNoInteractions(resourceManager); @@ -80,7 +80,7 @@ public void emptyLocationTest() throws Exception { } @Test - public void validKeyFromMap() throws Exception { + void validKeyFromMap() throws Exception { doAnswer(invocation -> getClass().getResourceAsStream(invocation.getArgument(0))) .when(resourceManager).getResourceAsInputStream(anyString()); @@ -145,7 +145,7 @@ public void validKeyFromMap() throws Exception { } @Test - public void invalidKeyFromMap() throws Exception { + void invalidKeyFromMap() throws Exception { doAnswer(invocation -> getClass().getResourceAsStream(invocation.getArgument(0))) .when(resourceManager).getResourceAsInputStream(anyString()); @@ -161,7 +161,7 @@ public void invalidKeyFromMap() throws Exception { } @Test - public void specialValueNoSig() throws Exception { + void specialValueNoSig() throws Exception { doAnswer(invocation -> getClass().getResourceAsStream(invocation.getArgument(0))) .when(resourceManager).getResourceAsInputStream(anyString()); @@ -190,7 +190,7 @@ public void specialValueNoSig() throws Exception { } @Test - public void specialValueBadSig() throws Exception { + void specialValueBadSig() throws Exception { doAnswer(invocation -> getClass().getResourceAsStream(invocation.getArgument(0))) .when(resourceManager).getResourceAsInputStream(anyString()); @@ -204,7 +204,7 @@ public void specialValueBadSig() throws Exception { } @Test - public void specialValueNoKey() throws Exception { + void specialValueNoKey() throws Exception { doAnswer(invocation -> getClass().getResourceAsStream(invocation.getArgument(0))) .when(resourceManager).getResourceAsInputStream(anyString()); @@ -218,7 +218,7 @@ public void specialValueNoKey() throws Exception { } @Test - public void shortKeyShouldThrownException() throws Exception { + void shortKeyShouldThrownException() throws Exception { doAnswer(invocation -> getClass().getResourceAsStream(invocation.getArgument(0))) .when(resourceManager).getResourceAsInputStream(anyString()); @@ -229,7 +229,7 @@ public void shortKeyShouldThrownException() throws Exception { } @Test - public void properLogShouldBeGeneratedForProcessingItems() throws Exception { + void properLogShouldBeGeneratedForProcessingItems() throws Exception { doAnswer(invocation -> getClass().getResourceAsStream(invocation.getArgument(0))) .when(resourceManager).getResourceAsInputStream(anyString()); @@ -249,7 +249,7 @@ public void properLogShouldBeGeneratedForProcessingItems() throws Exception { } @Test - public void onlyIncludedItemsFromMapByValue() throws Exception { + void onlyIncludedItemsFromMapByValue() throws Exception { doAnswer(invocation -> getClass().getResourceAsStream(invocation.getArgument(0))) .when(resourceManager).getResourceAsInputStream(anyString()); @@ -267,7 +267,7 @@ public void onlyIncludedItemsFromMapByValue() throws Exception { } @Test - public void onlyIncludedItemsFromMapByPattern() throws Exception { + void onlyIncludedItemsFromMapByPattern() throws Exception { doAnswer(invocation -> getClass().getResourceAsStream(invocation.getArgument(0))) .when(resourceManager).getResourceAsInputStream(anyString()); @@ -289,7 +289,7 @@ public void onlyIncludedItemsFromMapByPattern() throws Exception { } @Test - public void excludeItemsFromMap() throws Exception { + void excludeItemsFromMap() throws Exception { doAnswer(invocation -> getClass().getResourceAsStream(invocation.getArgument(0))) .when(resourceManager).getResourceAsInputStream(anyString()); diff --git a/src/test/java/org/simplify4u/plugins/pgp/PublicKeyUtilsTest.java b/src/test/java/org/simplify4u/plugins/pgp/PublicKeyUtilsTest.java index fcfe3c85..6bb11f53 100644 --- a/src/test/java/org/simplify4u/plugins/pgp/PublicKeyUtilsTest.java +++ b/src/test/java/org/simplify4u/plugins/pgp/PublicKeyUtilsTest.java @@ -25,18 +25,20 @@ import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPPublicKey; import org.bouncycastle.openpgp.PGPPublicKeyRing; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; -public class PublicKeyUtilsTest { +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class PublicKeyUtilsTest { private static final KeyId SUB_KEY_ID = KeyId.from(0xEFE8086F9E93774EL); private static final long MASTER_KEY_ID = 0x164BD2247B936711L; private PGPPublicKeyRing publicKeyRing; - @BeforeClass - public void loadKeyRing() throws IOException, PGPException { + @BeforeAll + void loadKeyRing() throws IOException, PGPException { try (InputStream inputStream = getClass().getResourceAsStream("/EFE8086F9E93774E.asc")) { Optional aPublicKeyRing = PublicKeyUtils.loadPublicKeyRing(inputStream, SUB_KEY_ID); @@ -49,7 +51,7 @@ public void loadKeyRing() throws IOException, PGPException { @Test - public void fingerPrintForMasterKey() { + void fingerPrintForMasterKey() { KeyInfo keyInfo = KeyInfo.builder() .fingerprint(new KeyFingerprint("0x58E79B6ABC762159DC0B1591164BD2247B936711")) @@ -61,7 +63,7 @@ public void fingerPrintForMasterKey() { } @Test - public void fingerPrintForSubKey() { + void fingerPrintForSubKey() { KeyInfo keyInfo = KeyInfo.builder() .fingerprint(new KeyFingerprint("0x1234567890123456789012345678901234567890")) .master(new KeyFingerprint("0x58E79B6ABC762159DC0B1591164BD2247B936711")) @@ -73,7 +75,7 @@ public void fingerPrintForSubKey() { } @Test - public void userIdsWithSubKey() { + void userIdsWithSubKey() { PGPPublicKey key = SUB_KEY_ID.getKeyFromRing(publicKeyRing); @@ -83,7 +85,7 @@ public void userIdsWithSubKey() { } @Test - public void userIdsWithMasterKey() { + void userIdsWithMasterKey() { PGPPublicKey key = publicKeyRing.getPublicKey(MASTER_KEY_ID); @@ -93,7 +95,7 @@ public void userIdsWithMasterKey() { } @Test - public void keyIdDescriptionForMasterKey() { + void keyIdDescriptionForMasterKey() { KeyInfo keyInfo = aKeyInfo("0x1234567890123456789012345678901234567890"); @@ -103,7 +105,7 @@ public void keyIdDescriptionForMasterKey() { } @Test - public void keyIdDescriptionForSubKey() { + void keyIdDescriptionForSubKey() { KeyInfo keyInfo = aKeyInfo("0x0987654321098765432109876543210987654321", "0x1234567890123456789012345678901234567890"); assertThat(keyInfo.getMaster()).isNotNull(); @@ -112,7 +114,7 @@ public void keyIdDescriptionForSubKey() { } @Test - public void invalidUTF8InUserId() throws IOException, PGPException { + void invalidUTF8InUserId() throws IOException, PGPException { try (InputStream inputStream = getClass().getResourceAsStream("/B0F3710FA64900E7.asc")) { Optional aPublicKeyRing = PublicKeyUtils.loadPublicKeyRing(inputStream, KeyId.from(0xB0F3710FA64900E7L)); @@ -126,7 +128,7 @@ public void invalidUTF8InUserId() throws IOException, PGPException { } @Test - public void validateSubKeyWithExternalSignature() throws IOException, PGPException { + void validateSubKeyWithExternalSignature() throws IOException, PGPException { try (InputStream inputStream = getClass().getResourceAsStream("/3D8B00E198E21827.asc")) { Optional aPublicKeyRing = PublicKeyUtils.loadPublicKeyRing(inputStream, KeyId.from(0x3D8B00E198E21827L)); @@ -140,7 +142,7 @@ public void validateSubKeyWithExternalSignature() throws IOException, PGPExcepti } @Test - public void validateSubKeyWithRevokedSignature() throws IOException, PGPException { + void validateSubKeyWithRevokedSignature() throws IOException, PGPException { try (InputStream inputStream = getClass().getResourceAsStream("/411063A3A0FFD119.asc")) { Optional aPublicKeyRing = PublicKeyUtils.loadPublicKeyRing(inputStream, KeyId.from(0x411063A3A0FFD119L)); diff --git a/src/test/java/org/simplify4u/plugins/pgp/ReportsUtilsTest.java b/src/test/java/org/simplify4u/plugins/pgp/ReportsUtilsTest.java index 44c78cb2..bfdba786 100644 --- a/src/test/java/org/simplify4u/plugins/pgp/ReportsUtilsTest.java +++ b/src/test/java/org/simplify4u/plugins/pgp/ReportsUtilsTest.java @@ -26,22 +26,22 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.simplify4u.plugins.TestUtils.aSignatureCheckResultBuilder; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class ReportsUtilsTest { +class ReportsUtilsTest { - private ReportsUtils reportsUtils = new ReportsUtils(); + private final ReportsUtils reportsUtils = new ReportsUtils(); private File reportFile; - @BeforeMethod + @BeforeEach void setup() throws IOException { reportFile = File.createTempFile("report-test", ".json"); reportFile.deleteOnExit(); } - @AfterMethod + @AfterEach void cleanup() { reportFile.delete(); } diff --git a/src/test/java/org/simplify4u/plugins/pgp/SignatureUtilsTest.java b/src/test/java/org/simplify4u/plugins/pgp/SignatureUtilsTest.java index aae8836e..e0b682d7 100644 --- a/src/test/java/org/simplify4u/plugins/pgp/SignatureUtilsTest.java +++ b/src/test/java/org/simplify4u/plugins/pgp/SignatureUtilsTest.java @@ -37,13 +37,14 @@ import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPPublicKeyRing; import org.bouncycastle.openpgp.PGPSignature; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.mockito.Mockito; import org.simplify4u.plugins.TestArtifactBuilder; import org.simplify4u.plugins.keyserver.PGPKeyNotFound; import org.simplify4u.plugins.keyserver.PGPKeysCache; import org.simplify4u.plugins.utils.HexUtils; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; public class SignatureUtilsTest { @@ -95,13 +96,13 @@ void testLoadSignatureContentIsSignature() throws IOException, SignatureExceptio } } - @Test(dataProvider = "provider-signature-hash-algorithms") + @ParameterizedTest + @MethodSource("providerSignatureHashAlgorithms") void testCheckWeakHashAlgorithmAllAlgorithms(int algorithm, boolean strong) { assertThat(signatureUtils.checkWeakHashAlgorithm(algorithm) == null).isEqualTo(strong); } - @DataProvider(name = "provider-signature-hash-algorithms") - Object[][] providerSignatureHashAlgorithms() { + public static Object[][] providerSignatureHashAlgorithms() { return new Object[][]{ {HashAlgorithmTags.MD5, false}, {HashAlgorithmTags.SHA1, true}, @@ -302,14 +303,15 @@ void checkSignaturePositiveFlow() throws IOException, PGPException { .build()); } - @DataProvider - Object[] keyAlgorithms() { + + public static Object[] keyAlgorithms() { return Arrays.stream(PublicKeyAlgorithmTags.class.getDeclaredFields()) .map(filed -> Try.of(() -> filed.getInt(null)).get()) .toArray(); } - @Test(dataProvider = "keyAlgorithms") + @ParameterizedTest + @MethodSource("keyAlgorithms") void keyAlgorithmNameShouldBeResolved(int keyAlgorithm) { assertThat(signatureUtils.keyAlgorithmName(keyAlgorithm)).isNotBlank(); } diff --git a/src/test/java/org/simplify4u/plugins/skipfilters/CompositeSkipperTest.java b/src/test/java/org/simplify4u/plugins/skipfilters/CompositeSkipperTest.java index cf95971d..f8498fc7 100644 --- a/src/test/java/org/simplify4u/plugins/skipfilters/CompositeSkipperTest.java +++ b/src/test/java/org/simplify4u/plugins/skipfilters/CompositeSkipperTest.java @@ -17,30 +17,30 @@ package org.simplify4u.plugins.skipfilters; import org.apache.maven.artifact.DefaultArtifact; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import static java.util.Arrays.asList; import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -public class CompositeSkipperTest { +class CompositeSkipperTest { @Test - public void testNullFilters() { + void testNullFilters() { assertThrows(NullPointerException.class, () -> new CompositeSkipper((Iterable) null)); assertThrows(NullPointerException.class, () -> new CompositeSkipper((SkipFilter[]) null)); assertThrows(IllegalArgumentException.class, () -> new CompositeSkipper((SkipFilter) null)); } - @Test(expectedExceptions = NullPointerException.class) - public void testEmptyFiltersList() { + @Test + void testEmptyFiltersList() { final CompositeSkipper filter = new CompositeSkipper(emptyList()); - filter.shouldSkipArtifact(null); + assertThrows(NullPointerException.class, () -> filter.shouldSkipArtifact(null)); } @Test - public void testActualArtifactEmptyFiltersList() { + void testActualArtifactEmptyFiltersList() { final DefaultArtifact artifact = new DefaultArtifact("abc", "def", "1.2.0", "compile", "jar", "some-classifier", null); final CompositeSkipper filter = new CompositeSkipper(emptyList()); @@ -48,7 +48,7 @@ public void testActualArtifactEmptyFiltersList() { } @Test - public void testCompileScopedArtifactProvidedScopeFilter() { + void testCompileScopedArtifactProvidedScopeFilter() { final DefaultArtifact artifact = new DefaultArtifact("abc", "def", "1.2.0", "compile", "jar", "some-classifier", null); final CompositeSkipper filter = new CompositeSkipper(singletonList(new ProvidedDependencySkipper())); @@ -56,7 +56,7 @@ public void testCompileScopedArtifactProvidedScopeFilter() { } @Test - public void testProvidedScopedArtifactProvidedScopeFilter() { + void testProvidedScopedArtifactProvidedScopeFilter() { final DefaultArtifact artifact = new DefaultArtifact("abc", "def", "1.2.0", "provided", "jar", "some-classifier", null); final CompositeSkipper filter = new CompositeSkipper(singletonList(new ProvidedDependencySkipper())); @@ -64,7 +64,7 @@ public void testProvidedScopedArtifactProvidedScopeFilter() { } @Test - public void testProvidedScopedArtifactMultipleFilters() { + void testProvidedScopedArtifactMultipleFilters() { final CompositeSkipper filter = new CompositeSkipper(asList( new ProvidedDependencySkipper(), new SnapshotDependencySkipper())); assertTrue(filter.shouldSkipArtifact(new DefaultArtifact("abc", "def", "1.2.0", "provided", diff --git a/src/test/java/org/simplify4u/plugins/skipfilters/ProvidedDependencySkipperTest.java b/src/test/java/org/simplify4u/plugins/skipfilters/ProvidedDependencySkipperTest.java index 1ce8b1f7..7adb1d64 100644 --- a/src/test/java/org/simplify4u/plugins/skipfilters/ProvidedDependencySkipperTest.java +++ b/src/test/java/org/simplify4u/plugins/skipfilters/ProvidedDependencySkipperTest.java @@ -17,29 +17,28 @@ package org.simplify4u.plugins.skipfilters; import org.apache.maven.artifact.DefaultArtifact; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; @SuppressWarnings("ConstantConditions") -public class ProvidedDependencySkipperTest { +class ProvidedDependencySkipperTest { - @Test(expectedExceptions = NullPointerException.class) - public void testNullArtifact() { + @Test + void testNullArtifact() { final ProvidedDependencySkipper filter = new ProvidedDependencySkipper(); - filter.shouldSkipArtifact(null); + assertThrows(NullPointerException.class, () -> filter.shouldSkipArtifact(null)); } @Test - public void testCompileArtifact() { + void testCompileArtifact() { final ProvidedDependencySkipper filter = new ProvidedDependencySkipper(); assertFalse(filter.shouldSkipArtifact(new DefaultArtifact("abc", "def", "1.0.0", "compile", "jar", "classifier", null))); } @Test - public void testProvidedArtifact() { + void testProvidedArtifact() { final ProvidedDependencySkipper filter = new ProvidedDependencySkipper(); assertTrue(filter.shouldSkipArtifact(new DefaultArtifact("abc", "def", "1.0.0", "provided", "jar", "classifier", null))); diff --git a/src/test/java/org/simplify4u/plugins/skipfilters/ScopeSkipperTest.java b/src/test/java/org/simplify4u/plugins/skipfilters/ScopeSkipperTest.java index 23260dd4..fd7e6c8d 100644 --- a/src/test/java/org/simplify4u/plugins/skipfilters/ScopeSkipperTest.java +++ b/src/test/java/org/simplify4u/plugins/skipfilters/ScopeSkipperTest.java @@ -18,20 +18,19 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DefaultArtifact; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; -public class ScopeSkipperTest { +class ScopeSkipperTest { - @Test(expectedExceptions = NullPointerException.class) - public void testConstructNullScopeFilter() { - new ScopeSkipper(null); + @Test + void testConstructNullScopeFilter() { + assertThrows(NullPointerException.class, () -> new ScopeSkipper(null)); } @Test - public void testConstructTestScopeFilter() { + void testConstructTestScopeFilter() { final ScopeSkipper filter = new ScopeSkipper(Artifact.SCOPE_TEST); assertFalse(filter.shouldSkipArtifact(new DefaultArtifact("a", "b", "1.0", "system", "jar", "classifier", null))); assertFalse(filter.shouldSkipArtifact(new DefaultArtifact("a", "b", "1.0", "provided", "jar", "classifier", null))); @@ -41,7 +40,7 @@ public void testConstructTestScopeFilter() { } @Test - public void testConstructCompileScopeFilter() { + void testConstructCompileScopeFilter() { final ScopeSkipper filter = new ScopeSkipper(Artifact.SCOPE_COMPILE); assertFalse(filter.shouldSkipArtifact(new DefaultArtifact("a", "b", "1.0", "system", "jar", "classifier", null))); assertFalse(filter.shouldSkipArtifact(new DefaultArtifact("a", "b", "1.0", "provided", "jar", "classifier", null))); @@ -51,7 +50,7 @@ public void testConstructCompileScopeFilter() { } @Test - public void testConstructRuntimeScopeFilter() { + void testConstructRuntimeScopeFilter() { final ScopeSkipper filter = new ScopeSkipper(Artifact.SCOPE_RUNTIME); assertTrue(filter.shouldSkipArtifact(new DefaultArtifact("a", "b", "1.0", "system", "jar", "classifier", null))); assertTrue(filter.shouldSkipArtifact(new DefaultArtifact("a", "b", "1.0", "provided", "jar", "classifier", null))); @@ -61,7 +60,7 @@ public void testConstructRuntimeScopeFilter() { } @Test - public void testConstructCompileRuntimeScopeFilter() { + void testConstructCompileRuntimeScopeFilter() { final ScopeSkipper filter = new ScopeSkipper(Artifact.SCOPE_COMPILE_PLUS_RUNTIME); assertFalse(filter.shouldSkipArtifact(new DefaultArtifact("a", "b", "1.0", "system", "jar", "classifier", null))); assertFalse(filter.shouldSkipArtifact(new DefaultArtifact("a", "b", "1.0", "provided", "jar", "classifier", null))); @@ -71,7 +70,7 @@ public void testConstructCompileRuntimeScopeFilter() { } @Test - public void testConstructInvalidScopeFilter() { + void testConstructInvalidScopeFilter() { final ScopeSkipper filter = new ScopeSkipper("invalid-scope"); assertTrue(filter.shouldSkipArtifact(new DefaultArtifact("a", "b", "1.0", "system", "jar", "classifier", null))); assertTrue(filter.shouldSkipArtifact(new DefaultArtifact("a", "b", "1.0", "provided", "jar", "classifier", null))); diff --git a/src/test/java/org/simplify4u/plugins/skipfilters/SnapshotDependencySkipperTest.java b/src/test/java/org/simplify4u/plugins/skipfilters/SnapshotDependencySkipperTest.java index 7d7d0e96..c4ad8c94 100644 --- a/src/test/java/org/simplify4u/plugins/skipfilters/SnapshotDependencySkipperTest.java +++ b/src/test/java/org/simplify4u/plugins/skipfilters/SnapshotDependencySkipperTest.java @@ -17,28 +17,28 @@ package org.simplify4u.plugins.skipfilters; import org.apache.maven.artifact.DefaultArtifact; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; @SuppressWarnings("ConstantConditions") -public class SnapshotDependencySkipperTest { +class SnapshotDependencySkipperTest { - @Test(expectedExceptions = NullPointerException.class) - public void testNullArtifact() { + @Test + void testNullArtifact() { final SnapshotDependencySkipper filter = new SnapshotDependencySkipper(); - filter.shouldSkipArtifact(null); + assertThrows(NullPointerException.class, () -> filter.shouldSkipArtifact(null)); } @Test - public void testCompileArtifact() { + void testCompileArtifact() { final SnapshotDependencySkipper filter = new SnapshotDependencySkipper(); assertFalse(filter.shouldSkipArtifact(new DefaultArtifact("abc", "def", "1.0.0", "compile", "jar", "classifier", null))); } @Test - public void testProvidedArtifact() { + void testProvidedArtifact() { final SnapshotDependencySkipper filter = new SnapshotDependencySkipper(); assertTrue(filter.shouldSkipArtifact(new DefaultArtifact("abc", "def", "1.0.0-SNAPSHOT", "compile", "jar", "classifier", null))); diff --git a/src/test/java/org/simplify4u/plugins/skipfilters/SystemDependencySkipperTest.java b/src/test/java/org/simplify4u/plugins/skipfilters/SystemDependencySkipperTest.java index b445ad01..27564ab9 100644 --- a/src/test/java/org/simplify4u/plugins/skipfilters/SystemDependencySkipperTest.java +++ b/src/test/java/org/simplify4u/plugins/skipfilters/SystemDependencySkipperTest.java @@ -17,28 +17,28 @@ package org.simplify4u.plugins.skipfilters; import org.apache.maven.artifact.DefaultArtifact; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; @SuppressWarnings("ConstantConditions") -public class SystemDependencySkipperTest { +class SystemDependencySkipperTest { - @Test(expectedExceptions = NullPointerException.class) - public void testNullArtifact() { + @Test + void testNullArtifact() { final SystemDependencySkipper filter = new SystemDependencySkipper(); - filter.shouldSkipArtifact(null); + assertThrows(NullPointerException.class, () -> filter.shouldSkipArtifact(null)); } @Test - public void testCompileArtifact() { + void testCompileArtifact() { final SystemDependencySkipper filter = new SystemDependencySkipper(); assertFalse(filter.shouldSkipArtifact(new DefaultArtifact("abc", "def", "1.0.0", "provided", "jar", "classifier", null))); } @Test - public void testProvidedArtifact() { + void testProvidedArtifact() { final SystemDependencySkipper filter = new SystemDependencySkipper(); assertTrue(filter.shouldSkipArtifact(new DefaultArtifact("abc", "def", "1.0.0", "system", "jar", "classifier", null))); diff --git a/src/test/java/org/simplify4u/plugins/utils/ExceptionUtilsTest.java b/src/test/java/org/simplify4u/plugins/utils/ExceptionUtilsTest.java index 9592ab46..b11a00ac 100644 --- a/src/test/java/org/simplify4u/plugins/utils/ExceptionUtilsTest.java +++ b/src/test/java/org/simplify4u/plugins/utils/ExceptionUtilsTest.java @@ -17,12 +17,11 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; -public class ExceptionUtilsTest { +class ExceptionUtilsTest { - @DataProvider public static Object[][] examplesMessages() { return new Object[][] { {new Exception(), null}, @@ -33,8 +32,9 @@ public static Object[][] examplesMessages() { } - @Test(dataProvider = "examplesMessages") - public void testGetMessage(Throwable trThrowable, String expectedMessage) { + @ParameterizedTest + @MethodSource("examplesMessages") + void testGetMessage(Throwable trThrowable, String expectedMessage) { assertThat(ExceptionUtils.getMessage(trThrowable)).isEqualTo(expectedMessage); } diff --git a/src/test/java/org/simplify4u/plugins/utils/MavenCompilerUtilsTest.java b/src/test/java/org/simplify4u/plugins/utils/MavenCompilerUtilsTest.java index e47d3646..927bf752 100644 --- a/src/test/java/org/simplify4u/plugins/utils/MavenCompilerUtilsTest.java +++ b/src/test/java/org/simplify4u/plugins/utils/MavenCompilerUtilsTest.java @@ -19,26 +19,23 @@ import org.apache.maven.model.Plugin; import org.apache.maven.repository.RepositorySystem; import org.codehaus.plexus.util.xml.Xpp3Dom; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.util.Set; import static java.util.Collections.emptySet; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.simplify4u.plugins.utils.MavenCompilerUtils.checkCompilerPlugin; import static org.simplify4u.plugins.utils.MavenCompilerUtils.extractAnnotationProcessors; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertThrows; -import static org.testng.Assert.assertTrue; @SuppressWarnings({"ConstantConditions", "SameParameterValue"}) -public final class MavenCompilerUtilsTest { +final class MavenCompilerUtilsTest { @Test - public void testCheckCompilerPlugin() { + void testCheckCompilerPlugin() { assertThrows(NullPointerException.class, () -> checkCompilerPlugin(null)); final Plugin compilerPlugin = mock(Plugin.class); when(compilerPlugin.getGroupId()).thenReturn("org.apache.maven.plugins"); @@ -53,7 +50,7 @@ public void testCheckCompilerPlugin() { } @Test - public void testExtractAnnotationProcessorsIllegalInputs() { + void testExtractAnnotationProcessorsIllegalInputs() { assertThrows(NullPointerException.class, () -> extractAnnotationProcessors(null, null)); final Plugin badPlugin = mock(Plugin.class); when(badPlugin.getGroupId()).thenReturn("org.my-bad-plugin"); @@ -66,17 +63,17 @@ public void testExtractAnnotationProcessorsIllegalInputs() { } @Test - public void testExtractAnnotationProcessorsNoConfiguration() { + void testExtractAnnotationProcessorsNoConfiguration() { final RepositorySystem repository = mock(RepositorySystem.class); final Plugin plugin = mock(Plugin.class); when(plugin.getGroupId()).thenReturn("org.apache.maven.plugins"); when(plugin.getArtifactId()).thenReturn("maven-compiler-plugin"); when(plugin.getVersion()).thenReturn("3.8.1"); - assertEquals(extractAnnotationProcessors(repository, plugin), emptySet()); + assertEquals(emptySet(), extractAnnotationProcessors(repository, plugin)); } @Test - public void testExtractAnnotationProcessorsUnsupportedConfigurationType() { + void testExtractAnnotationProcessorsUnsupportedConfigurationType() { final RepositorySystem repository = mock(RepositorySystem.class); final Plugin plugin = mock(Plugin.class); when(plugin.getGroupId()).thenReturn("org.apache.maven.plugins"); @@ -87,7 +84,7 @@ public void testExtractAnnotationProcessorsUnsupportedConfigurationType() { } @Test - public void testExtractAnnotationProcessors() { + void testExtractAnnotationProcessors() { final RepositorySystem repository = mock(RepositorySystem.class); final Plugin plugin = mock(Plugin.class); when(plugin.getGroupId()).thenReturn("org.apache.maven.plugins"); @@ -102,11 +99,11 @@ public void testExtractAnnotationProcessors() { return artifact; }); final Set result = extractAnnotationProcessors(repository, plugin); - assertEquals(result.size(), 1); + assertEquals(1, result.size()); final Artifact resultElement = result.iterator().next(); - assertEquals(resultElement.getGroupId(), "myGroupId"); - assertEquals(resultElement.getArtifactId(), "myArtifactId"); - assertEquals(resultElement.getVersion(), "1.2.3"); + assertEquals("myGroupId", resultElement.getGroupId()); + assertEquals("myArtifactId", resultElement.getArtifactId()); + assertEquals("1.2.3", resultElement.getVersion()); } private static Xpp3Dom createConfiguration() {