Skip to content

Commit b163f86

Browse files
committed
refactor(1.2-api): migrate to junit5
1 parent ccd5e89 commit b163f86

File tree

7 files changed

+16
-40
lines changed

7 files changed

+16
-40
lines changed

log4j-1.2-api/src/test/java/org/apache/log4j/CallerInformationTest.java

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

2121
import java.util.List;
2222
import org.apache.logging.log4j.core.test.appender.ListAppender;
23-
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
2423
import org.apache.logging.log4j.core.test.junit.Named;
24+
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
2525
import org.junit.jupiter.api.Test;
2626

2727
// config from log4j-core test-jar
28-
@LoggerContextSource(value = "log4j2-calling-class.xml", timeout = 10)
28+
@LoggerContextSource(value = "log4j2-calling-class.xml")
2929
public class CallerInformationTest {
3030

3131
@Test

log4j-1.2-api/src/test/java/org/apache/log4j/NDCTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.util.Stack;
2222
import org.apache.logging.log4j.util.Strings;
23+
import static org.junit.jupiter.api.Assertions.assertEquals;
2324
import org.junit.jupiter.api.Test;
2425

2526
public class NDCTest {

log4j-1.2-api/src/test/java/org/apache/log4j/config/AbstractLog4j1ConfigurationConverterTest.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,11 @@
2929
import java.util.List;
3030
import javax.xml.parsers.DocumentBuilderFactory;
3131
import javax.xml.parsers.ParserConfigurationException;
32+
import org.junit.jupiter.api.Test;
33+
import org.junit.runner.RunWith;
34+
import org.junit.runners.Parameterized;
3235
import org.xml.sax.SAXException;
33-
// import org.junit.jupiter.params.ParameterizedTest;
34-
// import org.junit.jupiter.params.provider.MethodSource;
3536

36-
// import org.junit.runner.RunWith;
37-
// import org.junit.runners.Parameterized;
3837

3938
public abstract class AbstractLog4j1ConfigurationConverterTest {
4039

@@ -50,20 +49,15 @@ public FileVisitResult visitFile(final Path file, final BasicFileAttributes attr
5049
return paths;
5150
}
5251

53-
protected final Path pathIn;
52+
public AbstractLog4j1ConfigurationConverterTest() {}
5453

55-
public AbstractLog4j1ConfigurationConverterTest(final Path path) {
56-
this.pathIn = path;
57-
}
58-
59-
// @ParameterizedTest
60-
// @MethodSource("data")
61-
public void test(final Path path) throws Exception {
54+
@Test
55+
public void test(Path path) throws Exception {
6256
final Path tempFile = Files.createTempFile("log4j2", ".xml");
6357
try {
6458
final Log4j1ConfigurationConverter.CommandLineArguments cla =
6559
new Log4j1ConfigurationConverter.CommandLineArguments();
66-
cla.setPathIn(pathIn);
60+
cla.setPathIn(path);
6761
cla.setPathOut(tempFile);
6862
Log4j1ConfigurationConverter.run(cla);
6963
checkWellFormedXml(tempFile);

log4j-1.2-api/src/test/java/org/apache/log4j/config/AbstractLog4j1ConfigurationTest.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -481,22 +481,18 @@ public void testMultipleFilters() throws Exception {
481481

482482
try (final LoggerContext loggerContext = configure("log4j-multipleFilters")) {
483483
final Configuration configuration = loggerContext.getConfiguration();
484-
System.out.println("#############" + configuration);
485484

486485
assertNotNull(configuration);
487486

488487
// Check only number of filters.
489488
final Filterable console = configuration.getAppender("CONSOLE");
490-
System.out.println("############# console.getFilter" + console.getFilter());
491489
assertNotNull(console);
492490
assertEquals(4, checkFilters(console.getFilter()));
493491
final Filterable file = configuration.getAppender("FILE");
494492
assertNotNull(file);
495-
System.out.println("############# file.getFilter" + file.getFilter());
496493
assertEquals(4, checkFilters(file.getFilter()));
497494
final Filterable rfa = configuration.getAppender("RFA");
498495
assertNotNull(rfa);
499-
System.out.println("############# rfa.getFilter" + rfa.getFilter());
500496
assertEquals(4, checkFilters(rfa.getFilter()));
501497
final Filterable drfa = configuration.getAppender("DRFA");
502498
assertNotNull(drfa);
@@ -508,7 +504,6 @@ public void testMultipleFilters() throws Exception {
508504
final ListAppender legacyAppender = (ListAppender) ((Adapter) appender).getAppender();
509505
final org.apache.logging.log4j.core.test.appender.ListAppender nativeAppender =
510506
configuration.getAppender("LIST2");
511-
System.out.println("############# list2appender.getFilter " + nativeAppender.getFilter());
512507
assertEquals(3, checkFilters(((Filterable) nativeAppender).getFilter()));
513508

514509
final Logger logger = LogManager.getLogger(PropertiesConfigurationTest.class);
@@ -529,11 +524,6 @@ public void testMultipleFilters() throws Exception {
529524
// message accepted by "StartsWith" filter
530525
logger.warn("ACCEPT message");
531526
expected++;
532-
System.out.println("#############expected" + expected);
533-
System.out.println("#############legacyAppender.getEvents().size()"
534-
+ legacyAppender.getEvents().size());
535-
System.out.println("#############nativeAppender.getEvents().size()"
536-
+ nativeAppender.getEvents().size());
537527
assertEquals(expected, legacyAppender.getEvents().size());
538528
assertEquals(expected, nativeAppender.getEvents().size());
539529
// message blocked by "StartsWith" filter

log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationConverterHadoopTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,16 @@
2424

2525
public class Log4j1ConfigurationConverterHadoopTest extends AbstractLog4j1ConfigurationConverterTest {
2626

27-
// @Parameterized.Parameters(name = "{0}")
2827
public static List<Path> data() throws IOException {
2928
return getPaths("src/test/resources/config-1.2/hadoop");
3029
}
3130

32-
public Log4j1ConfigurationConverterHadoopTest(final Path path) {
33-
super(path);
31+
public Log4j1ConfigurationConverterHadoopTest() {
32+
super();
3433
}
3534

36-
// ParameterizedTest replacing the JUnit 4 @Test in abstract class
3735
@ParameterizedTest
3836
@MethodSource("data")
39-
// @Override
4037
public void test(Path path) throws Exception {
4138
super.test(path);
4239
}

log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationConverterSparkTest.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,21 @@
1919
import java.io.IOException;
2020
import java.nio.file.Path;
2121
import java.util.List;
22-
import org.junit.jupiter.params.ParameterizedTest;
2322
import org.junit.jupiter.params.provider.MethodSource;
23+
import org.junit.jupiter.params.ParameterizedTest;
2424

25-
// import org.junit.runner.RunWith;
26-
// import org.junit.runners.Parameterized;
27-
28-
// @RunWith(Parameterized.class)
2925
public class Log4j1ConfigurationConverterSparkTest extends AbstractLog4j1ConfigurationConverterTest {
3026

3127
public static List<Path> data() throws IOException {
3228
return getPaths("src/test/resources/config-1.2/spark");
3329
}
3430

35-
public Log4j1ConfigurationConverterSparkTest(final Path path) {
36-
super(path);
31+
public Log4j1ConfigurationConverterSparkTest() {
32+
super();
3733
}
3834

39-
// ParameterizedTest replacing the JUnit 4 @Test in abstract class
4035
@ParameterizedTest
4136
@MethodSource("data")
42-
// @Override
4337
public void test(Path path) throws Exception {
4438
super.test(path);
4539
}

log4j-1.2-api/src/test/java/org/apache/log4j/helpers/CyclicBufferTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public void test0() {
106106
final int size = 2;
107107

108108
CyclicBuffer cb = new CyclicBuffer(size);
109-
assertEquals(cb.getMaxSize(), size);
109+
assertEquals(size, cb.getMaxSize());
110110

111111
cb.add(e[0]);
112112
assertEquals(cb.length(), 1);

0 commit comments

Comments
 (0)