SessionHistoryManager { private static List<SessionHistory> listHistory() { String sp = Util.getSessionBaseDir() + "/sessions"; List<SessionHistory> ls = new ArrayList<SessionHistory>(); File file = new File(sp); if (file.exists()) { File[] fl = file.listFiles(); for (File f : fl) { if (f.isDirectory() && !f.getName().startsWith(".")) { File[] sfl = f.listFiles(); for (File sf : sfl) { ls.add(new SessionHistory(sf.getName())); } } } } else { return ls; } Collections.sort(ls, new HistoryComparator()); return ls; }  static void showHistory(int n); static SessionHistory getLatest(); static SessionHistory getLatestSilently(); static void purgeHistory(int n); static SessionHistory createSessionHistory(String sid);  }
@Test public void testListHistory() 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()); assertFalse(StringUtils.isNullOrEmpty(hs)); int i1 = hs.indexOf("s1_session"); int i2 = hs.indexOf("s2_session"); int i3 = hs.indexOf("s3_session"); assertTrue("s1 > s2", i1 > i2); assertTrue("s3 > s2", i3 > i2); assertTrue("s1 > s3", i1 > i3); System.setErr(old); }