Code example for ByteArrayOutputStream

Methods: toString

0
  @Test (timeout=100000) 
  public void testMain() throws Exception { 
 
    SecurityManager securityManager = System.getSecurityManager();
 
    final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    final PrintStream out = new PrintStream(bytes);
    final PrintStream oldOut = System.out;
    System.setErr(out);
    ExitUtil.disableSystemExit(); 
    try { 
      String[] argv = new String[0];
      DebugGridmix.main(argv);
 
    } catch (ExitUtil.ExitException e) {
      assertEquals("ExitException", e.getMessage());
      ExitUtil.resetFirstExitException(); 
    } finally { 
      System.setErr(oldOut);
      System.setSecurityManager(securityManager);
    } 
    String print = bytes.toString();
    // should be printed tip in std error stream 
    assertTrue(print
            .contains("Usage: gridmix [-generate <MiB>] [-users URI] [-Dname=value ...] <iopath> <trace>"));
    assertTrue(print.contains("e.g. gridmix -generate 100m foo -"));
  } 
Connect your IDE to all the code out there  Get Codota for Java