-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
InitializationOutputTest.java
72 lines (58 loc) · 2.12 KB
/
InitializationOutputTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* Logback: the reliable, generic, fast and flexible logging framework.
* Copyright (C) 1999-2015, QOS.ch. All rights reserved.
*
* This program and the accompanying materials are dual-licensed under
* either the terms of the Eclipse Public License v1.0 as published by
* the Eclipse Foundation
*
* or (per the licensee's choosing)
*
* under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation.
*/
package org.slf4j.impl;
import static org.junit.Assert.assertEquals;
import java.io.PrintStream;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.LoggerFactoryFriend;
import ch.qos.logback.classic.ClassicConstants;
import ch.qos.logback.classic.ClassicTestConstants;
import ch.qos.logback.core.CoreConstants;
import ch.qos.logback.core.status.NopStatusListener;
import ch.qos.logback.core.testUtil.RandomUtil;
import ch.qos.logback.core.testUtil.TeeOutputStream;
/**
* @author Ceki Gülcü
*/
public class InitializationOutputTest {
int diff = RandomUtil.getPositiveInt();
TeeOutputStream tee;
PrintStream original;
@Before
public void setUp() {
original = System.out;
// tee will output bytes on System out but it will also
// collect them so that the output can be compared against
// some expected output data
// keep the console quiet
tee = new TeeOutputStream(null);
// redirect System.out to tee
System.setOut(new PrintStream(tee));
}
@After
public void tearDown() {
System.setOut(original);
System.clearProperty(ClassicConstants.CONFIG_FILE_PROPERTY);
System.clearProperty(CoreConstants.STATUS_LISTENER_CLASS_KEY);
}
@Test
public void noOutputIfContextHasAStatusListener() {
System.setProperty(ClassicConstants.CONFIG_FILE_PROPERTY, ClassicTestConstants.INPUT_PREFIX + "issue/logback292.xml");
System.setProperty(CoreConstants.STATUS_LISTENER_CLASS_KEY, NopStatusListener.class.getName());
LoggerFactoryFriend.reset();
assertEquals(0, tee.baos.size());
}
}