// Path: sysout-over-slf4j-context/src/test/java/uk/org/lidalia/sysoutslf4j/SysOutOverSLF4JTestCase.java
// public abstract class SysOutOverSLF4JTestCase {
// 
//     protected ClassLoader originalContextClassLoader;
//     protected PrintStream SYS_OUT;
//     protected PrintStream SYS_ERR;
// 
//     @Before
//     public void resetLoggers() {
//         TestLoggerFactory.clearAll();
//     }
// 
//     @Before
//     public void storeOriginalSystemOutAndErr() {
//         SYS_OUT = System.out;
//         SYS_ERR = System.err;
//     }
// 
//     @After
//     public void restoreOriginalSystemOutAndErr() {
//         System.setOut(SYS_OUT);
//         System.setErr(SYS_ERR);
//     }
// 
//     @Before
//     public void storeOriginalContextClassLoader() {
//         originalContextClassLoader = Thread.currentThread().getContextClassLoader();
//     }
// 
//     @After
//     public void restoreOriginalContextClassLoader() {
//         Thread.currentThread().setContextClassLoader(originalContextClassLoader);
//     }
// }
// 
// Path: sysout-over-slf4j-context/src/main/java/uk/org/lidalia/sysoutslf4j/context/exceptionhandlers/ExceptionHandlingStrategy.java
// public interface ExceptionHandlingStrategy {
// 
//     /**
//      * Called for each line of the stack trace as sent to the System.out/err PrintStream.
//      *
//      * @param line The stacktrace line
//      * @param log The {@link org.slf4j.Logger} with a name matching the fully qualified name of the
//      *                 class where printStacktrace was called
//      */
//     void handleExceptionLine(String line, Logger log);
// 
//     /**
//      * Called whenever any other calls are intercepted by sysout-over-slf4j
//      * - may be a useful trigger for flushing a buffer.
//      */
//     void notifyNotStackTrace();
// }


