1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package ch.qos.logback.classic.spi;
16
17 import java.io.PrintStream;
18
19 import org.junit.jupiter.api.AfterEach;
20 import org.junit.jupiter.api.BeforeEach;
21 import org.junit.jupiter.api.Test;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24 import org.slf4j.LoggerFactoryFriend;
25
26 import ch.qos.logback.classic.testUtil.StringPrintStream;
27
28 import static org.junit.jupiter.api.Assertions.assertEquals;
29 import static org.junit.jupiter.api.Assertions.assertTrue;
30 import static org.slf4j.helpers.Reporter.SLF4J_INTERNAL_VERBOSITY_KEY;
31
32 public class InvocationTest {
33
34 private final PrintStream oldErr = System.err;
35 final String loggerName = this.getClass().getName();
36 StringPrintStream sps = new StringPrintStream(oldErr, true);
37
38 String CONNECTED_WITH_MESSAGE = "SLF4J(D): Connected with provider of type [ch.qos.logback.classic.spi.LogbackServiceProvider]";
39
40 @BeforeEach
41 public void setUp() throws Exception {
42 System.setProperty(SLF4J_INTERNAL_VERBOSITY_KEY, "debug");
43 System.setErr(sps);
44 }
45
46 @AfterEach
47 public void tearDown() throws Exception {
48 LoggerFactoryFriend.reset();
49 System.setErr(oldErr);
50 System.clearProperty(SLF4J_INTERNAL_VERBOSITY_KEY);
51 }
52
53
54
55 @Test
56 public void smoke() {
57 Logger logger = LoggerFactory.getLogger(this.getClass());
58 logger.debug("Hello world.");
59
60 assertEquals(1, sps.stringList.size());
61 assertEquals(CONNECTED_WITH_MESSAGE, sps.stringList.get(0));
62
63 }
64
65 }