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 org.slf4j.impl;
15  
16  import static org.junit.Assert.assertEquals;
17  
18  import java.io.PrintStream;
19  
20  import org.junit.After;
21  import org.junit.Before;
22  import org.junit.Test;
23  import org.slf4j.LoggerFactoryFriend;
24  
25  import ch.qos.logback.classic.ClassicConstants;
26  import ch.qos.logback.classic.ClassicTestConstants;
27  import ch.qos.logback.core.CoreConstants;
28  import ch.qos.logback.core.status.NopStatusListener;
29  import ch.qos.logback.core.testUtil.RandomUtil;
30  import ch.qos.logback.core.testUtil.TeeOutputStream;
31  
32  /**
33   * @author Ceki Gülcü
34   */
35  public class InitializationOutputTest {
36  
37      int diff = RandomUtil.getPositiveInt();
38  
39      TeeOutputStream tee;
40      PrintStream original;
41  
42      @Before
43      public void setUp() {
44          original = System.out;
45          // tee will output bytes on System out but it will also
46          // collect them so that the output can be compared against
47          // some expected output data
48  
49          // keep the console quiet
50          tee = new TeeOutputStream(null);
51  
52          // redirect System.out to tee
53          System.setOut(new PrintStream(tee));
54      }
55  
56      @After
57      public void tearDown() {
58          System.setOut(original);
59          System.clearProperty(ClassicConstants.CONFIG_FILE_PROPERTY);
60          System.clearProperty(CoreConstants.STATUS_LISTENER_CLASS_KEY);
61      }
62  
63      @Test
64      public void noOutputIfContextHasAStatusListener() {
65          System.setProperty(ClassicConstants.CONFIG_FILE_PROPERTY, 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  }