Skip to content

Commit 33586a4

Browse files
committed
Partial port to JUnit 5
1 parent 60d1c48 commit 33586a4

8 files changed

Lines changed: 47 additions & 104 deletions

File tree

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@
171171
<version>${maven.dependency.version}</version>
172172
<scope>test</scope>
173173
</dependency>
174+
<dependency>
175+
<groupId>org.junit.jupiter</groupId>
176+
<artifactId>junit-jupiter</artifactId>
177+
<scope>test</scope>
178+
</dependency>
174179
<dependency>
175180
<groupId>org.junit.vintage</groupId>
176181
<artifactId>junit-vintage-engine</artifactId>

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<action type="fix" dev="ggregory" due-to="Gary Gregory">Fix Apache RAT plugin console warnings.</action>
3030
<action type="fix" dev="ggregory" due-to="Gary Gregory">Make some classes final.</action>
3131
<action type="fix" dev="ggregory" due-to="Gary Gregory">Fix missing version for org.codehaus.mojo:jdepend-maven-plugin: 2.1.</action>
32+
<action type="fix" dev="ggregory" due-to="Gary Gregory">Partial port to JUnit 5.</action>
3233
<action type="fix" dev="ggregory" due-to="Gary Gregory">Bump org.apache.maven:maven-artifact from 3.9.11 to 3.9.12.</action>
3334
<action type="fix" dev="ggregory" due-to="Gary Gregory">Bump org.apache.maven:maven-compat from 3.9.11 to 3.9.12.</action>
3435
<action type="fix" dev="ggregory" due-to="Gary Gregory">Bump org.apache.maven:maven-core from 3.9.11 to 3.9.12.</action>

src/main/java/org/apache/commons/release/plugin/mojos/CommonsSiteCompressionMojo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
* <code>./target/commons-release-plugin/site.zip</code>.
4141
*
4242
* @since 1.0
43-
* @deprecated - as we no longer wish to compress the site, we are going to put this functionality in the
43+
* @deprecated As we no longer wish to compress the site, we are going to put this functionality in the
4444
* {@link CommonsDistributionStagingMojo}.
4545
*/
4646
@Deprecated

src/test/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetachmentMojoTest.java

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,24 @@
1818

1919
import static junit.framework.TestCase.assertTrue;
2020
import static org.junit.Assert.assertFalse;
21-
import static org.junit.Assert.assertNotNull;
2221

2322
import java.io.File;
2423

25-
import org.apache.maven.plugin.testing.MojoRule;
24+
import org.apache.maven.api.plugin.testing.InjectMojo;
25+
import org.apache.maven.api.plugin.testing.MojoTest;
2626
import org.codehaus.plexus.util.FileUtils;
27-
import org.junit.Before;
28-
import org.junit.Rule;
29-
import org.junit.Test;
27+
import org.junit.jupiter.api.BeforeEach;
28+
import org.junit.jupiter.api.Test;
3029

