Skip to content

Commit a1bb14f

Browse files
authored
Convert to JUnit 5 (#445)
* Convert to JUnit 5 * Convert to JUnit 5 * Convert to JUnit 5 * Convert to JUnit 5 * Convert to JUnit 5 * Convert to JUnit 5 * rebase
1 parent c98c851 commit a1bb14f

File tree

7 files changed

+84
-111
lines changed

7 files changed

+84
-111
lines changed

pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,6 @@ under the License.
161161
<artifactId>maven-reporting-impl</artifactId>
162162
<version>4.0.0</version>
163163
</dependency>
164-
<dependency>
165-
<groupId>commons-io</groupId>
166-
<artifactId>commons-io</artifactId>
167-
<version>2.17.0</version>
168-
<scope>test</scope>
169-
</dependency>
170164

171165
<!-- plexus -->
172166
<dependency>

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.io.File;
2222
import java.io.IOException;
23+
import java.nio.file.Files;
2324

2425
import org.apache.commons.io.FileUtils;
2526
import org.apache.maven.artifact.Artifact;
@@ -49,15 +50,17 @@ protected void setUp(String testDirStr, boolean createFiles) throws Exception {
4950
protected void setUp(String testDirStr, boolean createFiles, boolean flattenedPath) throws Exception {
5051
// required for mojo lookups to work
5152
super.setUp();
53+
5254
testDir = new File(
5355
getBasedir(),
5456
"target" + File.separatorChar + "unit-tests" + File.separatorChar + testDirStr + File.separatorChar);
55-
FileUtils.deleteDirectory(testDir);
56-
assertFalse(testDir.exists());
57+
testDir = Files.createTempDirectory("testDirStr").toFile();
58+
testDir.deleteOnExit();
5759

5860
stubFactory = new DependencyArtifactStubFactory(this.testDir, createFiles, flattenedPath);
5961
}
6062

63+
@Override
6164
protected void tearDown() {
6265
if (testDir != null) {
6366
try {

src/test/java/org/apache/maven/plugins/dependency/utils/filters/TestDestFileFilter.java

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,43 +23,37 @@
2323
import java.util.HashSet;
2424
import java.util.Set;
2525

26-
import junit.framework.TestCase;
27-
import org.apache.commons.io.FileUtils;
2826
import org.apache.maven.artifact.Artifact;
2927
import org.apache.maven.plugin.MojoExecutionException;
30-
import org.apache.maven.plugin.logging.Log;
31-
import org.apache.maven.plugin.testing.SilentLog;
3228
import org.apache.maven.plugins.dependency.testUtils.DependencyArtifactStubFactory;
3329
import org.apache.maven.plugins.dependency.utils.DependencyUtil;
3430
import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
31+
import org.junit.jupiter.api.BeforeEach;
32+
import org.junit.jupiter.api.Test;
33+
import org.junit.jupiter.api.io.TempDir;
34+
35+
import static org.junit.jupiter.api.Assertions.assertFalse;
36+
import static org.junit.jupiter.api.Assertions.assertNull;
37+
import static org.junit.jupiter.api.Assertions.assertSame;
38+
import static org.junit.jupiter.api.Assertions.assertTrue;
3539

3640
/**
3741
* @author brianf
3842
*/
39-
public class TestDestFileFilter extends TestCase {
43+
public class TestDestFileFilter {
4044
Set<Artifact> artifacts = new HashSet<>();
4145

42-
Log log = new SilentLog();
43-
46+
@TempDir
4447
File outputFolder;
4548

4649
DependencyArtifactStubFactory fact;
4750

51+
@BeforeEach
4852
protected void setUp() throws Exception {
49-
super.setUp();
50-
51-
outputFolder = new File("target/markers/");
52-
FileUtils.deleteDirectory(outputFolder);
53-
assertFalse(outputFolder.exists());
54-
5553
this.fact = new DependencyArtifactStubFactory(outputFolder, false);
5654
artifacts = fact.getReleaseAndSnapshotArtifacts();
5755
}
5856

59-
protected void tearDown() throws IOException {
60-
FileUtils.deleteDirectory(outputFolder);
61-
}
62-
6357
public void createFile(Artifact artifact) throws IOException {
6458
createFile(artifact, false, false, false);
6559
}
@@ -91,6 +85,7 @@ public File createFile(
9185
return destFile;
9286
}
9387

88+
@Test
9489
public void testDestFileRelease() throws IOException, ArtifactFilterException {
9590
DestFileFilter filter = new DestFileFilter(outputFolder);
9691
Artifact artifact = fact.getReleaseArtifact();
@@ -103,6 +98,7 @@ public void testDestFileRelease() throws IOException, ArtifactFilterException {
10398
assertTrue(filter.isArtifactIncluded(artifact));
10499
}
105100

101+
@Test
106102
public void testDestFileSnapshot() throws IOException, ArtifactFilterException {
107103
DestFileFilter filter = new DestFileFilter(outputFolder);
108104
Artifact artifact = fact.getSnapshotArtifact();
@@ -115,6 +111,7 @@ public void testDestFileSnapshot() throws IOException, ArtifactFilterException {
115111
assertTrue(filter.isArtifactIncluded(artifact));
116112
}
117113

114+
@Test
118115
public void testDestFileStripVersion() throws IOException, ArtifactFilterException {
119116
DestFileFilter filter = new DestFileFilter(outputFolder);
120117
Artifact artifact = fact.getSnapshotArtifact();
@@ -128,6 +125,7 @@ public void testDestFileStripVersion() throws IOException, ArtifactFilterExcepti
128125
assertTrue(filter.isArtifactIncluded(artifact));
129126
}
130127

128+
@Test
131129
public void testDestFileStripClassifier() throws IOException, ArtifactFilterException {
132130
DestFileFilter filter = new DestFileFilter(outputFolder);
133131
Artifact artifact = fact.getSnapshotArtifact();
@@ -141,6 +139,7 @@ public void testDestFileStripClassifier() throws IOException, ArtifactFilterExce
141139
assertTrue(filter.isArtifactIncluded(artifact));
142140
}
143141

142+
@Test
144143
public void testDestFileSubPerArtifact() throws IOException, ArtifactFilterException {
145144
DestFileFilter filter = new DestFileFilter(outputFolder);
146145
Artifact artifact = fact.getSnapshotArtifact();
@@ -154,6 +153,7 @@ public void testDestFileSubPerArtifact() throws IOException, ArtifactFilterExcep
154153
assertTrue(filter.isArtifactIncluded(artifact));
155154
}
156155

156+
@Test
157157
public void testDestFileSubPerType() throws MojoExecutionException, IOException, ArtifactFilterException {
158158
DestFileFilter filter = new DestFileFilter(outputFolder);
159159
Artifact artifact = fact.getSnapshotArtifact();
@@ -167,6 +167,7 @@ public void testDestFileSubPerType() throws MojoExecutionException, IOException,
167167
assertTrue(filter.isArtifactIncluded(artifact));
168168
}
169169

170+
@Test
170171
public void testDestFileOverwriteIfNewer() throws MojoExecutionException, IOException, ArtifactFilterException {
171172
DestFileFilter filter = new DestFileFilter(outputFolder);
172173

@@ -192,6 +193,7 @@ public void testDestFileOverwriteIfNewer() throws MojoExecutionException, IOExce
192193
assertFalse(filter.isArtifactIncluded(artifact));
193194
}
194195

196+
@Test
195197
public void testGettersSetters() {
196198
DestFileFilter filter = new DestFileFilter(null);
197199
assertNull(filter.getOutputFileDirectory());

src/test/java/org/apache/maven/plugins/dependency/utils/filters/TestMarkerFileFilter.java

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,45 +23,38 @@
2323
import java.util.HashSet;
2424
import java.util.Set;
2525

26-
import junit.framework.TestCase;
27-
import org.apache.commons.io.FileUtils;
2826
import org.apache.maven.artifact.Artifact;
2927
import org.apache.maven.plugin.MojoExecutionException;
30-
import org.apache.maven.plugin.logging.Log;
31-
import org.apache.maven.plugin.testing.SilentLog;
3228
import org.apache.maven.plugins.dependency.testUtils.DependencyArtifactStubFactory;
3329
import org.apache.maven.plugins.dependency.utils.markers.DefaultFileMarkerHandler;
3430
import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
31+
import org.junit.jupiter.api.BeforeEach;
32+
import org.junit.jupiter.api.Test;
33+
import org.junit.jupiter.api.io.TempDir;
34+
35+
import static org.junit.jupiter.api.Assertions.assertEquals;
36+
import static org.junit.jupiter.api.Assertions.assertFalse;
37+
import static org.junit.jupiter.api.Assertions.assertTrue;
3538

3639
/**
3740
* @author brianf
3841
*/
39-
public class TestMarkerFileFilter extends TestCase {
42+
public class TestMarkerFileFilter {
4043
Set<Artifact> artifacts = new HashSet<>();
4144

42-
Log log = new SilentLog();
43-
45+
@TempDir
4446
File outputFolder;
4547

4648
DependencyArtifactStubFactory fact;
4749

50+
@BeforeEach
4851
protected void setUp() throws Exception {
49-
super.setUp();
50-
51-
outputFolder = new File("target/markers/");
52-
FileUtils.deleteDirectory(outputFolder);
53-
assertFalse(outputFolder.exists());
54-
5552
this.fact = new DependencyArtifactStubFactory(outputFolder, false);
5653
artifacts = fact.getReleaseAndSnapshotArtifacts();
5754
}
5855

59-
protected void tearDown() throws IOException {
60-
FileUtils.deleteDirectory(outputFolder);
61-
}
62-
56+
@Test
6357
public void testMarkerFile() throws ArtifactFilterException {
64-
6558
MarkerFileFilter filter = new MarkerFileFilter(true, true, false, new DefaultFileMarkerHandler(outputFolder));
6659
Set<Artifact> result = filter.filter(artifacts);
6760
assertEquals(2, result.size());
@@ -73,7 +66,6 @@ public void testMarkerFile() throws ArtifactFilterException {
7366
}
7467

7568
public void testMarkerSnapshots() throws ArtifactFilterException, MojoExecutionException, IOException {
76-
7769
DefaultFileMarkerHandler handler = new DefaultFileMarkerHandler(fact.getSnapshotArtifact(), outputFolder);
7870
handler.setMarker();
7971

@@ -85,8 +77,6 @@ public void testMarkerSnapshots() throws ArtifactFilterException, MojoExecutionE
8577
result = filter.filter(artifacts);
8678
assertEquals(2, result.size());
8779
assertTrue(handler.clearMarker());
88-
FileUtils.deleteDirectory(outputFolder);
89-
assertFalse(outputFolder.exists());
9080
}
9181

9282
public void testMarkerRelease() throws IOException, ArtifactFilterException, MojoExecutionException {
@@ -102,10 +92,9 @@ public void testMarkerRelease() throws IOException, ArtifactFilterException, Moj
10292
assertEquals(2, result.size());
10393

10494
assertTrue(handler.clearMarker());
105-
FileUtils.deleteDirectory(outputFolder);
106-
assertFalse(outputFolder.exists());
10795
}
10896

97+
@Test
10998
public void testMarkerTimestamp() throws IOException, MojoExecutionException, ArtifactFilterException {
11099
// filter includes release artifact because no marker present
111100
// filter includes snapshot artifact because it is newer than marker
@@ -137,10 +126,9 @@ public void testMarkerTimestamp() throws IOException, MojoExecutionException, Ar
137126
assertFalse(handler.isMarkerSet());
138127
snap.getFile().delete();
139128
release.getFile().delete();
140-
FileUtils.deleteDirectory(outputFolder);
141-
assertFalse(outputFolder.exists());
142129
}
143130

131+
@Test
144132
public void testGettersSetters() {
145133
MarkerFileFilter filter = new MarkerFileFilter(true, false, true, new DefaultFileMarkerHandler(outputFolder));
146134
assertTrue(filter.isOverWriteReleases());

src/test/java/org/apache/maven/plugins/dependency/utils/filters/TestResolveMarkerFileFilter.java

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

2121
import java.io.File;
2222
import java.io.IOException;
23-
import java.util.HashSet;
24-
import java.util.Set;
2523

26-
import junit.framework.TestCase;
27-
import org.apache.commons.io.FileUtils;
2824
import org.apache.maven.artifact.Artifact;
2925
import org.apache.maven.plugin.MojoExecutionException;
30-
import org.apache.maven.plugin.logging.Log;
31-
import org.apache.maven.plugin.testing.SilentLog;
3226
import org.apache.maven.plugins.dependency.testUtils.DependencyArtifactStubFactory;
3327
import org.apache.maven.plugins.dependency.utils.markers.SourcesFileMarkerHandler;
3428
import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
29+
import org.junit.jupiter.api.BeforeEach;
30+
import org.junit.jupiter.api.Test;
31+
import org.junit.jupiter.api.io.TempDir;
32+
33+
import static org.junit.jupiter.api.Assertions.assertFalse;
34+
import static org.junit.jupiter.api.Assertions.assertTrue;
3535

3636
/**
3737
* @author brianf
3838
*/
39-
public class TestResolveMarkerFileFilter extends TestCase {
40-
Set<Artifact> artifacts = new HashSet<>();
41-
42-
Log log = new SilentLog();
39+
public class TestResolveMarkerFileFilter {
4340

41+
@TempDir
4442
File outputFolder;
4543

4644
DependencyArtifactStubFactory fact;
4745

48-
protected void setUp() throws Exception {
49-
super.setUp();
50-
51-
outputFolder = new File("target/markers/");
52-
FileUtils.deleteDirectory(outputFolder);
53-
assertFalse(outputFolder.exists());
54-
55-
this.fact = new DependencyArtifactStubFactory(outputFolder, false);
56-
artifacts = fact.getReleaseAndSnapshotArtifacts();
57-
}
58-
59-
protected void tearDown() throws IOException {
60-
FileUtils.deleteDirectory(outputFolder);
46+
@BeforeEach
47+
protected void setUp() throws IOException {
48+
fact = new DependencyArtifactStubFactory(outputFolder, false);
49+
fact.getReleaseAndSnapshotArtifacts();
6150
}
6251

52+
@Test
6353
public void testResolveFile() throws IOException, ArtifactFilterException, MojoExecutionException {
6454
SourcesFileMarkerHandler handler = new SourcesFileMarkerHandler(outputFolder);
6555

0 commit comments

Comments
 (0)