StreamProgressMonitor implements ProgressMonitor { public void beginTask(String title, int totalWork) { endTask(); stream.print(title); if (totalWork != UNKNOWN) { stream.print(": "); stream.print(totalWork); } stream.print(' '); done = false; } StreamProgressMonitor(PrintStream stream); void start(int totalTasks); void beginTask(String title, int totalWork); void update(int completed); void endTask(); boolean isCancelled(); static final String DONE; }
@Test public void knownWork() { ByteArrayOutputStream stream = new ByteArrayOutputStream(); StreamProgressMonitor monitor = new StreamProgressMonitor( new PrintStream(stream)); monitor.beginTask("test task", 8); assertEquals("test task: 8 ", stream.toString()); }
@Test public void beginBeforeEnd() { ByteArrayOutputStream stream = new ByteArrayOutputStream(); StreamProgressMonitor monitor = new StreamProgressMonitor( new PrintStream(stream)); monitor.beginTask("task1", 1); monitor.beginTask("task2", StreamProgressMonitor.UNKNOWN); assertEquals("task1: 1 " + StreamProgressMonitor.DONE + SEPARATOR + "task2 ", stream.toString()); }
@Test public void unknownWork() { ByteArrayOutputStream stream = new ByteArrayOutputStream(); StreamProgressMonitor monitor = new StreamProgressMonitor( new PrintStream(stream)); monitor.beginTask("test task", StreamProgressMonitor.UNKNOWN); assertEquals("test task ", stream.toString()); }