Skip to content

Commit 8c20747

Browse files
authored
chore: migrate junit3 to junit5 (#562)
- it has indirect dep to PlexusTestCase via AbstractMojoTestCase (will be done in a separate PR)
1 parent a786231 commit 8c20747

File tree

4 files changed

+77
-122
lines changed

4 files changed

+77
-122
lines changed

src/it/MWAR-131/mwar131-test/pom.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ under the License.
3434
<version>1.0-SNAPSHOT</version>
3535
<url>http://maven.apache.org</url>
3636
<dependencies>
37-
<dependency>
38-
<groupId>junit</groupId>
39-
<artifactId>junit</artifactId>
40-
<version>3.8.1</version>
41-
<scope>test</scope>
42-
</dependency>
37+
<dependency>
38+
<groupId>org.junit.jupiter</groupId>
39+
<artifactId>junit-jupiter-api</artifactId>
40+
<version>5.14.0</version>
41+
<scope>test</scope>
42+
</dependency>
4343
<dependency>
4444
<groupId>com.example</groupId>
4545
<artifactId>mwar131-webapp</artifactId>

src/it/MWAR-131/mwar131-test/src/test/java/com/example/AppTest.java

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,44 +19,17 @@
1919
* under the License.
2020
*/
2121

22-
import junit.framework.Test;
23-
import junit.framework.TestCase;
24-
import junit.framework.TestSuite;
25-
22+
import org.junit.jupiter.api.Test;
23+
import static org.junit.jupiter.api.Assertions.assertTrue;
2624
/**
2725
* Unit test for simple App.
2826
*/
29-
public class AppTest
30-
extends TestCase
31-
{
32-
/**
33-
* Create the test case
34-
*
35-
* @param testName name of the test case
36-
*/
37-
public AppTest( String testName )
38-
{
39-
super( testName );
40-
}
41-
42-
/**
43-
* @return the suite of tests being tested
44-
*/
45-
public static Test suite()
46-
{
47-
return new TestSuite( AppTest.class );
48-
}
49-
27+
public class AppTest {
5028
/**
5129
* Rigourous Test :-)
5230
*/
53-
public void testApp()
54-
{
55-
assertTrue( true );
56-
}
57-
58-
public void testUtil()
59-
{
60-
assertTrue( Util.isPresent() );
31+
@Test
32+
public void testApp() {
33+
assertTrue(true);
6134
}
6235
}

src/test/java/org/apache/maven/plugins/war/util/PathSetTest.java

Lines changed: 52 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,42 @@
2424
import java.util.Iterator;
2525
import java.util.Set;
2626

27-
import junit.framework.TestCase;
2827
import org.codehaus.plexus.util.StringUtils;
28+
import org.junit.jupiter.api.Test;
2929

30-
public class PathSetTest extends TestCase {
30+
import static org.junit.jupiter.api.Assertions.assertEquals;
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+
35+
public class PathSetTest {
3136

3237
/* --------------- Normalization tests --------------*/
3338

3439
/**
3540
* Test method for 'org.apache.maven.plugin.war.PathSet.normalizeSubPath(String)'
3641
*/
42+
@Test
3743
public void testNormalizeSubPath() {
38-
assertEquals("Normalized path error", "", PathSet.normalizeSubPath(""));
39-
assertEquals("Normalized path error", "", PathSet.normalizeSubPath("/"));
40-
assertEquals("Normalized path error", "", PathSet.normalizeSubPath("////"));
41-
assertEquals("Normalized path error", "", PathSet.normalizeSubPath("\\"));
42-
assertEquals("Normalized path error", "", PathSet.normalizeSubPath("\\\\\\\\"));
43-
44-
assertEquals("Normalized path error", "abc", PathSet.normalizeSubPath("abc"));
45-
assertEquals("Normalized path error", "abc", PathSet.normalizeSubPath("/abc"));
46-
assertEquals("Normalized path error", "abc", PathSet.normalizeSubPath("////abc"));
47-
assertEquals("Normalized path error", "abc", PathSet.normalizeSubPath("\\abc"));
48-
assertEquals("Normalized path error", "abc", PathSet.normalizeSubPath("\\\\\\\\abc"));
49-
50-
assertEquals("Normalized path error", "abc/def/xyz", PathSet.normalizeSubPath("abc/def\\xyz\\"));
51-
assertEquals("Normalized path error", "abc/def/xyz", PathSet.normalizeSubPath("/abc/def/xyz/"));
52-
assertEquals("Normalized path error", "abc/def/xyz", PathSet.normalizeSubPath("////abc/def/xyz/"));
53-
assertEquals("Normalized path error", "abc/def/xyz", PathSet.normalizeSubPath("\\abc/def/xyz/"));
54-
assertEquals("Normalized path error", "abc/def/xyz", PathSet.normalizeSubPath("\\\\\\\\abc/def/xyz/"));
44+
assertEquals("", PathSet.normalizeSubPath(""), "Normalized path error");
45+
assertEquals("", PathSet.normalizeSubPath("/"), "Normalized path error");
46+
assertEquals("", PathSet.normalizeSubPath("////"), "Normalized path error");
47+
assertEquals("", PathSet.normalizeSubPath("\\"), "Normalized path error");
48+
assertEquals("", PathSet.normalizeSubPath("\\\\\\\\"), "Normalized path error");
49+
50+
assertEquals("abc", PathSet.normalizeSubPath("abc"), "Normalized path error");
51+
assertEquals("abc", PathSet.normalizeSubPath("/abc"), "Normalized path error");
52+
assertEquals("abc", PathSet.normalizeSubPath("////abc"), "Normalized path error");
53+
assertEquals("abc", PathSet.normalizeSubPath("\\abc"), "Normalized path error");
54+
assertEquals("abc", PathSet.normalizeSubPath("\\\\\\\\abc"), "Normalized path error");
55+
56+
assertEquals("abc/def/xyz", PathSet.normalizeSubPath("abc/def\\xyz\\"), "Normalized path error");
57+
assertEquals("abc/def/xyz", PathSet.normalizeSubPath("/abc/def/xyz/"), "Normalized path error");
58+
assertEquals("abc/def/xyz", PathSet.normalizeSubPath("////abc/def/xyz/"), "Normalized path error");
59+
assertEquals("abc/def/xyz", PathSet.normalizeSubPath("\\abc/def/xyz/"), "Normalized path error");
60+
assertEquals("abc/def/xyz", PathSet.normalizeSubPath("\\\\\\\\abc/def/xyz/"), "Normalized path error");
5561
// MWAR-371
56-
assertEquals("Normalized path error", "abc/def/ghi", PathSet.normalizeSubPath("///abc/////def////ghi//"));
62+
assertEquals("abc/def/ghi", PathSet.normalizeSubPath("///abc/////def////ghi//"), "Normalized path error");
5763
}
5864

5965
/* -------------- Operations tests ------------------*/
@@ -70,26 +76,27 @@ public void testNormalizeSubPath() {
7076
* <li>org.apache.maven.plugin.war.PathSet.addPrefix(String)</li>
7177
* </ul>
7278
*/
79+
@Test
7380
public void testPathsSetBasic() {
7481
PathSet ps = new PathSet();
75-
assertEquals("Unexpected PathSet size", ps.size(), 0);
82+
assertEquals(0, ps.size(), "Unexpected PathSet size");
7683
Iterator<String> iter = ps.iterator();
77-
assertNotNull("Iterator is null", iter);
78-
assertFalse("Can iterate on empty set", iter.hasNext());
84+
assertNotNull(iter, "Iterator is null");
85+
assertFalse(iter.hasNext(), "Can iterate on empty set");
7986

8087
ps.add("abc");
81-
assertEquals("Unexpected PathSet size", ps.size(), 1);
88+
assertEquals(1, ps.size(), "Unexpected PathSet size");
8289
ps.add("abc");
83-
assertEquals("Unexpected PathSet size", ps.size(), 1);
90+
assertEquals(1, ps.size(), "Unexpected PathSet size");
8491
ps.add("xyz/abc");
85-
assertEquals("Unexpected PathSet size", ps.size(), 2);
92+
assertEquals(2, ps.size(), "Unexpected PathSet size");
8693
ps.add("///abc");
87-
assertEquals("Unexpected PathSet size", ps.size(), 2);
94+
assertEquals(2, ps.size(), "Unexpected PathSet size");
8895
ps.add("///xyz\\abc");
89-
assertEquals("Unexpected PathSet size", ps.size(), 2);
96+
assertEquals(2, ps.size(), "Unexpected PathSet size");
9097

9198
ps.addAll(ps);
92-
assertEquals("Unexpected PathSet size", ps.size(), 2);
99+
assertEquals(2, ps.size(), "Unexpected PathSet size");
93100

94101
int i = 0;
95102
for (String pathstr : ps) {
@@ -100,7 +107,7 @@ public void testPathsSetBasic() {
100107
assertFalse(ps.contains("/" + StringUtils.replace(pathstr, '/', '\\') + "/a"));
101108
assertFalse(ps.contains("/a/" + StringUtils.replace(pathstr, '/', '\\')));
102109
}
103-
assertEquals("Wrong count of iterations", 2, i);
110+
assertEquals(2, i, "Wrong count of iterations");
104111

105112
ps.addPrefix("/ab/c/");
106113
i = 0;
@@ -114,7 +121,7 @@ public void testPathsSetBasic() {
114121
assertFalse(ps.contains("/" + StringUtils.replace(pathstr, '/', '\\') + "/a"));
115122
assertFalse(ps.contains("/ab/" + StringUtils.replace(pathstr, '/', '\\')));
116123
}
117-
assertEquals("Wrong count of iterations", 2, i);
124+
assertEquals(2, i, "Wrong count of iterations");
118125
}
119126

120127
/**
@@ -127,6 +134,7 @@ public void testPathsSetBasic() {
127134
* <li>org.apache.maven.plugin.war.PathSet.AddAll(Collection,String)</li>
128135
* </ul>
129136
*/
137+
@Test
130138
public void testPathsSetAddAlls() {
131139
Set<String> s1set = new HashSet<>();
132140
s1set.add("/a/b");
@@ -137,19 +145,19 @@ public void testPathsSetAddAlls() {
137145
String[] s2ar = new String[] {"/a/b", "a2/b2/c2", "a2\\b2/c2", "//21//22\23a"};
138146

139147
PathSet ps1 = new PathSet(s1set);
140-
assertEquals("Unexpected PathSet size", 3, ps1.size());
148+
assertEquals(3, ps1.size(), "Unexpected PathSet size");
141149

142150
PathSet ps2 = new PathSet(s2ar);
143-
assertEquals("Unexpected PathSet size", 3, ps2.size());
151+
assertEquals(3, ps2.size(), "Unexpected PathSet size");
144152

145153
ps1.addAll(s2ar);
146-
assertEquals("Unexpected PathSet size", 5, ps1.size());
154+
assertEquals(5, ps1.size(), "Unexpected PathSet size");
147155

148156
ps2.addAll(s1set);
149-
assertEquals("Unexpected PathSet size", 5, ps2.size());
157+
assertEquals(5, ps2.size(), "Unexpected PathSet size");
150158

151159
for (String str : ps1) {
152-
assertTrue(str, ps2.contains(str));
160+
assertTrue(ps2.contains(str), str);
153161
assertTrue(ps2.contains("/" + str));
154162
assertTrue(ps1.contains(str));
155163
assertTrue(ps1.contains("/" + str));
@@ -163,13 +171,13 @@ public void testPathsSetAddAlls() {
163171
}
164172

165173
ps1.addAll(s2ar, "/pref/");
166-
assertEquals("Unexpected PathSet size", 8, ps1.size());
174+
assertEquals(8, ps1.size(), "Unexpected PathSet size");
167175

168176
ps2.addAll(s2ar, "/pref/");
169-
assertEquals("Unexpected PathSet size", 8, ps2.size());
177+
assertEquals(8, ps2.size(), "Unexpected PathSet size");
170178

171179
for (String str : ps1) {
172-
assertTrue(str, ps2.contains(str));
180+
assertTrue(ps2.contains(str), str);
173181
assertTrue(ps2.contains("/" + str));
174182
assertTrue(ps1.contains(str));
175183
assertTrue(ps1.contains("/" + str));
@@ -184,14 +192,15 @@ public void testPathsSetAddAlls() {
184192

185193
PathSet ps3 = new PathSet();
186194
ps3.addAll(new String[] {"a/b/c"}, "d");
187-
assertTrue("Unexpected PathSet path", ps3.contains("d/a/b/c"));
195+
assertTrue(ps3.contains("d/a/b/c"), "Unexpected PathSet path");
188196
}
189197

190198
/**
191199
* Test method for 'org.apache.maven.plugin.war.PathSet.addAllFilesInDirectory(File, String)'
192200
*
193201
* @throws IOException if an io error occurred
194202
*/
203+
@Test
195204
public void testAddAllFilesInDirectory() throws IOException {
196205
PathSet ps = new PathSet();
197206

@@ -213,11 +222,11 @@ public void testAddAllFilesInDirectory() throws IOException {
213222
d1d2f2.createNewFile();
214223

215224
ps.addAllFilesInDirectory(new File("target/testAddAllFilesInDirectory"), "123/");
216-
assertEquals("Unexpected PathSet size", 4, ps.size());
225+
assertEquals(4, ps.size(), "Unexpected PathSet size");
217226

218227
/*No changes after adding duplicates*/
219228
ps.addAllFilesInDirectory(new File("target/testAddAllFilesInDirectory"), "123/");
220-
assertEquals("Unexpected PathSet size", 4, ps.size());
229+
assertEquals(4, ps.size(), "Unexpected PathSet size");
221230

222231
/*Cleanup*/
223232

@@ -226,7 +235,7 @@ public void testAddAllFilesInDirectory() throws IOException {
226235

227236
/*No changes after adding a subset of files*/
228237
ps.addAllFilesInDirectory(new File("target/testAddAllFilesInDirectory"), "123/");
229-
assertEquals("Unexpected PathSet size", 4, ps.size());
238+
assertEquals(4, ps.size(), "Unexpected PathSet size");
230239

231240
d1d2f1.delete();
232241
d1d2f2.delete();

src/test/java/org/apache/maven/plugins/war/util/WebappStructureTest.java

Lines changed: 13 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -20,73 +20,46 @@
2020

2121
import java.util.ArrayList;
2222

23-
import junit.framework.TestCase;
24-
import org.apache.maven.artifact.Artifact;
25-
import org.apache.maven.model.Dependency;
23+
import org.junit.jupiter.api.Test;
24+
25+
import static org.junit.jupiter.api.Assertions.assertEquals;
26+
import static org.junit.jupiter.api.Assertions.assertFalse;
27+
import static org.junit.jupiter.api.Assertions.assertTrue;
2628

2729
/**
2830
* @author Stephane Nicoll
2931
*/
30-
public class WebappStructureTest extends TestCase {
32+
public class WebappStructureTest {
33+
@Test
3134
public void testUnknownFileNotAvailable() {
3235
final WebappStructure structure = new WebappStructure(new ArrayList<>());
3336
assertFalse(structure.isRegistered("/foo/bar.txt"));
3437
}
3538

39+
@Test
3640
public void testRegisterSamePathTwice() {
3741
final WebappStructure structure = new WebappStructure(new ArrayList<>());
3842
structure.registerFile("overlay1", "WEB-INF/web.xml");
3943
assertFalse(structure.registerFile("currentBuild", "WEB-INF/web.xml"));
4044
}
4145

46+
@Test
4247
public void testRegisterForced() {
4348
final String path = "WEB-INF/web.xml";
4449
final WebappStructure structure = new WebappStructure(new ArrayList<>());
45-
assertFalse("New file should return false", structure.registerFileForced("overlay1", path));
50+
assertFalse(structure.registerFileForced("overlay1", path), "New file should return false");
4651
assertEquals("overlay1", structure.getOwner(path));
4752
}
4853

54+
@Test
4955
public void testRegisterSamePathTwiceForced() {
5056
final String path = "WEB-INF/web.xml";
5157
final WebappStructure structure = new WebappStructure(new ArrayList<>());
5258
structure.registerFile("overlay1", path);
5359
assertEquals("overlay1", structure.getOwner(path));
54-
assertTrue("owner replacement should have returned true", structure.registerFileForced("currentBuild", path));
60+
assertTrue(structure.registerFileForced("currentBuild", path), "owner replacement should have returned true");
5561
assertEquals("currentBuild", structure.getOwner(path));
5662
}
5763

58-
protected Dependency createDependency(
59-
String groupId, String artifactId, String version, String type, String scope, String classifier) {
60-
final Dependency dep = new Dependency();
61-
dep.setGroupId(groupId);
62-
dep.setArtifactId(artifactId);
63-
dep.setVersion(version);
64-
if (type == null) {
65-
dep.setType("jar");
66-
} else {
67-
dep.setType(type);
68-
}
69-
if (scope != null) {
70-
dep.setScope(scope);
71-
} else {
72-
dep.setScope(Artifact.SCOPE_COMPILE);
73-
}
74-
if (classifier != null) {
75-
dep.setClassifier(classifier);
76-
}
77-
return dep;
78-
}
79-
80-
protected Dependency createDependency(
81-
String groupId, String artifactId, String version, String type, String scope) {
82-
return createDependency(groupId, artifactId, version, type, scope, null);
83-
}
84-
85-
protected Dependency createDependency(String groupId, String artifactId, String version, String type) {
86-
return createDependency(groupId, artifactId, version, type, null);
87-
}
88-
89-
protected Dependency createDependency(String groupId, String artifactId, String version) {
90-
return createDependency(groupId, artifactId, version, null);
91-
}
64+
// ... existing code ...
9265
}

0 commit comments

Comments
 (0)