Skip to content

Commit 42516e7

Browse files
Migrate to JUnit 5 - avoid using TestCase
1 parent e65ec60 commit 42516e7

File tree

66 files changed

+976
-823
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+976
-823
lines changed

maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929

3030
import org.junit.jupiter.api.Test;
3131

32-
import static org.junit.Assert.assertEquals;
33-
import static org.junit.Assert.fail;
32+
import static org.junit.jupiter.api.Assertions.assertEquals;
33+
import static org.junit.jupiter.api.Assertions.fail;
3434

3535
public class ComparableVersionIT {
3636

@@ -52,7 +52,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
5252
});
5353

5454
try {
55-
assertEquals("Unexpected exit code", 0, p.waitFor());
55+
assertEquals(0, p.waitFor(), "Unexpected exit code");
5656
} catch (InterruptedException e) {
5757
fail(e.getMessage());
5858
}

maven-builder-support/src/test/java/org/apache/maven/building/DefaultProblemTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
package org.apache.maven.building;
2020

2121
import org.apache.maven.building.Problem.Severity;
22-
import org.junit.Test;
22+
import org.junit.jupiter.api.Test;
2323

24-
import static org.junit.Assert.assertEquals;
25-
import static org.junit.Assert.assertSame;
24+
import static org.junit.jupiter.api.Assertions.assertEquals;
25+
import static org.junit.jupiter.api.Assertions.assertSame;
2626

