16
16
*/
17
17
package org .apache .logging .log4j .jcl ;
18
18
19
- import static org .assertj .core .api .Assertions .assertThat ;
20
-
21
- import java .util .List ;
22
19
import org .apache .commons .logging .Log ;
23
20
import org .apache .commons .logging .LogFactory ;
24
21
import org .apache .logging .log4j .core .LoggerContext ;
25
22
import org .apache .logging .log4j .core .test .appender .ListAppender ;
26
- import org .apache .logging .log4j .test .junit .SetTestProperty ;
27
- import org .apache .logging .log4j .test .junit .UsingStatusListener ;
23
+ import org .apache .logging .log4j .core .test .junit .LoggerContextSource ;
28
24
import org .apache .logging .log4j .util .Strings ;
29
25
import org .junit .jupiter .api .Test ;
30
26
31
- @ UsingStatusListener
32
- @ SetTestProperty (key = "log4j2.configurationFile" , value = "org/apache/logging/log4j/jcl/LoggerTest.xml" )
27
+ import java .util .List ;
28
+
29
+ import static org .assertj .core .api .Assertions .assertThat ;
30
+
33
31
class LoggerTest {
34
32
35
33
@ Test
@@ -39,21 +37,21 @@ void testFactory() {
39
37
}
40
38
41
39
@ Test
42
- void testLog () {
40
+ @ LoggerContextSource ("LoggerTest.xml" )
41
+ void testLog (final LoggerContext context ) {
43
42
final Log logger = LogFactory .getLog ("LoggerTest" );
44
43
logger .debug ("Test message" );
45
- verify ("List" , "o.a.l.l.j.LoggerTest Test message MDC{}" + Strings .LINE_SEPARATOR );
44
+ verify (context , "o.a.l.l.j.LoggerTest Test message MDC{}" + Strings .LINE_SEPARATOR );
46
45
logger .debug ("Exception: " , new NullPointerException ("Test" ));
47
- verify ("List" , "o.a.l.l.j.LoggerTest Exception: MDC{}" + Strings .LINE_SEPARATOR );
46
+ verify (context , "o.a.l.l.j.LoggerTest Exception: MDC{}" + Strings .LINE_SEPARATOR );
48
47
logger .info ("Info Message" );
49
- verify ("List" , "o.a.l.l.j.LoggerTest Info Message MDC{}" + Strings .LINE_SEPARATOR );
48
+ verify (context , "o.a.l.l.j.LoggerTest Info Message MDC{}" + Strings .LINE_SEPARATOR );
50
49
logger .info ("Info Message {}" );
51
- verify ("List" , "o.a.l.l.j.LoggerTest Info Message {} MDC{}" + Strings .LINE_SEPARATOR );
50
+ verify (context , "o.a.l.l.j.LoggerTest Info Message {} MDC{}" + Strings .LINE_SEPARATOR );
52
51
}
53
52
54
- private void verify (final String name , final String expected ) {
55
- final LoggerContext context = LoggerContext .getContext (false );
56
- final ListAppender listApp = context .getConfiguration ().getAppender (name );
53
+ private static void verify (final LoggerContext context , final String expected ) {
54
+ final ListAppender listApp = context .getConfiguration ().getAppender ("List" );
57
55
final List <String > events = listApp .getMessages ();
58
56
assertThat (events ).hasSize (1 ).containsExactly (expected );
59
57
listApp .clear ();
0 commit comments