@Test public void interceptStdout() throws Exception { String result = ConsoleInterceptor.copyOut(() ->{ System.out.print("hello world"); System.out.print('!'); System.out.println(); System.out.println("foobar"); }); assertEquals("hello world!\nfoobar\n", result); result = ConsoleInterceptor.copyOut( () ->{ System.out.print("hello"); System.out.println(" world!"); }); assertEquals("hello world!\n", result); result = ConsoleInterceptor.copyOut( () ->{ System.out.print(58387); System.out.println(" world!"); }); assertEquals("58387 world!\n", result); }
private static Reporter callMain(String... args) throws Exception { output = ConsoleInterceptor.copyOut(() -> { String[] argsNew = new String[args.length+1]; for(int i =0; i< args.length;i++) { argsNew[i] = args[i]; } argsNew[args.length] = "--no-exit"; CLIMain.main(argsNew); errors = CLIMain.getReporter().getErrors(); }); return CLIMain.getReporter(); }
@Test public void interceptConsole() throws Exception { BufferedLogger log = new BufferedLogger(100); String res = ConsoleInterceptor.copyOut(()-> { log.interceptStdOut(); System.out.println("Hello, world"); System.out.println("iCodici rules"); System.out.println("last line"); // now we need that streams send their data throgh the pipes: while (log.getCopy().size() < 3) Thread.sleep(20); log.flush(); log.stopInterceptingStdOut(); log.close(); assertEquals("Hello, world,iCodici rules,last line", str(log.getCopy())); }); assertEquals("Hello, world\n" + "iCodici rules\n" + "last line", log.getCopy().stream() .map(x->x.message) .collect(Collectors.joining("\n"))); }
@Test public void checkNetwork() throws Exception { ClientNetwork n = new ClientNetwork(null); assertEquals(36, n.size()); ConsoleInterceptor.copyOut(() -> { int active = n.checkNetworkState(new Reporter()); assertEquals(36, active); }); } }
String output = ConsoleInterceptor.copyOut(() -> { registerAndCheckApproved(simpleContractRevision); Thread.sleep(5000);
String output = ConsoleInterceptor.copyOut(() -> { registerAndCheckApproved(simpleContractRevision); registerAndCheckApproved(simpleContractRevision2);
String output = ConsoleInterceptor.copyOut(() -> { registerAndCheckApproved(baseContract3); Thread.sleep(5000);