3130
/**
3231
* Unit tests for {@link CommonsDistributionDetachmentMojo}.
3332
*/
33+
@MojoTest
3434
public class CommonsDistributionDetachmentMojoTest {
3535

3636
private static final String COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH = "target/testing-commons-release-plugin";
3737

38-
@Rule
39-
public final MojoRule rule = new MojoRule() {
40-
@Override
41-
protected void after() {
42-
// noop
43-
}
44-
45-
@Override
46-
protected void before() throws Throwable {
47-
// noop
48-
}
49-
};
50-
51-
private CommonsDistributionDetachmentMojo mojo;
52-
53-
@Before
38+
@BeforeEach
5439
public void setUp() throws Exception {
5540
final File testingDirectory = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH);
5641
if (testingDirectory.exists()) {
@@ -59,22 +44,16 @@ public void setUp() throws Exception {
5944
}
6045

6146
@Test
62-
public void testDisabled() throws Exception {
63-
final File testPom = new File("src/test/resources/mojos/detach-distributions/detach-distributions-disabled.xml");
64-
assertNotNull(testPom);
65-
assertTrue(testPom.exists());
66-
mojo = (CommonsDistributionDetachmentMojo) rule.lookupMojo("detach-distributions", testPom);
47+
@InjectMojo(goal = "detach-distributions", pom = "src/test/resources/mojos/detach-distributions/detach-distributions-disabled.xml")
48+
public void testDisabled(final CommonsDistributionDetachmentMojo mojo) throws Exception {
6749
mojo.execute();
6850
final File testingDirectory = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH);
6951
assertFalse(testingDirectory.exists());
7052
}
7153

7254
@Test
73-
public void testSuccess() throws Exception {
74-
final File testPom = new File("src/test/resources/mojos/detach-distributions/detach-distributions.xml");
75-
assertNotNull(testPom);
76-
assertTrue(testPom.exists());
77-
mojo = (CommonsDistributionDetachmentMojo) rule.lookupMojo("detach-distributions", testPom);
55+
@InjectMojo(goal = "detach-distributions", pom = "src/test/resources/mojos/detach-distributions/detach-distributions.xml")
56+
public void testSuccess(final CommonsDistributionDetachmentMojo mojo) throws Exception {
7857
mojo.execute();
7958
final File detachedSrcTarGz = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/commons-text-1.4-src.tar.gz");
8059
final File detachedSrcTarGzAsc = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/commons-text-1.4-src.tar.gz.asc");

src/test/java/org/apache/commons/release/plugin/mojos/CommonsSiteCompressionMojoTest.java

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,41 +19,26 @@
1919
import static junit.framework.TestCase.assertTrue;
2020
import static org.junit.Assert.assertEquals;
2121
import static org.junit.Assert.assertFalse;
22-
import static org.junit.Assert.assertNotNull;
2322

2423
import java.io.File;
2524

25+
import org.apache.maven.api.plugin.testing.InjectMojo;
26+
import org.apache.maven.api.plugin.testing.MojoTest;
2627
import org.apache.maven.plugin.MojoFailureException;
27-
import org.apache.maven.plugin.testing.MojoRule;
2828
import org.codehaus.plexus.util.FileUtils;
29-
import org.junit.Before;
30-
import org.junit.Rule;
31-
import org.junit.Test;
29+
import org.junit.jupiter.api.BeforeEach;
30+
import org.junit.jupiter.api.Test;
3231

3332
/**
3433
* Unit tests for {@link CommonsSiteCompressionMojo}.
3534
*/
3635
@SuppressWarnings("deprecation") // testing a deprecated class
36+
@MojoTest
3737
public class CommonsSiteCompressionMojoTest {
3838

3939
private static final String COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH = "target/testing-commons-release-plugin";
4040

41-
@Rule
42-
public final MojoRule rule = new MojoRule() {
43-
@Override
44-
protected void after() {
45-
// noop
46-
}
47-
48-
@Override
49-
protected void before() throws Throwable {
50-
// noop
51-
}
52-
};
53-
54-
protected CommonsSiteCompressionMojo mojo;
55-
56-
@Before
41+
@BeforeEach
5742
public void setUp() throws Exception {
5843
final File testingDirectory = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH);
5944
if (testingDirectory.exists()) {
@@ -62,11 +47,8 @@ public void setUp() throws Exception {
6247
}
6348

6449
@Test
65-
public void testCompressSiteDirNonExistentFailure() throws Exception {
66-
final File testPom = new File("src/test/resources/mojos/compress-site/compress-site-failure.xml");
67-
assertNotNull(testPom);
68-
assertTrue(testPom.exists());
69-
mojo = (CommonsSiteCompressionMojo) rule.lookupMojo("compress-site", testPom);
50+
@InjectMojo(goal = "compress-site", pom = "src/test/resources/mojos/compress-site/compress-site-failure.xml")
51+
public void testCompressSiteDirNonExistentFailure(final CommonsSiteCompressionMojo mojo) throws Exception {
7052
try {
7153
mojo.execute();
7254
} catch (final MojoFailureException e) {
@@ -77,24 +59,18 @@ public void testCompressSiteDirNonExistentFailure() throws Exception {
7759
}
7860

7961
@Test
80-
public void testCompressSiteSuccess() throws Exception {
62+
@InjectMojo(goal = "compress-site", pom = "src/test/resources/mojos/compress-site/compress-site.xml")
63+
public void testCompressSiteSuccess(final CommonsSiteCompressionMojo mojo) throws Exception {
8164
final File testingDirectory = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH);
8265
testingDirectory.mkdir();
83-
final File testPom = new File("src/test/resources/mojos/compress-site/compress-site.xml");
84-
assertNotNull(testPom);
85-
assertTrue(testPom.exists());
86-
mojo = (CommonsSiteCompressionMojo) rule.lookupMojo("compress-site", testPom);
8766
mojo.execute();
8867
final File siteZip = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/site.zip");
8968
assertTrue(siteZip.exists());
9069
}
9170

9271
@Test
93-
public void testDisabled() throws Exception {
94-
final File testPom = new File("src/test/resources/mojos/compress-site/compress-site-disabled.xml");
95-
assertNotNull(testPom);
96-
assertTrue(testPom.exists());
97-
mojo = (CommonsSiteCompressionMojo) rule.lookupMojo("compress-site", testPom);
72+
@InjectMojo(goal = "compress-site", pom = "src/test/resources/mojos/compress-site/compress-site-disabled.xml")
73+
public void testDisabled(final CommonsSiteCompressionMojo mojo) throws Exception {
9874
mojo.execute();
9975
final File testingDirectory = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH);
10076
assertFalse(testingDirectory.exists());

src/test/java/org/apache/commons/release/plugin/mojos/CommonsStagingCleanupMojoTest.java

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,24 @@
1717
package org.apache.commons.release.plugin.mojos;
1818

1919
import static junit.framework.TestCase.assertTrue;
20-
import static org.junit.Assert.assertNotNull;
2120

2221
import java.io.File;
2322

24-
import org.apache.maven.plugin.testing.MojoRule;
23+
import org.apache.maven.api.plugin.testing.InjectMojo;
24+
import org.apache.maven.api.plugin.testing.MojoTest;
2525
import org.codehaus.plexus.util.FileUtils;
26-
import org.junit.Before;
27-
import org.junit.Rule;
28-
import org.junit.Test;
26+
import org.junit.jupiter.api.BeforeEach;
27+
import org.junit.jupiter.api.Test;
2928

3029
/**
3130
* Unit tests for {@link CommonsSiteCompressionMojo}.
3231
*/
32+
@MojoTest
3333
public class CommonsStagingCleanupMojoTest {
3434

3535
private static final String COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH = "target/testing-commons-release-plugin";
3636

37-
@Rule
38-
public final MojoRule rule = new MojoRule() {
39-
@Override
40-
protected void after() {
41-
// noop
42-
}
43-
44-
@Override
45-
protected void before() throws Throwable {
46-
// noop
47-
}
48-
};
49-
50-
protected CommonsStagingCleanupMojo mojo;
51-
52-
@Before
37+
@BeforeEach
5338
public void setUp() throws Exception {
5439
final File testingDirectory = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH);
5540
if (testingDirectory.exists()) {
@@ -58,13 +43,10 @@ public void setUp() throws Exception {
5843
}
5944

6045
@Test
61-
public void testCompressSiteSuccess() throws Exception {
46+
@InjectMojo(goal = "clean-staging", pom = "src/test/resources/mojos/staging-cleanup/staging-cleanup.xml")
47+
public void testCompressSiteSuccess(final CommonsStagingCleanupMojo mojo) throws Exception {
6248
final File testingDirectory = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH);
6349
testingDirectory.mkdir();
64-
final File testPom = new File("src/test/resources/mojos/staging-cleanup/staging-cleanup.xml");
65-
assertNotNull(testPom);
66-
assertTrue(testPom.exists());
67-
mojo = (CommonsStagingCleanupMojo) rule.lookupMojo("clean-staging", testPom);
6850
mojo.execute();
6951
final File cleanupDir = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm-cleanup");
7052
assertTrue(cleanupDir.exists());

src/test/java/org/apache/commons/release/plugin/velocity/HeaderHtmlVelocityDelegateTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@
1616
*/
1717
package org.apache.commons.release.plugin.velocity;
1818

19-
import static junit.framework.TestCase.assertTrue;
19+
import static org.junit.jupiter.api.Assertions.assertTrue;
2020

2121
import java.io.IOException;
2222
import java.io.StringWriter;
2323
import java.io.Writer;
2424

25-
import org.junit.Test;
25+
import org.junit.jupiter.api.Test;
2626

2727
/**
2828
* Unit tests for {@link HeaderHtmlVelocityDelegate}.
2929
*/
30-
public class HeaderHtmlVelocityDelegateTest {
30+
class HeaderHtmlVelocityDelegateTest {
3131

3232
@Test
33-
public void testSuccess() throws IOException {
33+
void testSuccess() throws IOException {
3434
final HeaderHtmlVelocityDelegate subject = HeaderHtmlVelocityDelegate.builder().build();
3535
try (Writer writer = subject.render(new StringWriter())) {
3636
assertTrue(writer.toString().contains("<h2>Apache Commons Project Distributions</h2>"));

src/test/java/org/apache/commons/release/plugin/velocity/ReadmeHtmlVelocityDelegateTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@
1616
*/
1717
package org.apache.commons.release.plugin.velocity;
1818

19-
import static junit.framework.TestCase.assertTrue;
19+
import static org.junit.jupiter.api.Assertions.assertTrue;
2020

2121
import java.io.IOException;
2222
import java.io.StringWriter;
2323
import java.io.Writer;
2424

25-
import org.junit.Test;
25+
import org.junit.jupiter.api.Test;
2626

2727
/**
2828
* Unit tests for {@link ReadmeHtmlVelocityDelegate}.
2929
*/
30-
public final class ReadmeHtmlVelocityDelegateTest {
30+
final class ReadmeHtmlVelocityDelegateTest {
3131

3232
@Test
33-
public void testSuccessfulRun() throws IOException {
33+
void testSuccessfulRun() throws IOException {
3434
final ReadmeHtmlVelocityDelegate delegate = ReadmeHtmlVelocityDelegate.builder()
3535
.withArtifactId("commons-text")
3636
.withVersion("1.4")
@@ -43,7 +43,7 @@ public void testSuccessfulRun() throws IOException {
4343
}
4444

4545
@Test
46-
public void testSuccessfulRunBcel() throws IOException {
46+
void testSuccessfulRunBcel() throws IOException {
4747
final ReadmeHtmlVelocityDelegate delegate = ReadmeHtmlVelocityDelegate.builder()
4848
.withArtifactId("bcel")
4949
.withVersion("1.5")
@@ -56,7 +56,7 @@ public void testSuccessfulRunBcel() throws IOException {
5656
}
5757

5858
@Test
59-
public void testSuccessfulRunLang3() throws IOException {
59+
void testSuccessfulRunLang3() throws IOException {
6060
final ReadmeHtmlVelocityDelegate delegate = ReadmeHtmlVelocityDelegate.builder()
6161
.withArtifactId("commons-lang3")
6262
.withVersion("3.8.1")

0 commit comments

Comments
 (0)