Skip to content

Commit

Permalink
Merge pull request #316 from timtebeek/junit-jupiter
Browse files Browse the repository at this point in the history
Migrate to JUnit Jupiter through OpenRewrite
  • Loading branch information
sparsick authored Feb 14, 2023
2 parents 49e5d3c + ea8c214 commit 1aa0722
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 96 deletions.
22 changes: 14 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -266,17 +266,10 @@
<version>4.7.3</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>3.12.4</version>
<version>4.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -285,6 +278,19 @@
<version>3.21.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.9.2</version>
<scope>test</scope>
</dependency>
<!-- Required by target/generated-sources/groovy-stubs/test -->
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.9.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/org/reficio/p2/P2ArtifactTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@
*/
package org.reficio.p2;

import static org.junit.Assert.*;
import org.junit.jupiter.api.Test;

import java.util.Collections;
import java.util.Map;
import java.util.Properties;

import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* @since 1.4.0
*/
public class P2ArtifactTest {
class P2ArtifactTest {

@Test
public void testCombinedInstructions() {
void testCombinedInstructions() {
// GIVEN
P2Artifact artifact = new P2Artifact();
artifact.setInstructions(Collections.singletonMap("Import-Package", "package.one"));
Expand All @@ -50,7 +50,7 @@ public void testCombinedInstructions() {
}

@Test
public void testInstructionsPropertiesOverrideInstructions() {
void testInstructionsPropertiesOverrideInstructions() {
// GIVEN
P2Artifact artifact = new P2Artifact();
artifact.setInstructions(Collections.singletonMap("Export-Package", "package.one"));
Expand All @@ -67,7 +67,7 @@ public void testInstructionsPropertiesOverrideInstructions() {
}

@Test
public void testInstructionsPropertiesOverrideInstructionsWhenPropertiesSetFirst() {
void testInstructionsPropertiesOverrideInstructionsWhenPropertiesSetFirst() {
// GIVEN
P2Artifact artifact = new P2Artifact();
Properties instructionsProperties = new Properties();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/
package org.reficio.p2.bundler;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.reficio.p2.P2Helper.calculateSourceName;

/**
Expand All @@ -29,10 +29,10 @@
* http://www.reficio.org
* @since 1.0.0
*/
public class ArtifactBundlerInstructionTest {
class ArtifactBundlerInstructionTest {

@Test
public void calculateSourceName_specTest() {
void calculateSourceName_specTest() {
assertEquals("org.reficio.p2.source", calculateSourceName(null, "org.reficio.p2"));
assertEquals("org.reficio.P2.source", calculateSourceName(null, "org.reficio.P2"));
assertEquals("Reficio P2 Source", calculateSourceName("Reficio P2", "org.reficio.p2"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
*/
package org.reficio.p2.bundler;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.Collections;

import static org.assertj.core.api.Assertions.assertThat;


public class ArtifactBundlerInstructionsTest {
class ArtifactBundlerInstructionsTest {

@Test
public void useDefaultInstruction(){
void useDefaultInstruction() {
ArtifactBundlerInstructions artifactBundlerInstructions = ArtifactBundlerInstructions.builder().build();

assertThat(artifactBundlerInstructions.getInstructions())
Expand All @@ -39,7 +39,7 @@ public void useDefaultInstruction(){
}

@Test
public void ignoreDefaultInstruction(){
void ignoreDefaultInstruction() {
ArtifactBundlerInstructions artifactBundlerInstructions = ArtifactBundlerInstructions.builder()
.instructions(Collections.singletonMap("-noee", "true"))
.build();
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/org/reficio/p2/bundler/P2ArtifactMapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
*/
package org.reficio.p2.bundler;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.reficio.p2.P2Artifact;

import java.util.Collection;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertNotNull;

public class P2ArtifactMapTest {
class P2ArtifactMapTest {

@Test
public void getNoFoundValueReturnsEmptyList() {
void getNoFoundValueReturnsEmptyList() {
P2ArtifactMap<P2Artifact> mapUnderTest = new P2ArtifactMap<>();

Collection<P2Artifact> value = mapUnderTest.get(new P2Artifact());
Expand Down
20 changes: 10 additions & 10 deletions src/test/java/org/reficio/p2/bundler/impl/AquteBundlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.apache.maven.plugin.logging.SystemStreamLog;
import org.assertj.core.api.ThrowableAssert;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
import org.reficio.p2.bundler.AquteAnalyzerException;
import org.reficio.p2.bundler.ArtifactBundlerInstructions;
Expand All @@ -39,21 +39,21 @@
import static org.mockito.Mockito.mockStatic;

@SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE")
public class AquteBundlerTest {
class AquteBundlerTest {


@BeforeClass
public static void setUpClass() {
@BeforeAll
static void setUpClass() {
Logger.initialize(new SystemStreamLog());
}

@AfterClass
public static void cleanUp() {
@AfterAll
static void cleanUp() {
Logger.initialize(null);
}

@Test
public void bndAnalyzerProduceErrorThenExceptionIsExpected() {
void bndAnalyzerProduceErrorThenExceptionIsExpected() {
try (MockedStatic<AquteHelper> theMock = mockStatic(AquteHelper.class)) {
theMock.when(() -> AquteHelper.buildAnalyzer(any(ArtifactBundlerRequest.class), any(ArtifactBundlerInstructions.class), anyBoolean()))
.thenReturn(new AnalyzerStub());
Expand All @@ -66,7 +66,7 @@ public void bndAnalyzerProduceErrorThenExceptionIsExpected() {
}

@Test
public void bndAnalyzerProduceErrorThenExceptionIsUnexpected() {
void bndAnalyzerProduceErrorThenExceptionIsUnexpected() {
try (MockedStatic<AquteHelper> theMock = mockStatic(AquteHelper.class)) {
theMock.when(() -> AquteHelper.buildAnalyzer(any(ArtifactBundlerRequest.class), any(ArtifactBundlerInstructions.class), anyBoolean()))
.thenReturn(new AnalyzerStub());
Expand Down
14 changes: 9 additions & 5 deletions src/test/java/org/reficio/p2/logger/LoggerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,23 @@
*/
package org.reficio.p2.logger;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertThrows;

/**
* @author Tom Bujok ([email protected])<br>
* Reficio (TM) - Reestablish your software!<br>
* http://www.reficio.org
* @since 1.0.0
*/
public class LoggerTest {
class LoggerTest {

@Test(expected = RuntimeException.class)
public void getLog_uninitializedLogger_exceptionThrown() {
Logger.getLog();
@Test
void getLog_uninitializedLogger_exceptionThrown() {
assertThrows(RuntimeException.class, () -> {
Logger.getLog();
});
}

}
69 changes: 40 additions & 29 deletions src/test/java/org/reficio/p2/publisher/CategoryPublisherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
import org.apache.maven.plugin.AbstractMojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.eclipse.sisu.equinox.launching.internal.P2ApplicationLauncher;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.when;

/**
Expand All @@ -36,44 +37,54 @@
* http://www.reficio.org
* @since 1.0.0
*/
public class CategoryPublisherTest {
class CategoryPublisherTest {

@Test(expected = NullPointerException.class)
public void nullLauncher() {
CategoryPublisher.builder().p2ApplicationLauncher(null);
@Test
void nullLauncher() {
assertThrows(NullPointerException.class, () -> {
CategoryPublisher.builder().p2ApplicationLauncher(null);
});
}

@Test(expected = NullPointerException.class)
public void emptyBuilder() {
CategoryPublisher.builder().build();
@Test
void emptyBuilder() {
assertThrows(NullPointerException.class, () -> {
CategoryPublisher.builder().build();
});
}

@Test(expected = IllegalArgumentException.class)
public void wrongTimeout() {
CategoryPublisher.builder().forkedProcessTimeoutInSeconds(-1);
@Test
void wrongTimeout() {
assertThrows(IllegalArgumentException.class, () -> {
CategoryPublisher.builder().forkedProcessTimeoutInSeconds(-1);
});
}

@Test(expected = IllegalArgumentException.class)
public void wrongArgs() {
CategoryPublisher.builder().additionalArgs("--zcx.vzxc.v§';s.dcxz-1-aods[vzmcxvlkzndofahsdpf");
@Test
void wrongArgs() {
assertThrows(IllegalArgumentException.class, () -> {
CategoryPublisher.builder().additionalArgs("--zcx.vzxc.v§';s.dcxz-1-aods[vzmcxvlkzndofahsdpf");
});
}

@Test(expected = MojoFailureException.class)
public void exceptionThrownInCaseOfLauncherFailure() throws IOException, AbstractMojoExecutionException {
// given
P2ApplicationLauncher launcher = Mockito.mock(P2ApplicationLauncher.class, Mockito.RETURNS_DEEP_STUBS);
when(launcher.execute(Mockito.anyInt())).thenReturn(137);
File file = File.createTempFile(UUID.randomUUID().toString(), UUID.randomUUID().toString());
file.deleteOnExit();
@Test
void exceptionThrownInCaseOfLauncherFailure() throws IOException, AbstractMojoExecutionException {
assertThrows(MojoFailureException.class, () -> {
// given
P2ApplicationLauncher launcher = Mockito.mock(P2ApplicationLauncher.class, Mockito.RETURNS_DEEP_STUBS);
when(launcher.execute(Mockito.anyInt())).thenReturn(137);
File file = File.createTempFile(UUID.randomUUID().toString(), UUID.randomUUID().toString());
file.deleteOnExit();

// when
CategoryPublisher publisher = CategoryPublisher.builder()
.p2ApplicationLauncher(launcher)
.categoryFileLocation(file.getPath())
.additionalArgs("-args")
.metadataRepositoryLocation("target/tmp")
.build();
publisher.execute();
// when
CategoryPublisher publisher = CategoryPublisher.builder()
.p2ApplicationLauncher(launcher)
.categoryFileLocation(file.getPath())
.additionalArgs("-args")
.metadataRepositoryLocation("target/tmp")
.build();
publisher.execute();
});
}

}
10 changes: 4 additions & 6 deletions src/test/java/org/reficio/p2/resolver/impl/AetherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@
*/
package org.reficio.p2.resolver.impl;

import org.hamcrest.core.IsInstanceOf;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.reficio.p2.resolver.maven.impl.Aether;
import org.reficio.p2.resolver.maven.impl.facade.AetherEclipseFacade;
import org.reficio.p2.resolver.maven.impl.facade.AetherFacade;
import org.reficio.p2.resolver.maven.impl.facade.AetherSonatypeFacade;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;

/**
Expand All @@ -35,10 +33,10 @@
* http://www.reficio.org
* @since 1.1.0
*/
public class AetherTest {
class AetherTest {

@Test
public void facade_sonatypeAetherSystem() {
void facade_sonatypeAetherSystem() {
// GIVEN
Object repositorySystem = mock(org.sonatype.aether.RepositorySystem.class);

Expand All @@ -50,7 +48,7 @@ public void facade_sonatypeAetherSystem() {
}

@Test
public void facade_eclipseAetherSystem() {
void facade_eclipseAetherSystem() {
// GIVEN
Object repositorySystem = mock(org.eclipse.aether.RepositorySystem.class);

Expand Down
Loading

0 comments on commit 1aa0722

Please sign in to comment.