16
16
*/
17
17
package org .apache .logging .log4j .core .impl ;
18
18
19
- import static org .junit .Assert .assertEquals ;
20
- import static org .junit .Assert .assertTrue ;
19
+ import static org .junit .jupiter . api . Assertions .assertEquals ;
20
+ import static org .junit .jupiter . api . Assertions .assertTrue ;
21
21
22
22
import java .io .BufferedReader ;
23
23
import java .io .File ;
26
26
import java .nio .file .Files ;
27
27
import java .util .HashSet ;
28
28
import java .util .Set ;
29
+ import org .apache .logging .log4j .LogManager ;
29
30
import org .apache .logging .log4j .Logger ;
30
31
import org .apache .logging .log4j .core .test .CoreLoggerContexts ;
31
- import org .apache .logging .log4j .core .test .junit .LoggerContextRule ;
32
- import org .junit .Before ;
33
- import org .junit .BeforeClass ;
34
- import org .junit .Rule ;
35
- import org .junit .Test ;
32
+ import org .apache .logging .log4j .core .test .junit .LoggerContextSource ;
33
+ import org .junit .jupiter .api .BeforeAll ;
34
+ import org .junit .jupiter .api .BeforeEach ;
35
+ import org .junit .jupiter .api .Test ;
36
36
37
37
/**
38
38
* Test for LOG4J2-2368.
39
39
*/
40
+ @ LoggerContextSource ("log4j-nested-logging-throwable-message.xml" )
40
41
public class NestedLoggingFromThrowableMessageTest {
41
42
42
43
private static final File file1 = new File ("target/NestedLoggerTest1.log" );
43
44
private static final File file2 = new File ("target/NestedLoggerTest2.log" );
44
45
45
- @ BeforeClass
46
- public static void beforeClass () {
47
- file1 .delete ();
48
- file2 .delete ();
46
+ @ BeforeAll
47
+ public static void beforeAll () {
48
+ System .setProperty ("log4j2.enableThreadlocals" , "true" );
49
49
}
50
50
51
- @ Rule
52
- public LoggerContextRule context = new LoggerContextRule ("log4j-nested-logging-throwable-message.xml" );
53
-
54
51
private Logger logger ;
55
52
56
- @ Before
53
+ @ BeforeEach
57
54
public void before () {
58
- logger = context .getLogger (NestedLoggingFromThrowableMessageTest .class );
55
+ logger = LogManager .getLogger (NestedLoggingFromThrowableMessageTest .class );
59
56
}
60
57
61
58
class ThrowableLogsInGetMessage extends RuntimeException {
@@ -77,7 +74,7 @@ public void testNestedLoggingInLastArgument() throws Exception {
77
74
final Set <String > lines1 = readUniqueLines (file1 );
78
75
final Set <String > lines2 = readUniqueLines (file2 );
79
76
80
- assertEquals ("Expected the same data from both appenders" , lines1 , lines2 );
77
+ assertEquals (lines1 , lines2 , "Expected the same data from both appenders" );
81
78
assertEquals (2 , lines1 .size ());
82
79
assertTrue (lines1 .contains ("INFO NestedLoggingFromThrowableMessageTest Logging in getMessage " ));
83
80
assertTrue (lines1 .contains ("ERROR NestedLoggingFromThrowableMessageTest Test message" ));
@@ -89,7 +86,7 @@ private static Set<String> readUniqueLines(final File input) throws IOException
89
86
new BufferedReader (new InputStreamReader (Files .newInputStream (input .toPath ())))) {
90
87
String line ;
91
88
while ((line = reader .readLine ()) != null ) {
92
- assertTrue ("Read duplicate line: " + line , lines . add ( line ) );
89
+ assertTrue (lines . add ( line ), "Read duplicate line: " + line );
93
90
}
94
91
}
95
92
return lines ;
0 commit comments