@Override protected String run(final String... args) throws IOException { try { final ArrayOutput ao = new ArrayOutput(); System.setOut(new PrintStream(ao)); System.setErr(NULL); new BaseX(args); return ao.toString(); } finally { System.setOut(OUT); System.setErr(ERR); } }
public static int test(int n) throws Exception { PrintStream oldOut = System.out; int sum = 0; for (int i = 0; i < 10; i++) { ByteArrayOutputStream ba = new ByteArrayOutputStream(n * 10); PrintStream newOut = new PrintStream(ba); System.setOut(newOut); doPrint(n); sum += ba.size(); } System.setOut(oldOut); return sum; }
@Before public void init() { alist.add(a1); alist.add(a2); alist.add(a3); alist.add(a4); alist.add(a5); alist.add(a6); alist.add(a7); alist.add(a8); alist.add(a9); System.setOut(new PrintStream(outContent)); System.setErr(new PrintStream(errContent)); }
/** * Runs a request with the specified arguments and server arguments. * * @param args command-line arguments * @param sargs server arguments * @return result * @throws IOException I/O exception */ private static String run(final String[] args, final String[] sargs) throws IOException { final BaseXServer server = createServer(sargs); final ArrayOutput ao = new ArrayOutput(); System.setOut(new PrintStream(ao)); System.setErr(NULL); final StringList sl = new StringList(); sl.add("-p9999").add("-U" + Text.S_ADMIN).add("-P" + Text.S_ADMIN).add(args); try { new BaseXClient(sl.finish()); return ao.toString(); } finally { System.setErr(ERR); stopServer(server); } }
@Before public void setup() { System.setOut(new PrintStream(stdout)); }
@After public void teardown() { System.setOut(null); }
@After public void cleanUpStreams() { System.setOut(null); System.setErr(null); }
@After public void restoreStandardOutput() { System.setOut(originalSystemOut); }
@Before public void redirectStandardOutput() { originalSystemOut = System.out; System.setOut(new PrintStream(testOutput)); }
/** Before each test, initialize a new System.out stream */ @Before public void setUpStreams() { System.setOut(new PrintStream(consl)); // redirect the stdout ans = new StringBuilder(""); }
/** Clean up System.out after each test, setting it back to the old PrintStream */ @After public void cleanUpStreams() { System.setOut(oldStdOut); // reset the stdout }