Skip to content

Commit b748fa0

Browse files
committed
Optimize testRelocation with parameterized test
1 parent 8d6538a commit b748fa0

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

log4j-transform-maven-shade-plugin-extensions/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@
6262
<scope>test</scope>
6363
</dependency>
6464

65+
<dependency>
66+
<groupId>org.junit.jupiter</groupId>
67+
<artifactId>junit-jupiter-params</artifactId>
68+
<scope>test</scope>
69+
</dependency>
70+
6571
<dependency>
6672
<groupId>org.osgi</groupId>
6773
<artifactId>osgi.annotation</artifactId>

log4j-transform-maven-shade-plugin-extensions/src/test/java/org/apache/logging/log4j/maven/plugins/shade/transformer/Log4j2PluginCacheFileTransformerTest.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.util.jar.JarEntry;
3535
import java.util.jar.JarInputStream;
3636
import java.util.jar.JarOutputStream;
37+
import java.util.stream.Stream;
3738
import org.apache.commons.io.IOUtils;
3839
import org.apache.logging.log4j.core.config.plugins.processor.PluginCache;
3940
import org.apache.logging.log4j.core.config.plugins.processor.PluginEntry;
@@ -42,6 +43,9 @@
4243
import org.junit.jupiter.api.AfterAll;
4344
import org.junit.jupiter.api.BeforeAll;
4445
import org.junit.jupiter.api.Test;
46+
import org.junit.jupiter.params.ParameterizedTest;
47+
import org.junit.jupiter.params.provider.Arguments;
48+
import org.junit.jupiter.params.provider.MethodSource;
4549

4650
final class Log4j2PluginCacheFileTransformerTest {
4751

@@ -110,16 +114,9 @@ private void assertTransformedCacheFile(
110114
}
111115
}
112116

113-
@Test
114-
public void testRelocation() throws IOException {
115-
// test with matching relocator
116-
testRelocation("org.apache.logging", "new.location.org.apache.logging", "new.location.org.apache.logging");
117-
118-
// test without matching relocator
119-
testRelocation("com.apache.logging", "new.location.com.apache.logging", "org.apache.logging");
120-
}
121-
122-
private void testRelocation(final String src, final String pattern, final String target) throws IOException {
117+
@ParameterizedTest
118+
@MethodSource("relocationParameters")
119+
public void testRelocation(final String src, final String pattern, final String target) throws IOException {
123120
final Log4j2PluginCacheFileTransformer transformer = new Log4j2PluginCacheFileTransformer();
124121
final Relocator log4jRelocator = new SimpleRelocator(src, pattern, null, null);
125122
final PluginCache aggregator = new PluginCache();
@@ -135,6 +132,15 @@ private void testRelocation(final String src, final String pattern, final String
135132
}
136133
}
137134

135+
private static Stream<Arguments> relocationParameters() {
136+
return Stream.of(
137+
// test with matching relocator
138+
Arguments.of(
139+
"org.apache.logging", "new.location.org.apache.logging", "new.location.org.apache.logging"),
140+
// test without matching relocator
141+
Arguments.of("com.apache.logging", "new.location.com.apache.logging", "org.apache.logging"));
142+
}
143+
138144
@AfterAll
139145
public static void tearDown() {
140146
pluginUrl = null;

0 commit comments

Comments
 (0)