Search in sources :

Example 61 with PrintStream

use of java.io.PrintStream in project byte-buddy by raphw.

the class AgentBuilderListenerTest method testStreamWritingOnError.

@Test
public void testStreamWritingOnError() throws Exception {
    PrintStream printStream = mock(PrintStream.class);
    AgentBuilder.Listener listener = new AgentBuilder.Listener.StreamWriting(printStream);
    listener.onError(FOO, classLoader, module, LOADED, throwable);
    verify(printStream).printf("[Byte Buddy] ERROR %s [%s, %s, loaded=%b]%n", FOO, classLoader, module, LOADED);
    verifyNoMoreInteractions(printStream);
    verify(throwable).printStackTrace(printStream);
    verifyNoMoreInteractions(throwable);
}
Also used : PrintStream(java.io.PrintStream) Test(org.junit.Test)

Example 62 with PrintStream

use of java.io.PrintStream in project byte-buddy by raphw.

the class AdviceTest method testExceptionPriniting.

@Test
public void testExceptionPriniting() throws Exception {
    Class<?> type = new ByteBuddy().redefine(Sample.class).visit(Advice.to(ExceptionWriterTest.class).withExceptionPrinting().on(named(FOO))).make().load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER).getLoaded();
    PrintStream printStream = mock(PrintStream.class);
    PrintStream err = System.err;
    synchronized (System.err) {
        System.setErr(printStream);
        try {
            assertThat(type.getDeclaredMethod(FOO).invoke(type.getDeclaredConstructor().newInstance()), is((Object) FOO));
        } finally {
            System.setErr(err);
        }
    }
    verify(printStream, times(2)).println(Mockito.any(RuntimeException.class));
}
Also used : PrintStream(java.io.PrintStream) ByteBuddy(net.bytebuddy.ByteBuddy) Test(org.junit.Test)

Example 63 with PrintStream

use of java.io.PrintStream in project spring-security by spring-projects.

the class AuditLoggerTests method setUp.

// ~ Methods
// ========================================================================================================
@Before
public void setUp() throws Exception {
    logger = new ConsoleAuditLogger();
    ace = mock(AuditableAccessControlEntry.class);
    console = System.out;
    System.setOut(new PrintStream(bytes));
}
Also used : PrintStream(java.io.PrintStream) AuditableAccessControlEntry(org.springframework.security.acls.model.AuditableAccessControlEntry) Before(org.junit.Before)

Example 64 with PrintStream

use of java.io.PrintStream in project flink by apache.

the class SocketWindowWordCountITCase method testJavaProgram.

@Test
public void testJavaProgram() throws Exception {
    InetAddress localhost = InetAddress.getByName("localhost");
    // suppress sysout messages from this example
    final PrintStream originalSysout = System.out;
    final PrintStream originalSyserr = System.err;
    final ByteArrayOutputStream errorMessages = new ByteArrayOutputStream();
    System.setOut(new PrintStream(new NullStream()));
    System.setErr(new PrintStream(errorMessages));
    try {
        try (ServerSocket server = new ServerSocket(0, 10, localhost)) {
            final ServerThread serverThread = new ServerThread(server);
            serverThread.setDaemon(true);
            serverThread.start();
            final int serverPort = server.getLocalPort();
            org.apache.flink.streaming.examples.socket.SocketWindowWordCount.main(new String[] { "--port", String.valueOf(serverPort) });
            if (errorMessages.size() != 0) {
                fail("Found error message: " + new String(errorMessages.toByteArray(), ConfigConstants.DEFAULT_CHARSET));
            }
            serverThread.join();
            serverThread.checkError();
        }
    } finally {
        System.setOut(originalSysout);
        System.setErr(originalSyserr);
    }
}
Also used : PrintStream(java.io.PrintStream) ServerSocket(java.net.ServerSocket) ByteArrayOutputStream(java.io.ByteArrayOutputStream) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 65 with PrintStream

use of java.io.PrintStream in project flink by apache.

the class SocketWindowWordCountITCase method testScalaProgram.

@Test
public void testScalaProgram() throws Exception {
    InetAddress localhost = InetAddress.getByName("localhost");
    // suppress sysout messages from this example
    final PrintStream originalSysout = System.out;
    final PrintStream originalSyserr = System.err;
    final ByteArrayOutputStream errorMessages = new ByteArrayOutputStream();
    System.setOut(new PrintStream(new NullStream()));
    System.setErr(new PrintStream(errorMessages));
    try {
        try (ServerSocket server = new ServerSocket(0, 10, localhost)) {
            final ServerThread serverThread = new ServerThread(server);
            serverThread.setDaemon(true);
            serverThread.start();
            final int serverPort = server.getLocalPort();
            org.apache.flink.streaming.scala.examples.socket.SocketWindowWordCount.main(new String[] { "--port", String.valueOf(serverPort) });
            if (errorMessages.size() != 0) {
                fail("Found error message: " + new String(errorMessages.toByteArray(), ConfigConstants.DEFAULT_CHARSET));
            }
            serverThread.join();
            serverThread.checkError();
        }
    } finally {
        System.setOut(originalSysout);
        System.setErr(originalSyserr);
    }
}
Also used : PrintStream(java.io.PrintStream) ServerSocket(java.net.ServerSocket) ByteArrayOutputStream(java.io.ByteArrayOutputStream) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Aggregations

PrintStream (java.io.PrintStream)1828 ByteArrayOutputStream (java.io.ByteArrayOutputStream)805 Test (org.junit.Test)583 File (java.io.File)331 IOException (java.io.IOException)295 FileOutputStream (java.io.FileOutputStream)207 ArrayList (java.util.ArrayList)89 FileNotFoundException (java.io.FileNotFoundException)83 OutputStream (java.io.OutputStream)81 Before (org.junit.Before)66 BufferedReader (java.io.BufferedReader)53 BufferedOutputStream (java.io.BufferedOutputStream)49 Map (java.util.Map)49 Date (java.util.Date)46 Path (org.apache.hadoop.fs.Path)42 UnsupportedEncodingException (java.io.UnsupportedEncodingException)41 InputStreamReader (java.io.InputStreamReader)38 Matchers.anyString (org.mockito.Matchers.anyString)38 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)36 List (java.util.List)35