Skip to content

Commit 7ce1492

Browse files
authored
Migrate JUnit3 based Tests to JUnit 5 (apache#1541)
* chore: migration from junit3 to junit5 Signed-off-by: Sandra Parsick <sandra@parsick.dev> * chore: remove unused code Signed-off-by: Sandra Parsick <sandra@parsick.dev> --------- Signed-off-by: Sandra Parsick <sandra@parsick.dev>
1 parent 6b20362 commit 7ce1492

File tree

3 files changed

+36
-79
lines changed

3 files changed

+36
-79
lines changed

src/test/java/org/apache/maven/plugins/dependency/AbstractDependencyMojoTest.java

Lines changed: 0 additions & 70 deletions
This file was deleted.

src/test/java/org/apache/maven/plugins/dependency/analyze/TestAnalyzeDepMgt.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.util.Map;
2727
import java.util.Set;
2828

29-
import junit.framework.TestCase;
3029
import org.apache.maven.artifact.Artifact;
3130
import org.apache.maven.model.Dependency;
3231
import org.apache.maven.model.DependencyManagement;
@@ -36,10 +35,16 @@
3635
import org.apache.maven.plugins.dependency.testUtils.DependencyArtifactStubFactory;
3736
import org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub;
3837
import org.apache.maven.project.MavenProject;
38+
import org.junit.jupiter.api.BeforeEach;
39+
import org.junit.jupiter.api.Test;
3940

41+
import static org.junit.Assert.assertEquals;
4042
import static org.junit.Assert.assertNotEquals;
43+
import static org.junit.Assert.assertSame;
44+
import static org.junit.Assert.assertTrue;
45+
import static org.junit.Assert.fail;
4146

42-
public class TestAnalyzeDepMgt extends TestCase {
47+
public class TestAnalyzeDepMgt {
4348

4449
AnalyzeDepMgt mojo;
4550

@@ -51,8 +56,8 @@ public class TestAnalyzeDepMgt extends TestCase {
5156

5257
DependencyManagement depMgt;
5358

54-
@Override
55-
protected void setUp() throws Exception {
59+
@BeforeEach
60+
public void setUp() throws Exception {
5661

5762
MavenProject project = new DependencyProjectStub();
5863
mojo = new AnalyzeDepMgt(project);
@@ -86,6 +91,7 @@ protected void setUp() throws Exception {
8691
project.setDependencyArtifacts(directArtifacts);
8792
}
8893

94+
@Test
8995
public void testGetManagementKey() throws IOException {
9096
Dependency dep = new Dependency();
9197
dep.setArtifactId("artifact");
@@ -145,6 +151,7 @@ public void testGetManagementKey() throws IOException {
145151
assertEquals(dep.getManagementKey(), mojo.getArtifactManagementKey(artifact));
146152
}
147153

154+
@Test
148155
public void testAddExclusions() {
149156

150157
assertEquals(0, mojo.addExclusions(null).size());
@@ -158,6 +165,7 @@ public void testAddExclusions() {
158165
assertSame(ex, map.get(mojo.getExclusionKey(ex)));
159166
}
160167

168+
@Test
161169
public void testGetExclusionErrors() {
162170
List<Exclusion> list = new ArrayList<>();
163171
list.add(ex);
@@ -172,6 +180,7 @@ public void testGetExclusionErrors() {
172180
assertEquals(mojo.getExclusionKey(ex), mojo.getExclusionKey(l.get(0)));
173181
}
174182

183+
@Test
175184
public void testGetMismatch() throws IOException {
176185
Map<String, Dependency> depMgtMap = new HashMap<>();
177186

@@ -186,6 +195,7 @@ public void testGetMismatch() throws IOException {
186195
assertSame(exclusion, results.get(stubFactory.getReleaseArtifact()));
187196
}
188197

198+
@Test
189199
public void testMojo() throws IOException, MojoExecutionException, MojoFailureException {
190200
mojo.setIgnoreDirect(false);
191201
// test with nothing in depMgt

src/test/java/org/apache/maven/plugins/dependency/utils/markers/TestSourcesMarkerFileHandler.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.util.List;
2525
import java.util.Random;
2626

27-
import junit.framework.TestCase;
2827
import org.apache.maven.artifact.Artifact;
2928
import org.apache.maven.artifact.DefaultArtifact;
3029
import org.apache.maven.artifact.handler.ArtifactHandler;
@@ -34,19 +33,26 @@
3433
import org.apache.maven.plugin.logging.Log;
3534
import org.apache.maven.plugin.testing.SilentLog;
3635
import org.apache.maven.plugins.dependency.testUtils.stubs.StubSourcesFileMarkerHandler;
36+
import org.junit.jupiter.api.AfterEach;
37+
import org.junit.jupiter.api.BeforeEach;
38+
import org.junit.jupiter.api.Test;
39+
40+
import static org.junit.Assert.assertFalse;
41+
import static org.junit.Assert.assertTrue;
42+
import static org.junit.Assert.fail;
3743

3844
/**
3945
* @author brianf
4046
*/
41-
public class TestSourcesMarkerFileHandler extends TestCase {
47+
public class TestSourcesMarkerFileHandler {
4248
List<Artifact> artifacts = new ArrayList<>();
4349

4450
Log log = new SilentLog();
4551

4652
File outputFolder;
4753

48-
protected void setUp() throws Exception {
49-
super.setUp();
54+
@BeforeEach
55+
public void setUp() throws Exception {
5056

5157
ArtifactHandler ah = new DefaultArtifactHandler();
5258
VersionRange vr = VersionRange.createFromVersion("1.1");
@@ -66,10 +72,12 @@ protected void setUp() throws Exception {
6672
assertFalse(outputFolder.exists());
6773
}
6874

69-
protected void tearDown() {
75+
@AfterEach
76+
public void tearDown() {
7077
outputFolder.delete();
7178
}
7279

80+
@Test
7381
public void testSetMarkerResolved() throws MojoExecutionException {
7482
DefaultFileMarkerHandler handler = new SourcesFileMarkerHandler(artifacts.get(0), this.outputFolder, true);
7583
assertFalse(handler.isMarkerSet());
@@ -88,6 +96,7 @@ public void testSetMarkerResolved() throws MojoExecutionException {
8896
assertFalse(outputFolder.exists());
8997
}
9098

99+
@Test
91100
public void testSetMarkerUnresolved() throws MojoExecutionException {
92101
DefaultFileMarkerHandler handler = new SourcesFileMarkerHandler(artifacts.get(0), this.outputFolder, false);
93102
assertFalse(handler.isMarkerSet());
@@ -106,6 +115,7 @@ public void testSetMarkerUnresolved() throws MojoExecutionException {
106115
assertFalse(outputFolder.exists());
107116
}
108117

118+
@Test
109119
public void testBothMarkers() throws MojoExecutionException {
110120
DefaultFileMarkerHandler handler = new SourcesFileMarkerHandler(artifacts.get(1), this.outputFolder, true);
111121
DefaultFileMarkerHandler handler2 = new SourcesFileMarkerHandler(artifacts.get(1), this.outputFolder, false);
@@ -121,6 +131,7 @@ public void testBothMarkers() throws MojoExecutionException {
121131
assertFalse(outputFolder.exists());
122132
}
123133

134+
@Test
124135
public void testMarkerFile() throws MojoExecutionException, IOException {
125136
DefaultFileMarkerHandler handler = new SourcesFileMarkerHandler(artifacts.get(0), this.outputFolder, true);
126137
DefaultFileMarkerHandler handler2 = new SourcesFileMarkerHandler(artifacts.get(0), this.outputFolder, false);
@@ -176,10 +187,12 @@ public void testMarkerFile() throws MojoExecutionException, IOException {
176187
assertFalse(outputFolder.exists());
177188
}
178189

190+
@Test
179191
public void testMarkerTimeStampResolved() throws MojoExecutionException, IOException, InterruptedException {
180192
doTestMarkerTimeStamp(true);
181193
}
182194

195+
@Test
183196
public void testMarkerTimeStampUnResolved() throws MojoExecutionException, IOException, InterruptedException {
184197
doTestMarkerTimeStamp(false);
185198
}
@@ -220,6 +233,7 @@ public void doTestMarkerTimeStamp(boolean resolved)
220233
assertFalse(resolvedHandler.isMarkerSet());
221234
}
222235

236+
@Test
223237
public void testMarkerFileException() {
224238
// this stub wraps the file with an object to throw exceptions
225239
StubSourcesFileMarkerHandler handler =
@@ -231,13 +245,15 @@ public void testMarkerFileException() {
231245
}
232246
}
233247

248+
@Test
234249
public void testMarkerFileResolvedSetter() {
235250
SourcesFileMarkerHandler handler = new SourcesFileMarkerHandler(null, null, true);
236251
assertTrue(handler.isResolved());
237252
handler.setResolved(false);
238253
assertFalse(handler.isResolved());
239254
}
240255

256+
@Test
241257
public void testNullParent() throws MojoExecutionException {
242258
// the parent isn't set so this will create the marker in the local
243259
// folder. We must clear the
@@ -250,6 +266,7 @@ public void testNullParent() throws MojoExecutionException {
250266
assertFalse(handler.isMarkerSet());
251267
}
252268

269+
@Test
253270
public void testNullParentResolved() throws MojoExecutionException {
254271
// the parent isn't set so this will create the marker in the local
255272
// folder. We must clear the

0 commit comments

Comments
 (0)