2727
public class DefaultProblemTest {
2828

maven-builder-support/src/test/java/org/apache/maven/building/FileSourceTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
import java.io.InputStream;
2323
import java.util.Scanner;
2424

25-
import org.junit.Test;
25+
import org.junit.jupiter.api.Test;
2626

27-
import static org.junit.Assert.assertEquals;
28-
import static org.junit.Assert.fail;
27+
import static org.junit.jupiter.api.Assertions.assertEquals;
28+
import static org.junit.jupiter.api.Assertions.fail;
2929

3030
public class FileSourceTest {
3131

maven-builder-support/src/test/java/org/apache/maven/building/ProblemCollectorFactoryTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020

2121
import java.util.Collections;
2222

23-
import org.junit.Test;
23+
import org.junit.jupiter.api.Test;
2424

25-
import static org.junit.Assert.assertEquals;
26-
import static org.junit.Assert.assertNotSame;
25+
import static org.junit.jupiter.api.Assertions.assertEquals;
26+
import static org.junit.jupiter.api.Assertions.assertNotSame;
2727

2828
public class ProblemCollectorFactoryTest {
2929

maven-builder-support/src/test/java/org/apache/maven/building/StringSourceTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
import java.io.InputStream;
2222
import java.util.Scanner;
2323

24-
import org.junit.Test;
24+
import org.junit.jupiter.api.Test;
2525

26-
import static org.junit.Assert.assertEquals;
26+
import static org.junit.jupiter.api.Assertions.assertEquals;
2727

2828
public class StringSourceTest {
2929
@Test

maven-builder-support/src/test/java/org/apache/maven/building/UrlSourceTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
import java.net.URL;
2424
import java.util.Scanner;
2525

26-
import org.junit.Test;
26+
import org.junit.jupiter.api.Test;
2727

28-
import static org.junit.Assert.assertEquals;
29-
import static org.junit.Assert.fail;
28+
import static org.junit.jupiter.api.Assertions.assertEquals;
29+
import static org.junit.jupiter.api.Assertions.fail;
3030

3131
public class UrlSourceTest {
3232

maven-compat/pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,17 @@ under the License.
117117
<artifactId>maven-resolver-transport-wagon</artifactId>
118118
<scope>test</scope>
119119
</dependency>
120+
<dependency>
121+
<groupId>org.junit.jupiter</groupId>
122+
<artifactId>junit-jupiter-api</artifactId>
123+
<scope>test</scope>
124+
</dependency>
125+
<dependency>
126+
<groupId>org.codehaus.plexus</groupId>
127+
<artifactId>plexus-testing</artifactId>
128+
<version>2.0.2</version>
129+
<scope>test</scope>
130+
</dependency>
120131
</dependencies>
121132

122133
<build>

maven-compat/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java renamed to maven-compat/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTest.java

Lines changed: 19 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*/
1919
package org.apache.maven.artifact;
2020

21+
import javax.inject.Inject;
22+
2123
import java.io.File;
2224
import java.io.FileOutputStream;
2325
import java.io.IOException;
@@ -31,15 +33,12 @@
3133
import org.apache.maven.artifact.repository.ArtifactRepository;
3234
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
3335
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
36+
import org.apache.maven.artifact.resolver.TestMavenWorkspaceReader;
3437
import org.apache.maven.execution.DefaultMavenExecutionRequest;
3538
import org.apache.maven.execution.DefaultMavenExecutionResult;
3639
import org.apache.maven.execution.MavenSession;
3740
import org.apache.maven.plugin.LegacySupport;
3841
import org.apache.maven.repository.legacy.repository.ArtifactRepositoryFactory;
39-
import org.codehaus.plexus.ContainerConfiguration;
40-
import org.codehaus.plexus.PlexusConstants;
41-
import org.codehaus.plexus.PlexusTestCase;
42-
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
4342
import org.eclipse.aether.DefaultRepositorySystemSession;
4443
import org.eclipse.aether.RepositorySystemSession;
4544
import org.eclipse.aether.collection.DependencyGraphTransformer;
@@ -48,7 +47,6 @@
4847
import org.eclipse.aether.collection.DependencyTraverser;
4948
import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
5049
import org.eclipse.aether.repository.LocalRepository;
51-
import org.eclipse.aether.repository.WorkspaceReader;
5250
import org.eclipse.aether.util.graph.manager.ClassicDependencyManager;
5351
import org.eclipse.aether.util.graph.selector.AndDependencySelector;
5452
import org.eclipse.aether.util.graph.selector.ExclusionDependencySelector;
@@ -63,76 +61,45 @@
6361
import org.eclipse.aether.util.graph.transformer.SimpleOptionalitySelector;
6462
import org.eclipse.aether.util.graph.traverser.FatArtifactTraverser;
6563
import org.eclipse.aether.util.repository.SimpleArtifactDescriptorPolicy;
64+
import org.junit.jupiter.api.BeforeEach;
65+
66+
import static org.codehaus.plexus.testing.PlexusExtension.getBasedir;
67+
import static org.junit.jupiter.api.Assertions.fail;
6668

6769
/**
6870
* @author <a href="mailto:[email protected]">Jason van Zyl </a>
6971
*/
70-
public abstract class AbstractArtifactComponentTestCase extends PlexusTestCase {
72+
public abstract class AbstractArtifactComponentTest {
73+
74+
@Inject
7175
protected ArtifactFactory artifactFactory;
7276

77+
@Inject
7378
protected ArtifactRepositoryFactory artifactRepositoryFactory;
7479

75-
@Override
76-
protected void customizeContainerConfiguration(ContainerConfiguration containerConfiguration) {
77-
super.customizeContainerConfiguration(containerConfiguration);
78-
containerConfiguration.setAutoWiring(true);
79-
containerConfiguration.setClassPathScanning(PlexusConstants.SCANNING_INDEX);
80-
}
80+
@Inject
81+
private LegacySupport legacySupport;
8182

82-
@Override
83+
@Inject
84+
private ArtifactRepositoryLayout repoLayout;
85+
86+
@BeforeEach
8387
protected void setUp() throws Exception {
84-
super.setUp();
85-
artifactFactory = lookup(ArtifactFactory.class);
86-
artifactRepositoryFactory = lookup(ArtifactRepositoryFactory.class);
8788

8889
RepositorySystemSession repoSession = initRepoSession();
8990
MavenSession session = new MavenSession(
90-
getContainer(), repoSession, new DefaultMavenExecutionRequest(), new DefaultMavenExecutionResult());
91+
null, repoSession, new DefaultMavenExecutionRequest(), new DefaultMavenExecutionResult());
9192

92-
LegacySupport legacySupport = lookup(LegacySupport.class);
9393
legacySupport.setSession(session);
9494
}
9595

96-
@Override
97-
protected void tearDown() throws Exception {
98-
release(artifactFactory);
99-
100-
super.tearDown();
101-
}
102-
10396
protected abstract String component();
10497

105-
/**
106-
* Return an existing file, not a directory - causes creation to fail.
107-
*
108-
* @throws Exception
109-
*/
110-
protected ArtifactRepository badLocalRepository() throws Exception {
111-
String path = "target/test-repositories/" + component() + "/bad-local-repository";
112-
113-
File f = new File(getBasedir(), path);
114-
115-
f.createNewFile();
116-
117-
ArtifactRepositoryLayout repoLayout =
118-
(ArtifactRepositoryLayout) lookup(ArtifactRepositoryLayout.ROLE, "default");
119-
120-
return artifactRepositoryFactory.createArtifactRepository(
121-
"test", "file://" + f.getPath(), repoLayout, null, null);
122-
}
123-
124-
protected String getRepositoryLayout() {
125-
return "default";
126-
}
127-
12898
protected ArtifactRepository localRepository() throws Exception {
12999
String path = "target/test-repositories/" + component() + "/local-repository";
130100

131101
File f = new File(getBasedir(), path);
132102

133-
ArtifactRepositoryLayout repoLayout =
134-
(ArtifactRepositoryLayout) lookup(ArtifactRepositoryLayout.ROLE, "default");
135-
136103
return artifactRepositoryFactory.createArtifactRepository(
137104
"local", "file://" + f.getPath(), repoLayout, null, null);
138105
}
@@ -142,9 +109,6 @@ protected ArtifactRepository remoteRepository() throws Exception {
142109

143110
File f = new File(getBasedir(), path);
144111

145-
ArtifactRepositoryLayout repoLayout =
146-
(ArtifactRepositoryLayout) lookup(ArtifactRepositoryLayout.ROLE, "default");
147-
148112
return artifactRepositoryFactory.createArtifactRepository(
149113
"test",
150114
"file://" + f.getPath(),
@@ -154,25 +118,11 @@ protected ArtifactRepository remoteRepository() throws Exception {
154118
}
155119

156120
protected ArtifactRepository badRemoteRepository() throws Exception {
157-
ArtifactRepositoryLayout repoLayout =
158-
(ArtifactRepositoryLayout) lookup(ArtifactRepositoryLayout.ROLE, "default");
159121

160122
return artifactRepositoryFactory.createArtifactRepository(
161123
"test", "http://foo.bar/repository", repoLayout, null, null);
162124
}
163125

164-
protected void assertRemoteArtifactPresent(Artifact artifact) throws Exception {
165-
ArtifactRepository remoteRepo = remoteRepository();
166-
167-
String path = remoteRepo.pathOf(artifact);
168-
169-
File file = new File(remoteRepo.getBasedir(), path);
170-
171-
if (!file.exists()) {
172-
fail("Remote artifact " + file + " should be present.");
173-
}
174-
}
175-
176126
protected void assertLocalArtifactPresent(Artifact artifact) throws Exception {
177127
ArtifactRepository localRepo = localRepository();
178128

@@ -185,30 +135,6 @@ protected void assertLocalArtifactPresent(Artifact artifact) throws Exception {
185135
}
186136
}
187137

188-
protected void assertRemoteArtifactNotPresent(Artifact artifact) throws Exception {
189-
ArtifactRepository remoteRepo = remoteRepository();
190-
191-
String path = remoteRepo.pathOf(artifact);
192-
193-
File file = new File(remoteRepo.getBasedir(), path);
194-
195-
if (file.exists()) {
196-
fail("Remote artifact " + file + " should not be present.");
197-
}
198-
}
199-
200-
protected void assertLocalArtifactNotPresent(Artifact artifact) throws Exception {
201-
ArtifactRepository localRepo = localRepository();
202-
203-
String path = localRepo.pathOf(artifact);
204-
205-
File file = new File(localRepo.getBasedir(), path);
206-
207-
if (file.exists()) {
208-
fail("Local artifact " + file + " should not be present.");
209-
}
210-
}
211-
212138
// ----------------------------------------------------------------------
213139
//
214140
// ----------------------------------------------------------------------
@@ -241,14 +167,6 @@ protected Artifact createRemoteArtifact(String artifactId, String version) throw
241167
return artifact;
242168
}
243169

244-
protected void createLocalArtifact(Artifact artifact) throws Exception {
245-
createArtifact(artifact, localRepository());
246-
}
247-
248-
protected void createRemoteArtifact(Artifact artifact) throws Exception {
249-
createArtifact(artifact, remoteRepository());
250-
}
251-
252170
protected void createArtifact(Artifact artifact, ArtifactRepository repository) throws Exception {
253171
String path = repository.pathOf(artifact);
254172

@@ -315,11 +233,7 @@ protected RepositorySystemSession initRepoSession() throws Exception {
315233

316234
LocalRepository localRepo = new LocalRepository(localRepository().getBasedir());
317235
session.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory().newInstance(session, localRepo));
318-
try {
319-
session.setWorkspaceReader(lookup(WorkspaceReader.class, "test"));
320-
} catch (ComponentLookupException e) {
321-
// no reader, nothing to do...
322-
}
236+
session.setWorkspaceReader(new TestMavenWorkspaceReader());
323237

324238
return session;
325239
}

maven-compat/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,40 @@
1818
*/
1919
package org.apache.maven.artifact.deployer;
2020

21+
import javax.inject.Inject;
22+
2123
import java.io.File;
2224

23-
import org.apache.maven.artifact.AbstractArtifactComponentTestCase;
25+
import org.apache.maven.artifact.AbstractArtifactComponentTest;
2426
import org.apache.maven.artifact.Artifact;
2527
import org.apache.maven.artifact.repository.ArtifactRepository;
2628
import org.apache.maven.execution.MavenSession;
2729
import org.apache.maven.session.scope.internal.SessionScope;
30+
import org.codehaus.plexus.testing.PlexusTest;
2831
import org.codehaus.plexus.util.FileUtils;
32+
import org.junit.jupiter.api.Test;
2933

34+
import static org.codehaus.plexus.testing.PlexusExtension.getBasedir;
35+
import static org.junit.jupiter.api.Assertions.assertEquals;
36+
import static org.junit.jupiter.api.Assertions.assertTrue;
3037
import static org.mockito.Mockito.mock;
3138

3239
/**
3340
* @author <a href="mailto:[email protected]">Jason van Zyl</a>
3441
*/
35-
public class ArtifactDeployerTest extends AbstractArtifactComponentTestCase {
42+
@PlexusTest
43+
public class ArtifactDeployerTest extends AbstractArtifactComponentTest {
44+
@Inject
3645
private ArtifactDeployer artifactDeployer;
3746

47+
@Inject
3848
private SessionScope sessionScope;
3949

40-
protected void setUp() throws Exception {
41-
super.setUp();
42-
43-
artifactDeployer = (ArtifactDeployer) lookup(ArtifactDeployer.ROLE);
44-
45-
sessionScope = lookup(SessionScope.class);
46-
}
47-
4850
protected String component() {
4951
return "deployer";
5052
}
5153

54+
@Test
5255
public void testArtifactInstallation() throws Exception {
5356
sessionScope.enter();
5457
try {

0 commit comments

Comments
 (0)