Skip to content

Commit 1aa0722

Browse files
authored
Merge pull request #316 from timtebeek/junit-jupiter
Migrate to JUnit Jupiter through OpenRewrite
2 parents 49e5d3c + ea8c214 commit 1aa0722

File tree

10 files changed

+117
-96
lines changed

10 files changed

+117
-96
lines changed

pom.xml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,17 +266,10 @@
266266
<version>4.7.3</version>
267267
<scope>provided</scope>
268268
</dependency>
269-
270-
<dependency>
271-
<groupId>junit</groupId>
272-
<artifactId>junit</artifactId>
273-
<version>4.13.2</version>
274-
<scope>test</scope>
275-
</dependency>
276269
<dependency>
277270
<groupId>org.mockito</groupId>
278271
<artifactId>mockito-inline</artifactId>
279-
<version>3.12.4</version>
272+
<version>4.11.0</version>
280273
<scope>test</scope>
281274
</dependency>
282275
<dependency>
@@ -285,6 +278,19 @@
285278
<version>3.21.0</version>
286279
<scope>test</scope>
287280
</dependency>
281+
<dependency>
282+
<groupId>org.junit.jupiter</groupId>
283+
<artifactId>junit-jupiter</artifactId>
284+
<version>5.9.2</version>
285+
<scope>test</scope>
286+
</dependency>
287+
<!-- Required by target/generated-sources/groovy-stubs/test -->
288+
<dependency>
289+
<groupId>org.junit.vintage</groupId>
290+
<artifactId>junit-vintage-engine</artifactId>
291+
<version>5.9.2</version>
292+
<scope>test</scope>
293+
</dependency>
288294
</dependencies>
289295

290296
<build>

src/test/java/org/reficio/p2/P2ArtifactTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@
1818
*/
1919
package org.reficio.p2;
2020

21-
import static org.junit.Assert.*;
21+
import org.junit.jupiter.api.Test;
2222

2323
import java.util.Collections;
2424
import java.util.Map;
2525
import java.util.Properties;
2626

27-
import org.junit.Test;
27+
import static org.junit.jupiter.api.Assertions.assertEquals;
2828