import java.io.PrintStream;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
import org.slf4j.Logger;
import uk.org.lidalia.slf4jtest.TestLogger;
import uk.org.lidalia.slf4jtest.TestLoggerFactory;
import uk.org.lidalia.slf4jext.Level;
import uk.org.lidalia.sysoutslf4j.SysOutOverSLF4JTestCase;
import uk.org.lidalia.sysoutslf4j.context.exceptionhandlers.ExceptionHandlingStrategy;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.powermock.api.mockito.PowerMockito.mock;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
import static org.powermock.api.mockito.PowerMockito.when;
import static uk.org.lidalia.slf4jtest.LoggingEvent.info;
import static uk.org.lidalia.slf4jtest.LoggingEvent.warn;
    private PrintStream origPrintStreamMock = mock(PrintStream.class);
    private LoggingSystemRegister loggingSystemRegisterMock = mock(LoggingSystemRegister.class);
    private LoggingOutputStream outputStream = new LoggingOutputStream(level, exceptionHandlingStrategyMock, origPrintStreamMock, loggingSystemRegisterMock);
    private TestLogger logger = TestLoggerFactory.getTestLogger(CLASS_NAME);

    @Before
    public void setUp() {
        mockGettingCallOrigin(false, false, CLASS_NAME);
    }

    @Test
    public void flushLogsWhenMessageEndsWithUnixLineBreak() throws Exception {
        outputStream.write("the message\n".getBytes("UTF-8"));
        outputStream.flush();
        assertEquals(asList(info("the message")), logger.getLoggingEvents());
    }

    @Test
    public void flushLogsWhenMessageEndsWithWindowsLineBreak() throws Exception {
        outputStream.write("the message\r\n".getBytes("UTF-8"));
        outputStream.flush();
        assertEquals(asList(info("the message")), logger.getLoggingEvents());
    }

    @Test
    public void flushWritesToOriginalPrintStreamIfInLoggingSystem() throws Exception {
        mockGettingCallOrigin(false, true, CLASS_IN_LOGGING_SYSTEM);

        byte[] bytes = "twelve chars".getBytes("UTF-8");
        outputStream.write(bytes);
// Path: sysout-over-slf4j-context/src/test/java/uk/org/lidalia/sysoutslf4j/SysOutOverSLF4JTestCase.java
// public abstract class SysOutOverSLF4JTestCase {
// 
//     protected ClassLoader originalContextClassLoader;
//     protected PrintStream SYS_OUT;
//     protected PrintStream SYS_ERR;
// 
//     @Before
//     public void resetLoggers() {
//         TestLoggerFactory.clearAll();
//     }
// 
//     @Before
//     public void storeOriginalSystemOutAndErr() {
//         SYS_OUT = System.out;
//         SYS_ERR = System.err;
//     }
// 
//     @After
//     public void restoreOriginalSystemOutAndErr() {
//         System.setOut(SYS_OUT);
//         System.setErr(SYS_ERR);
//     }
// 
//     @Before
//     public void storeOriginalContextClassLoader() {
//         originalContextClassLoader = Thread.currentThread().getContextClassLoader();
//     }
// 
//     @After
//     public void restoreOriginalContextClassLoader() {
//         Thread.currentThread().setContextClassLoader(originalContextClassLoader);
//     }
// }
// 
// Path: sysout-over-slf4j-context/src/main/java/uk/org/lidalia/sysoutslf4j/context/exceptionhandlers/ExceptionHandlingStrategy.java
// public interface ExceptionHandlingStrategy {
// 
//     /**
//      * Called for each line of the stack trace as sent to the System.out/err PrintStream.
//      *
//      * @param line The stacktrace line
//      * @param log The {@link org.slf4j.Logger} with a name matching the fully qualified name of the
//      *                 class where printStacktrace was called
//      */
//     void handleExceptionLine(String line, Logger log);
// 
//     /**
//      * Called whenever any other calls are intercepted by sysout-over-slf4j
//      * - may be a useful trigger for flushing a buffer.
//      */
//     void notifyNotStackTrace();
// }


// Path: sysout-over-slf4j-context/src/test/java/uk/org/lidalia/sysoutslf4j/context/LoggingOutputStreamTests.java
import java.io.PrintStream;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
import org.slf4j.Logger;
import uk.org.lidalia.slf4jtest.TestLogger;
import uk.org.lidalia.slf4jtest.TestLoggerFactory;
import uk.org.lidalia.slf4jext.Level;
import uk.org.lidalia.sysoutslf4j.SysOutOverSLF4JTestCase;
import uk.org.lidalia.sysoutslf4j.context.exceptionhandlers.ExceptionHandlingStrategy;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.powermock.api.mockito.PowerMockito.mock;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
import static org.powermock.api.mockito.PowerMockito.when;
import static uk.org.lidalia.slf4jtest.LoggingEvent.info;
import static uk.org.lidalia.slf4jtest.LoggingEvent.warn;

    private PrintStream origPrintStreamMock = mock(PrintStream.class);
    private LoggingSystemRegister loggingSystemRegisterMock = mock(LoggingSystemRegister.class);
    private LoggingOutputStream outputStream = new LoggingOutputStream(level, exceptionHandlingStrategyMock, origPrintStreamMock, loggingSystemRegisterMock);
    private TestLogger logger = TestLoggerFactory.getTestLogger(CLASS_NAME);

    @Before
    public void setUp() {
        mockGettingCallOrigin(false, false, CLASS_NAME);
    }

    @Test
    public void flushLogsWhenMessageEndsWithUnixLineBreak() throws Exception {
        outputStream.write("the message\n".getBytes("UTF-8"));
        outputStream.flush();
        assertEquals(asList(info("the message")), logger.getLoggingEvents());
    }

    @Test
    public void flushLogsWhenMessageEndsWithWindowsLineBreak() throws Exception {
        outputStream.write("the message\r\n".getBytes("UTF-8"));
        outputStream.flush();
        assertEquals(asList(info("the message")), logger.getLoggingEvents());
    }

    @Test
    public void flushWritesToOriginalPrintStreamIfInLoggingSystem() throws Exception {
        mockGettingCallOrigin(false, true, CLASS_IN_LOGGING_SYSTEM);

        byte[] bytes = "twelve chars".getBytes("UTF-8");
        outputStream.write(bytes);
        outputStream.flush();