Skip to content

Commit 5534fd6

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

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-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: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import java.util.jar.JarEntry;
3535
import java.util.jar.JarInputStream;
3636
import java.util.jar.JarOutputStream;
37+
import java.util.stream.Stream;
38+
3739
import org.apache.commons.io.IOUtils;
3840
import org.apache.logging.log4j.core.config.plugins.processor.PluginCache;
3941
import org.apache.logging.log4j.core.config.plugins.processor.PluginEntry;
@@ -42,6 +44,9 @@
4244
import org.junit.jupiter.api.AfterAll;
4345
import org.junit.jupiter.api.BeforeAll;
4446
import org.junit.jupiter.api.Test;
47+
import org.junit.jupiter.params.ParameterizedTest;
48+
import org.junit.jupiter.params.provider.Arguments;
49+
import org.junit.jupiter.params.provider.MethodSource;
4550

4651
final class Log4j2PluginCacheFileTransformerTest {
4752

@@ -110,16 +115,9 @@ private void assertTransformedCacheFile(
110115
}
111116
}
112117

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 {
118+
@ParameterizedTest
119+
@MethodSource("relocationParameters")
120+
public void testRelocation(final String src, final String pattern, final String target) throws IOException {
123121
final Log4j2PluginCacheFileTransformer transformer = new Log4j2PluginCacheFileTransformer();
124122
final Relocator log4jRelocator = new SimpleRelocator(src, pattern, null, null);
125123
final PluginCache aggregator = new PluginCache();
@@ -135,6 +133,15 @@ private void testRelocation(final String src, final String pattern, final String
135133
}
136134
}
137135

136+
private static Stream<Arguments> relocationParameters() {
137+
return Stream.of(
138+
// test with matching relocator
139+
Arguments.of("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+
}
144+
138145
@AfterAll
139146
public static void tearDown() {
140147
pluginUrl = null;

0 commit comments

Comments
 (0)