Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate to JUnit from TestNG #436

Merged
merged 1 commit into from
Feb 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -272,18 +272,23 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-testng</artifactId>
<version>0.4.31</version>
<artifactId>mockito-junit-jupiter</artifactId>
<version>4.11.0</version>
</dependency>
<dependency>
<groupId>org.simplify4u</groupId>
<artifactId>slf4j-mock</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.4.0</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.9.1</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.9.1</version>
</dependency>
<!-- /testing -->
</dependencies>
Expand Down Expand Up @@ -418,7 +423,7 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-testng</artifactId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -427,8 +432,13 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<!-- /testing -->
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/org/simplify4u/plugins/AbstractPGPMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
39 changes: 20 additions & 19 deletions src/test/java/org/simplify4u/plugins/ArtifactResolverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Artifact> IS_JAR_TYPE = new Condition<>(a -> "jar".equals(a.getType()), "is jar type");
private static final Condition<Artifact> IS_POM_TYPE = new Condition<>(a -> "pom".equals(a.getType()), "is pom type");
Expand All @@ -76,7 +77,7 @@ public class ArtifactResolverTest {

private ArtifactResolver resolver;

@BeforeMethod
@BeforeEach
void setup() {
when(session.getLocalRepository()).thenReturn(localRepository);
when(session.getCurrentProject()).thenReturn(project);
Expand All @@ -86,7 +87,7 @@ void setup() {
}

@Test
public void testConstructArtifactResolverWithNull() {
void testConstructArtifactResolverWithNull() {

reset(session, project);

Expand All @@ -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()),
Expand All @@ -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<ArtifactResolutionResult>) invocation -> {
Expand All @@ -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<ArtifactResolutionResult>) invocation -> {
Expand Down Expand Up @@ -179,7 +180,7 @@ public void testResolveProjectArtifactsWithPoms() throws MojoExecutionException
}

@Test
public void testResolveSignaturesEmpty() throws MojoExecutionException {
void testResolveSignaturesEmpty() throws MojoExecutionException {

// when
Map<Artifact, Artifact> resolved = resolver.resolveSignatures(emptyList());
Expand All @@ -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<ArtifactResolutionResult>) invocation -> {
Expand Down Expand Up @@ -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<ArtifactResolutionResult>) invocation -> {
Artifact artifact = invocation.<ArtifactResolutionRequest>getArgument(0).getArtifact();
Expand All @@ -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(),
Expand All @@ -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},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
19 changes: 10 additions & 9 deletions src/test/java/org/simplify4u/plugins/ShowMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
38 changes: 19 additions & 19 deletions src/test/java/org/simplify4u/plugins/ValidationChecksumTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,60 +24,60 @@

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)
.forEach(File::delete);
}

@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();
assertThat(checksum.checkValidation()).isFalse();
}

@Test
public void testValidationChecksumBuilderChecksumArtifactsNullFails() {
void testValidationChecksumBuilderChecksumArtifactsNullFails() {

final Artifact a1 = TestArtifactBuilder.testArtifact()
.groupId("org.apache.maven.plugins")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -51,7 +51,7 @@ public class KeyServerClientSettingsTest {
*
*/
@Test
public void testIfProxyDeterminationWorksUsingIDs() {
void testIfProxyDeterminationWorksUsingIDs() {

List<Proxy> proxies = Arrays.asList(
makeMavenProxy(null, null, "p1", true),
Expand Down Expand Up @@ -79,7 +79,7 @@ public void testIfProxyDeterminationWorksUsingIDs() {
*
*/
@Test
public void testIfProxyDeterminationWorksUsinFirstActive() {
void testIfProxyDeterminationWorksUsinFirstActive() {

when(mavenSession.getSettings()).thenReturn(settings);
when(settings.getActiveProxy()).thenReturn(makeMavenProxy("p5"));
Expand Down
Loading