Skip to content

Commit b14073c

Browse files
authored
chore: migrate junit 3/4 to junit 5 tests (#611)
* chore: migrate junit 3/4 to junit 5 tests AbstractMojoTestCase based tests will be migrate in a separate PR Signed-off-by: Sandra Parsick <[email protected]> * chore: rename tests to follow the junit 5 test name pattern Signed-off-by: Sandra Parsick <[email protected]> --------- Signed-off-by: Sandra Parsick <[email protected]>
1 parent b1bb2e9 commit b14073c

19 files changed

+168
-81
lines changed

pom.xml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ under the License.
242242
<groupId>xml-apis</groupId>
243243
<artifactId>xml-apis</artifactId>
244244
</exclusion>
245+
<exclusion>
246+
<groupId>junit</groupId>
247+
<artifactId>junit</artifactId>
248+
</exclusion>
245249
</exclusions>
246250
</dependency>
247251
<dependency>
@@ -318,14 +322,6 @@ under the License.
318322
<artifactId>rome</artifactId>
319323
<version>2.1.0</version>
320324
</dependency>
321-
322-
<!-- test dependencies -->
323-
<dependency>
324-
<groupId>junit</groupId>
325-
<artifactId>junit</artifactId>
326-
<version>4.13.2</version>
327-
<scope>test</scope>
328-
</dependency>
329325
<dependency>
330326
<groupId>org.mockito</groupId>
331327
<artifactId>mockito-core</artifactId>
@@ -356,6 +352,16 @@ under the License.
356352
<version>${mavenResolverVersion}</version>
357353
<scope>test</scope>
358354
</dependency>
355+
<dependency>
356+
<groupId>org.junit.jupiter</groupId>
357+
<artifactId>junit-jupiter-api</artifactId>
358+
<scope>test</scope>
359+
</dependency>
360+
<dependency>
361+
<groupId>org.junit.vintage</groupId>
362+
<artifactId>junit-vintage-engine</artifactId>
363+
<scope>test</scope>
364+
</dependency>
359365
</dependencies>
360366

361367
<build>
@@ -458,6 +464,8 @@ under the License.
458464
<!-- These next two should be removed. See https://issues.apache.org/jira/browse/MCHANGES-463 -->
459465
<ignoredUnusedDeclaredDependency>org.codehaus.plexus:plexus-mail-sender-javamail</ignoredUnusedDeclaredDependency>
460466
<ignoredUnusedDeclaredDependency>org.codehaus.plexus:plexus-mail-sender-simple</ignoredUnusedDeclaredDependency>
467+
<!-- junit vintage is needed for the tests that are based on AbstractMojoTestCase-->
468+
<ignoredUnusedDeclaredDependency>org.junit.vintage:junit-vintage-engine</ignoredUnusedDeclaredDependency>
461469
</ignoredUnusedDeclaredDependencies>
462470
</configuration>
463471
</execution>

src/test/java/org/apache/maven/plugins/changes/ActionTest.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,52 +18,50 @@
1818
*/
1919
package org.apache.maven.plugins.changes;
2020

21-
import junit.framework.Test;
22-
import junit.framework.TestCase;
23-
import junit.framework.TestSuite;
2421
import org.apache.maven.plugins.changes.model.Action;
22+
import org.junit.jupiter.api.Test;
2523

26-
public class ActionTest extends TestCase {
27-
Action action = new Action();
28-
29-
public ActionTest(String testName) {
30-
super(testName);
31-
}
24+
import static org.junit.jupiter.api.Assertions.assertEquals;
3225

33-
public static Test suite() {
34-
return new TestSuite(ActionTest.class);
35-
}
26+
public class ActionTest {
27+
Action action = new Action();
3628

29+
@Test
3730
public void testGetSetAction() {
3831
action.setAction("action");
3932

4033
assertEquals("action", action.getAction());
4134
}
4235

36+
@Test
4337
public void testGetSetDev() {
4438
action.setDev("developer");
4539

4640
assertEquals("developer", action.getDev());
4741
}
4842

43+
@Test
4944
public void testGetSetType() {
5045
action.setType("type");
5146

5247
assertEquals("type", action.getType());
5348
}
5449

50+
@Test
5551
public void testGetSetIssue() {
5652
action.setIssue("issue");
5753

5854
assertEquals("issue", action.getIssue());
5955
}
6056

57+
@Test
6158
public void testGetSetDueTo() {
6259
action.setDueTo("due-to");
6360

6461
assertEquals("due-to", action.getDueTo());
6562
}
6663

64+
@Test
6765
public void testGetSetDueToEmail() {
6866
action.setDueToEmail("due-to-mail");
6967

src/test/java/org/apache/maven/plugins/changes/ChangesCheckMojoTestCase.java renamed to src/test/java/org/apache/maven/plugins/changes/ChangesCheckMojoTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@
1818
*/
1919
package org.apache.maven.plugins.changes;
2020

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

23-
import static org.junit.Assert.assertFalse;
24-
import static org.junit.Assert.assertTrue;
25-
import static org.junit.Assume.assumeTrue;
23+
import static org.junit.jupiter.api.Assertions.assertFalse;
24+
import static org.junit.jupiter.api.Assertions.assertTrue;
25+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
2626

2727
/**
2828
* @author Dennis Lundberg
2929
* @version $Id$
3030
* @since 2.4
3131
*/
32-
public class ChangesCheckMojoTestCase {
32+
public class ChangesCheckMojoTest {
3333
@Test
3434
public void testIsValidDate() {
3535
String pattern;

src/test/java/org/apache/maven/plugins/changes/ChangesValidatorMojoTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222

2323
import org.apache.maven.plugin.MojoExecutionException;
2424
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
25+
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.Test;
27+
28+
import static org.junit.jupiter.api.Assertions.fail;
2529

2630
/**
2731
* @author Olivier Lamy
@@ -32,12 +36,14 @@ public class ChangesValidatorMojoTest extends AbstractMojoTestCase {
3236

3337
protected ChangesValidatorMojo mojo;
3438

39+
@BeforeEach
3540
public void setUp() throws Exception {
3641
super.setUp();
3742
File pom = new File(getBasedir(), "/src/test/unit/plugin-config.xml");
3843
mojo = lookupMojo("changes-validate", pom);
3944
}
4045

46+
@Test
4147
public void testValidationSuccess() throws Exception {
4248
File changesXml = new File(getBasedir(), "/src/test/unit/changes.xml");
4349
setVariableValueToObject(mojo, "xmlPath", changesXml);
@@ -46,6 +52,7 @@ public void testValidationSuccess() throws Exception {
4652
mojo.execute();
4753
}
4854

55+
@Test
4956
public void testValidationFailedWithMojoFailure() throws Exception {
5057
File changesXml = new File(getBasedir(), "/src/test/unit/non-valid-changes.xml");
5158
setVariableValueToObject(mojo, "xmlPath", changesXml);
@@ -59,6 +66,7 @@ public void testValidationFailedWithMojoFailure() throws Exception {
5966
}
6067
}
6168

69+
@Test
6270
public void testValidationFailedWithNoMojoFailure() throws Exception {
6371
File changesXml = new File(getBasedir(), "/src/test/unit/non-valid-changes.xml");
6472
setVariableValueToObject(mojo, "xmlPath", changesXml);

src/test/java/org/apache/maven/plugins/changes/ChangesXMLTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
import org.apache.maven.plugin.testing.SilentLog;
2525
import org.apache.maven.plugins.changes.model.Action;
2626
import org.apache.maven.plugins.changes.model.Release;
27-
import org.junit.Test;
27+
import org.junit.jupiter.api.Test;
2828

29-
import static org.junit.Assert.assertEquals;
30-
import static org.junit.Assert.assertNotNull;
31-
import static org.junit.Assert.fail;
29+
import static org.junit.jupiter.api.Assertions.assertEquals;
30+
import static org.junit.jupiter.api.Assertions.assertNotNull;
31+
import static org.junit.jupiter.api.Assertions.fail;
3232

3333
/**
3434
* @author Olivier Lamy

src/test/java/org/apache/maven/plugins/changes/FeedGeneratorTest.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,35 @@
2525
import java.util.List;
2626
import java.util.Locale;
2727

28-
import junit.framework.TestCase;
2928
import org.apache.maven.plugins.changes.model.Release;
29+
import org.junit.jupiter.api.Test;
30+
31+
import static org.junit.jupiter.api.Assertions.assertFalse;
32+
import static org.junit.jupiter.api.Assertions.assertNotNull;
33+
import static org.junit.jupiter.api.Assertions.assertTrue;
34+
import static org.junit.jupiter.api.Assertions.fail;
3035

3136
/**
3237
* @author ltheussl
3338
*/
34-
public class FeedGeneratorTest extends TestCase {
39+
public class FeedGeneratorTest {
3540
/**
3641
* Test of isSupportedFeedType method, of class FeedGenerator.
3742
*/
43+
@Test
3844
public void testIsSupportedFeedType() {
3945
final FeedGenerator generator = new FeedGenerator(Locale.ENGLISH);
4046

41-
assertTrue("rss_0.9 not supported?", generator.isSupportedFeedType("rss_0.9"));
42-
assertTrue("rss_0.91N not supported?", generator.isSupportedFeedType("rss_0.91N"));
43-
assertTrue("rss_0.91U not supported?", generator.isSupportedFeedType("rss_0.91U"));
44-
assertTrue("rss_0.92 not supported?", generator.isSupportedFeedType("rss_0.92"));
45-
assertTrue("rss_0.93 not supported?", generator.isSupportedFeedType("rss_0.93"));
46-
assertTrue("rss_0.94 not supported?", generator.isSupportedFeedType("rss_0.94"));
47-
assertTrue("rss_1.0 not supported?", generator.isSupportedFeedType("rss_1.0"));
48-
assertTrue("rss_2.0 not supported?", generator.isSupportedFeedType("rss_2.0"));
49-
assertTrue("atom_0.3 not supported?", generator.isSupportedFeedType("atom_0.3"));
50-
assertTrue("atom_1.0 not supported?", generator.isSupportedFeedType("atom_1.0"));
47+
assertTrue(generator.isSupportedFeedType("rss_0.9"), "rss_0.9 not supported?");
48+
assertTrue(generator.isSupportedFeedType("rss_0.91N"), "rss_0.91N not supported?");
49+
assertTrue(generator.isSupportedFeedType("rss_0.91U"), "rss_0.91U not supported?");
50+
assertTrue(generator.isSupportedFeedType("rss_0.92"), "rss_0.92 not supported?");
51+
assertTrue(generator.isSupportedFeedType("rss_0.93"), "rss_0.93 not supported?");
52+
assertTrue(generator.isSupportedFeedType("rss_0.94"), "rss_0.94 not supported?");
53+
assertTrue(generator.isSupportedFeedType("rss_1.0"), "rss_1.0 not supported?");
54+
assertTrue(generator.isSupportedFeedType("rss_2.0"), "rss_2.0 not supported?");
55+
assertTrue(generator.isSupportedFeedType("atom_0.3"), "atom_0.3 not supported?");
56+
assertTrue(generator.isSupportedFeedType("atom_1.0"), "atom_1.0 not supported?");
5157

5258
assertFalse(generator.isSupportedFeedType(""));
5359
assertFalse(generator.isSupportedFeedType(null));
@@ -59,6 +65,7 @@ public void testIsSupportedFeedType() {
5965
*
6066
* @throws Exception if any.
6167
*/
68+
@Test
6269
public void testExport() throws Exception {
6370
final FeedGenerator generator = new FeedGenerator(Locale.ENGLISH);
6471
generator.setAuthor("author");

src/test/java/org/apache/maven/plugins/changes/IssueAdapterTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,23 @@
2121
import java.util.Arrays;
2222
import java.util.List;
2323

24-
import junit.framework.TestCase;
2524
import org.apache.maven.plugins.changes.issues.Issue;
2625
import org.apache.maven.plugins.changes.issues.IssueManagementSystem;
2726
import org.apache.maven.plugins.changes.jira.JIRAIssueManagementSystem;
2827
import org.apache.maven.plugins.changes.model.Action;
2928
import org.apache.maven.plugins.changes.model.Release;
29+
import org.junit.jupiter.api.Test;
30+
31+
import static org.junit.jupiter.api.Assertions.assertEquals;
3032

3133
/**
3234
* @author Alan Parkinson
3335
* @version $Id$
3436
* @since 2.6
3537
*/
36-
public class IssueAdapterTest extends TestCase {
38+
public class IssueAdapterTest {
3739

40+
@Test
3841
public void testDefaultIssueTypeMapping() {
3942
IssueAdapter adapter = new IssueAdapter(new JIRAIssueManagementSystem());
4043

@@ -67,6 +70,7 @@ public void testDefaultIssueTypeMapping() {
6770
assertEquals("", action.getType());
6871
}
6972

73+
@Test
7074
public void testCustomIssueTypeMappingOveridesDefaultMapping() {
7175
IssueManagementSystem ims = new JIRAIssueManagementSystem();
7276

@@ -90,6 +94,7 @@ public void testCustomIssueTypeMappingOveridesDefaultMapping() {
9094
assertEquals("", action.getType());
9195
}
9296

97+
@Test
9398
public void testCustomIssueTypeMapping() {
9499
IssueManagementSystem ims = new JIRAIssueManagementSystem();
95100
ims.getIssueTypeMap().put("Story", IssueType.ADD);
@@ -137,6 +142,7 @@ private Issue createIssue(String key, String type, String version) {
137142
return issue;
138143
}
139144

145+
@Test
140146
public void testReleaseOrder() {
141147
IssueManagementSystem ims = new JIRAIssueManagementSystem();
142148
ims.getIssueTypeMap().put("Story", IssueType.ADD);

src/test/java/org/apache/maven/plugins/changes/ReleaseTest.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,30 @@
2121
import java.util.ArrayList;
2222
import java.util.List;
2323

24-
import junit.framework.Test;
25-
import junit.framework.TestCase;
26-
import junit.framework.TestSuite;
2724
import org.apache.maven.plugins.changes.model.Action;
2825
import org.apache.maven.plugins.changes.model.Release;
26+
import org.junit.jupiter.api.Test;
2927

30-
public class ReleaseTest extends TestCase {
31-
Release release = new Release();
32-
33-
public ReleaseTest(String testName) {
34-
super(testName);
35-
}
28+
import static org.junit.jupiter.api.Assertions.assertEquals;
3629

37-
public static Test suite() {
38-
return new TestSuite(ReleaseTest.class);
39-
}
30+
public class ReleaseTest {
31+
Release release = new Release();
4032

33+
@Test
4134
public void testGetSetVersion() {
4235
release.setVersion("version");
4336

4437
assertEquals("version", release.getVersion());
4538
}
4639

40+
@Test
4741
public void testGetSetDateRelease() {
4842
release.setDateRelease("12-09-1979");
4943

5044
assertEquals("12-09-1979", release.getDateRelease());
5145
}
5246

47+
@Test
5348
public void testGetSetAction() {
5449
List<Action> actionList = new ArrayList<>();
5550

0 commit comments

Comments
 (0)