001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package org.slf4j.impl;
015
016import static org.junit.Assert.assertEquals;
017
018import java.io.PrintStream;
019
020import org.junit.After;
021import org.junit.Before;
022import org.junit.Test;
023import org.slf4j.LoggerFactoryFriend;
024
025import ch.qos.logback.classic.ClassicConstants;
026import ch.qos.logback.classic.ClassicTestConstants;
027import ch.qos.logback.core.CoreConstants;
028import ch.qos.logback.core.status.NopStatusListener;
029import ch.qos.logback.core.testUtil.RandomUtil;
030import ch.qos.logback.core.testUtil.TeeOutputStream;
031
032/**
033 * @author Ceki Gülcü
034 */
035public class InitializationOutputTest {
036
037    int diff = RandomUtil.getPositiveInt();
038
039    TeeOutputStream tee;
040    PrintStream original;
041
042    @Before
043    public void setUp() {
044        original = System.out;
045        // tee will output bytes on System out but it will also
046        // collect them so that the output can be compared against
047        // some expected output data
048
049        // keep the console quiet
050        tee = new TeeOutputStream(null);
051
052        // redirect System.out to tee
053        System.setOut(new PrintStream(tee));
054    }
055
056    @After
057    public void tearDown() {
058        System.setOut(original);
059        System.clearProperty(ClassicConstants.CONFIG_FILE_PROPERTY);
060        System.clearProperty(CoreConstants.STATUS_LISTENER_CLASS_KEY);
061    }
062
063    @Test
064    public void noOutputIfContextHasAStatusListener() {
065        System.setProperty(ClassicConstants.CONFIG_FILE_PROPERTY, ClassicTestConstants.INPUT_PREFIX + "issue/logback292.xml");
066        System.setProperty(CoreConstants.STATUS_LISTENER_CLASS_KEY, NopStatusListener.class.getName());
067
068        LoggerFactoryFriend.reset();
069        assertEquals(0, tee.baos.size());
070    }
071
072}