1   /*
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2026, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v2.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
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      // https://jira.qos.ch/browse/LOGBACK-1568 would have been prevented
54      // had this silly test existed.
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  }