### Question:
SimpleBackgroundTask extends BackgroundTask { @Override public int start(TaskStatusMonitor progress) { progress.startProgress(this.getDescription(), list.size()); for (T t : list) { if (shouldStop(progress)) { return BackgroundTask.RETURN_INTERRUPTED; } run(t); progress.incrementProgress(1); } return BackgroundTask.RETURN_SUCCESS; } SimpleBackgroundTask(String description, List<T> list); @Override int start(TaskStatusMonitor progress); abstract void run(T t);  }### Answer:
@Test public void startReturnsSuccessOnSuccess() { assertEquals(BackgroundTask.RETURN_SUCCESS, task.start(progress)); }
@Test public void startProgressIsCalledWhenCallingStart() { task.start(progress); verify(progress, times(1)).startProgress(anyString(), anyInt()); }
@Test public void objectsInListAreUsed() { task.start(progress); for (Foo o : list) { verify(o, times(1)).bar(); } }
@Test public void incrementProgressIsCalled() { task.start(progress); for (Foo o : list) { verify(progress, times(list.size())).incrementProgress(1); } }
@Test public void isCancelRequestedIsCalledOnEveryLoopIteration() { task.start(progress); verify(progress, times(list.size())).isCancelRequested(); }
@Test public void startReturnsFailureOnCancellation() { when(progress.isCancelRequested()).thenReturn(true); assertEquals(BackgroundTask.RETURN_INTERRUPTED, task.start(progress)); }
@Test public void objectsInListAreNotUsedIfProgressIsHaltedImmediately() { when(progress.isCancelRequested()).thenReturn(true); task.start(progress); for (Foo o : list) { verify(o, times(0)).bar(); } }
@Test public void incrementProgressIsNotCalledWhenIsHaltedImmediately() { when(progress.isCancelRequested()).thenReturn(true); task.start(progress); for (Foo o : list) { verify(progress, times(0)).incrementProgress(1); } }
@Test public void objectsInListAreNotUsedIfStopIsCalledImmediately() { task.stop(); task.start(progress); for (Foo o : list) { verify(o, times(0)).bar(); } }