1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.slf4j.implTest;
15
16 import ch.qos.logback.classic.ClassicConstants;
17 import ch.qos.logback.classic.ClassicTestConstants;
18 import ch.qos.logback.core.CoreConstants;
19 import ch.qos.logback.core.status.NopStatusListener;
20 import ch.qos.logback.core.testUtil.RandomUtil;
21 import ch.qos.logback.core.testUtil.TeeOutputStream;
22 import org.junit.jupiter.api.AfterEach;
23 import org.junit.jupiter.api.BeforeEach;
24 import org.junit.jupiter.api.Test;
25 import org.slf4j.LoggerFactoryFriend;
26
27 import java.io.PrintStream;
28
29 import static org.junit.jupiter.api.Assertions.assertEquals;
30
31
32
33
34 public class InitializationOutputTest {
35
36 int diff = RandomUtil.getPositiveInt();
37
38 TeeOutputStream tee;
39 PrintStream original;
40
41 @BeforeEach
42 public void setUp() {
43 original = System.out;
44
45
46
47
48
49 tee = new TeeOutputStream(null);
50
51
52 System.setOut(new PrintStream(tee));
53 }
54
55 @AfterEach
56 public void tearDown() {
57 System.setOut(original);
58 System.clearProperty(ClassicConstants.CONFIG_FILE_PROPERTY);
59 System.clearProperty(CoreConstants.STATUS_LISTENER_CLASS_KEY);
60 }
61
62 @Test
63 public void noOutputIfContextHasAStatusListener() {
64 System.setProperty(ClassicConstants.CONFIG_FILE_PROPERTY,
65 ClassicTestConstants.INPUT_PREFIX + "issue/logback292.xml");
66 System.setProperty(CoreConstants.STATUS_LISTENER_CLASS_KEY, NopStatusListener.class.getName());
67
68 LoggerFactoryFriend.reset();
69 assertEquals(0, tee.baos.size());
70 }
71
72 }