CollectingLogOutputStream extends LogOutputStream { public List<String> getLastNLines(int n) { Lock lock = new ReentrantLock(); lock.lock(); List<String> nlines = new ArrayList<String>(n); int start, end; end = this.lines.size(); start = Math.max(0, this.lines.size() - n); if (end > start && start >= 0) { nlines = this.lines.subList(start, end); } lock.unlock(); return nlines; }  String getAllLinesAsString(); List<String> getLastNLines(int n);  }
@Test public void testGetLastNLines() { CollectingLogOutputStream instance = new CollectingLogOutputStream(); instance.processLine("add a line of funky output", 1); instance.processLine("add another line of groovy output", 2); List<String> output = instance.getLastNLines(1); assertTrue("output does not match", output.size() == 1 && output.get(0).contains("groovy")); }