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);
}
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));
}
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));
}
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);
}
}
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);
}
}
Aggregations