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