2929
/**
3030
* @since 1.4.0
3131
*/
32-
public class P2ArtifactTest {
32+
class P2ArtifactTest {
3333

3434
@Test
35-
public void testCombinedInstructions() {
35+
void testCombinedInstructions() {
3636
// GIVEN
3737
P2Artifact artifact = new P2Artifact();
3838
artifact.setInstructions(Collections.singletonMap("Import-Package", "package.one"));
@@ -50,7 +50,7 @@ public void testCombinedInstructions() {
5050
}
5151

5252
@Test
53-
public void testInstructionsPropertiesOverrideInstructions() {
53+
void testInstructionsPropertiesOverrideInstructions() {
5454
// GIVEN
5555
P2Artifact artifact = new P2Artifact();
5656
artifact.setInstructions(Collections.singletonMap("Export-Package", "package.one"));
@@ -67,7 +67,7 @@ public void testInstructionsPropertiesOverrideInstructions() {
6767
}
6868

6969
@Test
70-
public void testInstructionsPropertiesOverrideInstructionsWhenPropertiesSetFirst() {
70+
void testInstructionsPropertiesOverrideInstructionsWhenPropertiesSetFirst() {
7171
// GIVEN
7272
P2Artifact artifact = new P2Artifact();
7373
Properties instructionsProperties = new Properties();

src/test/java/org/reficio/p2/bundler/ArtifactBundlerInstructionTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
*/
1919
package org.reficio.p2.bundler;
2020

21-
import org.junit.Test;
21+
import org.junit.jupiter.api.Test;
2222

23-
import static org.junit.Assert.assertEquals;
23+
import static org.junit.jupiter.api.Assertions.assertEquals;
2424
import static org.reficio.p2.P2Helper.calculateSourceName;
2525

2626
/**
@@ -29,10 +29,10 @@
2929
* http://www.reficio.org
3030
* @since 1.0.0
3131
*/
32-
public class ArtifactBundlerInstructionTest {
32+
class ArtifactBundlerInstructionTest {
3333

3434
@Test
35-
public void calculateSourceName_specTest() {
35+
void calculateSourceName_specTest() {
3636
assertEquals("org.reficio.p2.source", calculateSourceName(null, "org.reficio.p2"));
3737
assertEquals("org.reficio.P2.source", calculateSourceName(null, "org.reficio.P2"));
3838
assertEquals("Reficio P2 Source", calculateSourceName("Reficio P2", "org.reficio.p2"));

src/test/java/org/reficio/p2/bundler/ArtifactBundlerInstructionsTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@
1818
*/
1919
package org.reficio.p2.bundler;
2020

21-
import org.junit.Test;
21+
import org.junit.jupiter.api.Test;
2222

2323
import java.util.Collections;
2424

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

2727

28-
public class ArtifactBundlerInstructionsTest {
28+
class ArtifactBundlerInstructionsTest {
2929

3030
@Test
31-
public void useDefaultInstruction(){
31+
void useDefaultInstruction() {
3232
ArtifactBundlerInstructions artifactBundlerInstructions = ArtifactBundlerInstructions.builder().build();
3333

3434
assertThat(artifactBundlerInstructions.getInstructions())
@@ -39,7 +39,7 @@ public void useDefaultInstruction(){
3939
}
4040

4141
@Test
42-
public void ignoreDefaultInstruction(){
42+
void ignoreDefaultInstruction() {
4343
ArtifactBundlerInstructions artifactBundlerInstructions = ArtifactBundlerInstructions.builder()
4444
.instructions(Collections.singletonMap("-noee", "true"))
4545
.build();

src/test/java/org/reficio/p2/bundler/P2ArtifactMapTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@
1818
*/
1919
package org.reficio.p2.bundler;
2020

21-
import org.junit.Test;
21+
import org.junit.jupiter.api.Test;
2222
import org.reficio.p2.P2Artifact;
2323

2424
import java.util.Collection;
2525

26-
import static org.junit.Assert.*;
26+
import static org.junit.jupiter.api.Assertions.assertNotNull;
2727

28-
public class P2ArtifactMapTest {
28+
class P2ArtifactMapTest {
2929

3030
@Test
31-
public void getNoFoundValueReturnsEmptyList() {
31+
void getNoFoundValueReturnsEmptyList() {
3232
P2ArtifactMap<P2Artifact> mapUnderTest = new P2ArtifactMap<>();
3333

3434
Collection<P2Artifact> value = mapUnderTest.get(new P2Artifact());

src/test/java/org/reficio/p2/bundler/impl/AquteBundlerTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2323
import org.apache.maven.plugin.logging.SystemStreamLog;
2424
import org.assertj.core.api.ThrowableAssert;
25-
import org.junit.AfterClass;
26-
import org.junit.BeforeClass;
27-
import org.junit.Test;
25+
import org.junit.jupiter.api.AfterAll;
26+
import org.junit.jupiter.api.BeforeAll;
27+
import org.junit.jupiter.api.Test;
2828
import org.mockito.MockedStatic;
2929
import org.reficio.p2.bundler.AquteAnalyzerException;
3030
import org.reficio.p2.bundler.ArtifactBundlerInstructions;
@@ -39,21 +39,21 @@
3939
import static org.mockito.Mockito.mockStatic;
4040

4141
@SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE")
42-
public class AquteBundlerTest {
42+
class AquteBundlerTest {
4343

4444

45-
@BeforeClass
46-
public static void setUpClass() {
45+
@BeforeAll
46+
static void setUpClass() {
4747
Logger.initialize(new SystemStreamLog());
4848
}
4949

50-
@AfterClass
51-
public static void cleanUp() {
50+
@AfterAll
51+
static void cleanUp() {
5252
Logger.initialize(null);
5353
}
5454

5555
@Test
56-
public void bndAnalyzerProduceErrorThenExceptionIsExpected() {
56+
void bndAnalyzerProduceErrorThenExceptionIsExpected() {
5757
try (MockedStatic<AquteHelper> theMock = mockStatic(AquteHelper.class)) {
5858
theMock.when(() -> AquteHelper.buildAnalyzer(any(ArtifactBundlerRequest.class), any(ArtifactBundlerInstructions.class), anyBoolean()))
5959
.thenReturn(new AnalyzerStub());
@@ -66,7 +66,7 @@ public void bndAnalyzerProduceErrorThenExceptionIsExpected() {
6666
}
6767

6868
@Test
69-
public void bndAnalyzerProduceErrorThenExceptionIsUnexpected() {
69+
void bndAnalyzerProduceErrorThenExceptionIsUnexpected() {
7070
try (MockedStatic<AquteHelper> theMock = mockStatic(AquteHelper.class)) {
7171
theMock.when(() -> AquteHelper.buildAnalyzer(any(ArtifactBundlerRequest.class), any(ArtifactBundlerInstructions.class), anyBoolean()))
7272
.thenReturn(new AnalyzerStub());

src/test/java/org/reficio/p2/logger/LoggerTest.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,23 @@
1818
*/
1919
package org.reficio.p2.logger;
2020

21-
import org.junit.Test;
21+
import org.junit.jupiter.api.Test;
22+
23+
import static org.junit.jupiter.api.Assertions.assertThrows;
2224

2325
/**
2426
* @author Tom Bujok ([email protected])<br>
2527
* Reficio (TM) - Reestablish your software!<br>
2628
* http://www.reficio.org
2729
* @since 1.0.0
2830
*/
29-
public class LoggerTest {
31+
class LoggerTest {
3032

31-
@Test(expected = RuntimeException.class)
32-
public void getLog_uninitializedLogger_exceptionThrown() {
33-
Logger.getLog();
33+
@Test
34+
void getLog_uninitializedLogger_exceptionThrown() {
35+
assertThrows(RuntimeException.class, () -> {
36+
Logger.getLog();
37+
});
3438
}
3539

3640
}

src/test/java/org/reficio/p2/publisher/CategoryPublisherTest.java

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@
2121
import org.apache.maven.plugin.AbstractMojoExecutionException;
2222
import org.apache.maven.plugin.MojoFailureException;
2323
import org.eclipse.sisu.equinox.launching.internal.P2ApplicationLauncher;
24-
import org.junit.Test;
24+
import org.junit.jupiter.api.Test;
2525
import org.mockito.Mockito;
2626

2727
import java.io.File;
2828
import java.io.IOException;
2929
import java.util.UUID;
3030

31+
import static org.junit.jupiter.api.Assertions.assertThrows;
3132
import static org.mockito.Mockito.when;
3233

3334
/**
@@ -36,44 +37,54 @@
3637
* http://www.reficio.org
3738
* @since 1.0.0
3839
*/
39-
public class CategoryPublisherTest {
40+
class CategoryPublisherTest {
4041

41-
@Test(expected = NullPointerException.class)
42-
public void nullLauncher() {
43-
CategoryPublisher.builder().p2ApplicationLauncher(null);
42+
@Test
43+
void nullLauncher() {
44+
assertThrows(NullPointerException.class, () -> {
45+
CategoryPublisher.builder().p2ApplicationLauncher(null);
46+
});
4447
}
4548

46-
@Test(expected = NullPointerException.class)
47-
public void emptyBuilder() {
48-
CategoryPublisher.builder().build();
49+
@Test
50+
void emptyBuilder() {
51+
assertThrows(NullPointerException.class, () -> {
52+
CategoryPublisher.builder().build();
53+
});
4954
}
5055

51-
@Test(expected = IllegalArgumentException.class)
52-
public void wrongTimeout() {
53-
CategoryPublisher.builder().forkedProcessTimeoutInSeconds(-1);
56+
@Test
57+
void wrongTimeout() {
58+
assertThrows(IllegalArgumentException.class, () -> {
59+
CategoryPublisher.builder().forkedProcessTimeoutInSeconds(-1);
60+
});
5461
}
5562

56-
@Test(expected = IllegalArgumentException.class)
57-
public void wrongArgs() {
58-
CategoryPublisher.builder().additionalArgs("--zcx.vzxc.v§';s.dcxz-1-aods[vzmcxvlkzndofahsdpf");
63+
@Test
64+
void wrongArgs() {
65+
assertThrows(IllegalArgumentException.class, () -> {
66+
CategoryPublisher.builder().additionalArgs("--zcx.vzxc.v§';s.dcxz-1-aods[vzmcxvlkzndofahsdpf");
67+
});
5968
}
6069

61-
@Test(expected = MojoFailureException.class)
62-
public void exceptionThrownInCaseOfLauncherFailure() throws IOException, AbstractMojoExecutionException {
63-
// given
64-
P2ApplicationLauncher launcher = Mockito.mock(P2ApplicationLauncher.class, Mockito.RETURNS_DEEP_STUBS);
65-
when(launcher.execute(Mockito.anyInt())).thenReturn(137);
66-
File file = File.createTempFile(UUID.randomUUID().toString(), UUID.randomUUID().toString());
67-
file.deleteOnExit();
70+
@Test
71+
void exceptionThrownInCaseOfLauncherFailure() throws IOException, AbstractMojoExecutionException {
72+
assertThrows(MojoFailureException.class, () -> {
73+
// given
74+
P2ApplicationLauncher launcher = Mockito.mock(P2ApplicationLauncher.class, Mockito.RETURNS_DEEP_STUBS);
75+
when(launcher.execute(Mockito.anyInt())).thenReturn(137);
76+
File file = File.createTempFile(UUID.randomUUID().toString(), UUID.randomUUID().toString());
77+
file.deleteOnExit();
6878

69-
// when
70-
CategoryPublisher publisher = CategoryPublisher.builder()
71-
.p2ApplicationLauncher(launcher)
72-
.categoryFileLocation(file.getPath())
73-
.additionalArgs("-args")
74-
.metadataRepositoryLocation("target/tmp")
75-
.build();
76-
publisher.execute();
79+
// when
80+
CategoryPublisher publisher = CategoryPublisher.builder()
81+
.p2ApplicationLauncher(launcher)
82+
.categoryFileLocation(file.getPath())
83+
.additionalArgs("-args")
84+
.metadataRepositoryLocation("target/tmp")
85+
.build();
86+
publisher.execute();
87+
});
7788
}
7889

7990
}

src/test/java/org/reficio/p2/resolver/impl/AetherTest.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@
1818
*/
1919
package org.reficio.p2.resolver.impl;
2020

21-
import org.hamcrest.core.IsInstanceOf;
22-
import org.junit.Test;
21+
import org.junit.jupiter.api.Test;
2322
import org.reficio.p2.resolver.maven.impl.Aether;
2423
import org.reficio.p2.resolver.maven.impl.facade.AetherEclipseFacade;
2524
import org.reficio.p2.resolver.maven.impl.facade.AetherFacade;
2625
import org.reficio.p2.resolver.maven.impl.facade.AetherSonatypeFacade;
2726

2827
import static org.assertj.core.api.Assertions.assertThat;
29-
import static org.junit.Assert.assertTrue;
3028
import static org.mockito.Mockito.mock;
3129

3230
/**
@@ -35,10 +33,10 @@
3533
* http://www.reficio.org
3634
* @since 1.1.0
3735
*/
38-
public class AetherTest {
36+
class AetherTest {
3937

4038
@Test
41-
public void facade_sonatypeAetherSystem() {
39+
void facade_sonatypeAetherSystem() {
4240
// GIVEN
4341
Object repositorySystem = mock(org.sonatype.aether.RepositorySystem.class);
4442

@@ -50,7 +48,7 @@ public void facade_sonatypeAetherSystem() {
5048
}
5149

5250
@Test
53-
public void facade_eclipseAetherSystem() {
51+
void facade_eclipseAetherSystem() {
5452
// GIVEN
5553
Object repositorySystem = mock(org.eclipse.aether.RepositorySystem.class);
5654

0 commit comments

Comments
 (0)