SessionHistoryManager { public static void showHistory(int n) throws FileNotFoundException, IOException { List<SessionHistory> l = listHistory(); int size = n > l.size() ? l.size() : n; for (int i = 0; i < size; i++) { int idx = l.size() - i - 1; Map<String, String> ctx = l.get(idx).loadProperty(); String status = ctx.get(Constants.STATUS); if (SessionStatus.success.toString().equals(status) && l.get(idx).existsBad()) { status = "bad"; } System.err.println(l.get(idx).sid + "\t" + status + "\t'" + ctx.get(Constants.COMMAND) + "'"); } }  static void showHistory(int n); static SessionHistory getLatest(); static SessionHistory getLatestSilently(); static void purgeHistory(int n); static SessionHistory createSessionHistory(String sid);  }
@Test public void testListHistoryStatus() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); PrintStream s = new PrintStream(out); PrintStream old = System.err; System.setErr(s); SessionHistoryManager.showHistory(1000); String hs = new String(out.toByteArray()); int i4 = hs.indexOf("s1_session\tsuccess\t'download"); int i5 = hs.indexOf("s2_session\tbad\t'upload"); int i6 = hs.indexOf("s3_session\trunning\t'upload"); assertFalse(StringUtils.isNullOrEmpty(hs)); assertTrue("status success", i4 >= 0); assertTrue("status bad", i5 >= 0); assertTrue("status running", i6 >= 0); System.setErr(old); }