View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, 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 v1.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  package ch.qos.logback.classic.util;
15  
16  import ch.qos.logback.classic.ClassicConstants;
17  import ch.qos.logback.classic.Logger;
18  import ch.qos.logback.classic.LoggerContext;
19  import ch.qos.logback.classic.spi.ILoggingEvent;
20  import ch.qos.logback.core.Appender;
21  import ch.qos.logback.core.ConsoleAppender;
22  import ch.qos.logback.core.CoreConstants;
23  import org.junit.jupiter.api.AfterEach;
24  import org.junit.jupiter.api.BeforeEach;
25  import org.junit.jupiter.api.Disabled;
26  import org.junit.jupiter.api.Test;
27  import org.slf4j.LoggerFactory;
28  
29  import static org.junit.jupiter.api.Assertions.assertNotNull;
30  import static org.junit.jupiter.api.Assertions.assertTrue;
31  
32  public class ContextInitializerAutoConfigTest {
33  
34      org.slf4j.Logger logger = LoggerFactory.getLogger(this.getClass());
35      Logger root = (Logger) LoggerFactory.getLogger("root");
36  
37      @BeforeEach
38      public void setUp() throws Exception {
39          logger.debug("Hello-didily-odily");
40      }
41  
42      @AfterEach
43      public void tearDown() throws Exception {
44          System.clearProperty(ClassicConstants.CONFIG_FILE_PROPERTY);
45          System.clearProperty(CoreConstants.STATUS_LISTENER_CLASS_KEY);
46      }
47  
48      @Test
49      @Disabled
50      // this test works only if logback-test.xml or logback.xml files are on the
51      // classpath.
52      // However, this is something we try to avoid in order to simplify the life
53      // of users trying to follow the manual and logback-examples from an IDE
54      public void autoconfig() {
55          LoggerContext iLoggerFactory = (LoggerContext) LoggerFactory.getILoggerFactory();
56          iLoggerFactory.reset();
57          Appender<ILoggingEvent> appender = root.getAppender("STDOUT");
58          assertNotNull(appender);
59          assertTrue(appender instanceof ConsoleAppender);
60      }
61  }