Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 942d6b3

Browse files
Migrate Maven instrumentation and Utf8Cache tests to JUnit 5 (#9568)
1 parent 56fa28c commit 942d6b3

File tree

8 files changed

+168
-119
lines changed

8 files changed

+168
-119
lines changed
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ public abstract class AbstractMavenTest {
2020

2121
protected AbstractMavenTest() {
2222
System.setProperty(
23-
"maven.multiModuleProjectDirectory",
24-
WORKING_DIRECTORY.getRoot().toAbsolutePath().toString());
23+
"maven.multiModuleProjectDirectory", WORKING_DIRECTORY.toAbsolutePath().toString());
2524
}
2625

2726
protected void executeMaven(
@@ -58,8 +57,7 @@ protected void customizeContainer(PlexusContainer container) {
5857
arguments[2] = goal;
5958
System.arraycopy(additionalArgs, 0, arguments, 3, additionalArgs.length);
6059

61-
mavenCli.doMain(
62-
arguments, WORKING_DIRECTORY.getRoot().toAbsolutePath().toString(), stdOut, stderr);
60+
mavenCli.doMain(arguments, WORKING_DIRECTORY.toAbsolutePath().toString(), stdOut, stderr);
6361

6462
Exception error = spy.handlerError.get();
6563
if (error != null) {
Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package datadog.trace.instrumentation.maven3;
22

3-
import static org.junit.Assert.assertTrue;
3+
import static org.junit.jupiter.api.Assertions.assertTrue;
44
import static org.mockito.Mockito.mock;
55
import static org.mockito.Mockito.when;
66

@@ -12,54 +12,42 @@
1212
import java.io.InputStreamReader;
1313
import java.io.PrintStream;
1414
import java.net.URISyntaxException;
15-
import java.util.Arrays;
16-
import java.util.Collection;
1715
import java.util.Collections;
16+
import java.util.stream.Stream;
1817
import org.apache.maven.execution.ExecutionEvent;
1918
import org.apache.maven.execution.MavenSession;
2019
import org.apache.maven.plugin.MojoExecution;
2120
import org.apache.maven.project.MavenProject;
22-
import org.junit.Test;
23-
import org.junit.runner.RunWith;
24-
import org.junit.runners.Parameterized;
21+
import org.junit.jupiter.params.ParameterizedTest;
22+
import org.junit.jupiter.params.provider.Arguments;
23+
import org.junit.jupiter.params.provider.MethodSource;
2524
import org.slf4j.Logger;
2625
import org.slf4j.LoggerFactory;
2726

28-
@RunWith(Parameterized.class)
2927
public class MavenProjectConfiguratorTest extends AbstractMavenTest {
3028

3129
private static final Logger LOGGER = LoggerFactory.getLogger(MavenProjectConfiguratorTest.class);
3230

33-
@Parameterized.Parameters(name = "{0} - {1}")
34-
public static Collection<Object[]> surefireVersions() {
35-
return Arrays.asList(
36-
new Object[][] {
37-
{"sampleProject/pom.xml", "test", new String[] {"-X", "-DargLine=-DmyArgLineProp=true"}},
38-
{
31+
public static Stream<Arguments> surefireVersions() {
32+
return Stream.of(
33+
Arguments.of(
34+
"sampleProject/pom.xml", "test", new String[] {"-X", "-DargLine=-DmyArgLineProp=true"}),
35+
Arguments.of(
3936
"sampleProject/pom.xml",
4037
"surefire:test",
41-
new String[] {"-X", "-DargLine=-DmyArgLineProp=true"}
42-
},
43-
{"sampleProjectArgLine/pom.xml", "test", new String[] {"-X"}},
44-
{"sampleProjectArgLine/pom.xml", "surefire:test", new String[] {"-X"}},
45-
{"sampleProjectSurefireArgLine/pom.xml", "test", new String[] {"-X"}},
46-
{"sampleProjectSurefireArgLine/pom.xml", "surefire:test", new String[] {"-X"}},
47-
{"sampleProjectSurefireLateProcessingArgLine/pom.xml", "test", new String[] {"-X"}},
48-
});
38+
new String[] {"-X", "-DargLine=-DmyArgLineProp=true"}),
39+
Arguments.of("sampleProjectArgLine/pom.xml", "test", new String[] {"-X"}),
40+
Arguments.of("sampleProjectArgLine/pom.xml", "surefire:test", new String[] {"-X"}),
41+
Arguments.of("sampleProjectSurefireArgLine/pom.xml", "test", new String[] {"-X"}),
42+
Arguments.of("sampleProjectSurefireArgLine/pom.xml", "surefire:test", new String[] {"-X"}),
43+
Arguments.of(
44+
"sampleProjectSurefireLateProcessingArgLine/pom.xml", "test", new String[] {"-X"}));
4945
}
5046

51-
private final String pomPath;
52-
private final String goal;
53-
private final String[] additionalCmdLineArgs;
54-
55-
public MavenProjectConfiguratorTest(String pomPath, String goal, String[] additionalCmdLineArgs) {
56-
this.pomPath = pomPath;
57-
this.goal = goal;
58-
this.additionalCmdLineArgs = additionalCmdLineArgs;
59-
}
60-
61-
@Test
62-
public void testTracerInjection() throws Exception {
47+
@ParameterizedTest
48+
@MethodSource("surefireVersions")
49+
public void testTracerInjection(String pomPath, String goal, String[] additionalCmdLineArgs)
50+
throws Exception {
6351
ByteArrayOutputStream stdOutBaos = new ByteArrayOutputStream();
6452
PrintStream buildOutput = new PrintStream(stdOutBaos);
6553

@@ -85,8 +73,8 @@ public void testTracerInjection() throws Exception {
8573
&& buildOutputLine.contains("-DmyArgLineProp=true");
8674
}
8775

88-
assertTrue("Tracer wasn't injected", javaAgentInjected);
89-
assertTrue("Original argLine was not preserved", argLinePreserved);
76+
assertTrue(javaAgentInjected, "Tracer wasn't injected");
77+
assertTrue(argLinePreserved, "Original argLine was not preserved");
9078

9179
} catch (Exception | Error e) {
9280
LOGGER.info("Build output:\n\n" + stdOutBaos);

0 commit comments

Comments
 (0)