Skip to content

Commit 1658acc

Browse files
committed
Port to JUnit 5 and maven-plugin-testing-harness 3.4.1
Don't use deprecated Maven code
1 parent 33586a4 commit 1658acc

2 files changed

Lines changed: 27 additions & 39 deletions

File tree

pom.xml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162
<dependency>
163163
<groupId>org.apache.maven.plugin-testing</groupId>
164164
<artifactId>maven-plugin-testing-harness</artifactId>
165-
<version>3.4.0</version>
165+
<version>3.4.1-SNAPSHOT</version>
166166
<scope>test</scope>
167167
</dependency>
168168
<dependency>
@@ -536,7 +536,6 @@
536536
</plugin>
537537
</plugins>
538538
</reporting>
539-
540539
<profiles>
541540
<profile>
542541
<id>setup-checkout</id>
@@ -680,6 +679,18 @@
680679
</properties>
681680
</profile>
682681
</profiles>
682+
<pluginRepositories>
683+
<pluginRepository>
684+
<id>apache.snapshots</id>
685+
<url>https://repository.apache.org/snapshots/</url>
686+
<snapshots>
687+
<enabled>true</enabled>
688+
</snapshots>
689+
<releases>
690+
<enabled>false</enabled>
691+
</releases>
692+
</pluginRepository>
693+
</pluginRepositories>
683694
<developers>
684695
<developer>
685696
<name>Rob Tompkins</name>

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

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,44 +14,28 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17+
1718
package org.apache.commons.release.plugin.mojos;
1819

1920
import static junit.framework.TestCase.assertTrue;
2021
import static org.junit.Assert.assertFalse;
21-
import static org.junit.Assert.assertNotNull;
2222

2323
import java.io.File;
2424

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

3131
/**
3232
* Unit tests for {@link CommonsDistributionStagingMojo}.
3333
*/
34+
@MojoTest
3435
public class CommonsDistributionStagingMojoTest {
3536

3637
private static final String COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH = "target/testing-commons-release-plugin";
3738

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 detachmentMojo;
52-
53-
private CommonsDistributionStagingMojo mojoForTest;
54-
5539
private void assertRequisiteFilesExist() {
5640
final File targetScmDirectory = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1");
5741
final File releaseNotes = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/RELEASE-NOTES.txt");
@@ -105,7 +89,7 @@ private void assertRequisiteFilesExist() {
10589
assertTrue(siteSubdirectoryIndexHtml.exists());
10690
}
10791

108-
@Before
92+
@BeforeEach
10993
public void setUp() throws Exception {
11094
final File testingDirectory = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH);
11195
if (testingDirectory.exists()) {
@@ -114,26 +98,19 @@ public void setUp() throws Exception {
11498
}
11599

116100
@Test
117-
public void testDisabled() throws Exception {
118-
final File testPom = new File("src/test/resources/mojos/stage-distributions/stage-distributions-disabled.xml");
119-
assertNotNull(testPom);
120-
assertTrue(testPom.exists());
121-
mojoForTest = (CommonsDistributionStagingMojo) rule.lookupMojo("stage-distributions", testPom);
101+
public void testDisabled(
102+
@InjectMojo(goal = "stage-distributions", pom = "src/test/resources/mojos/stage-distributions/stage-distributions-disabled.xml") final CommonsDistributionStagingMojo mojoForTest)
103+
throws Exception {
122104
mojoForTest.execute();
123105
final File testingDirectory = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH);
124106
assertFalse(testingDirectory.exists());
125107
}
126108

127109
@Test
128-
public void testSuccess() throws Exception {
129-
final File testPom = new File("src/test/resources/mojos/stage-distributions/stage-distributions.xml");
130-
assertNotNull(testPom);
131-
assertTrue(testPom.exists());
132-
final File detachmentPom = new File("src/test/resources/mojos/detach-distributions/detach-distributions.xml");
133-
assertNotNull(detachmentPom);
134-
assertTrue(detachmentPom.exists());
135-
mojoForTest = (CommonsDistributionStagingMojo) rule.lookupMojo("stage-distributions", testPom);
136-
detachmentMojo = (CommonsDistributionDetachmentMojo) rule.lookupMojo("detach-distributions", detachmentPom);
110+
public void testSuccess(
111+
@InjectMojo(goal = "stage-distributions", pom = "src/test/resources/mojos/stage-distributions/stage-distributions.xml") final CommonsDistributionStagingMojo mojoForTest,
112+
@InjectMojo(goal = "detach-distributions", pom = "src/test/resources/mojos/detach-distributions/detach-distributions.xml") final CommonsDistributionDetachmentMojo detachmentMojo)
113+
throws Exception {
137114
detachmentMojo.execute();
138115
final File releaseNotesBasedir = new File("src/test/resources/mojos/stage-distributions/");
139116
mojoForTest.setBaseDir(releaseNotesBasedir);

0 commit comments

Comments
 (0)