### Question:
CodeReviewRequestTask extends BackgroundTask { @Override public int start(TaskStatusMonitor progress) { progress.startProgress(this.getDescription(), 2); return run(progress); } CodeReviewRequestTask(ProjectUploader uploader, String path, String requestMessage, ProjectDAO projectDAO,
            IdeUIInvoker invoker); @Override int start(TaskStatusMonitor progress);  }### Answer:
@Test public void runningWithCorrectSettingsReturnsSuccessAndCallsRequiredMethods() throws IOException { when(progress.isCancelRequested()).thenReturn(false); assertEquals(BackgroundTask.RETURN_SUCCESS, task.start(progress)); verify(uploader, times(1)).setProject(any(Project.class)); verify(uploader, times(1)).setAsRequest("requestMessage"); verify(uploader, times(1)).zipProjects(); }
@Test public void taskReturnsInterruptedIfCancelIsRequestedAtFirstCheckpoint() throws IOException { when(progress.isCancelRequested()).thenReturn(true); assertEquals(BackgroundTask.RETURN_INTERRUPTED, task.start(progress)); verify(progress, times(0)).incrementProgress(1); }
@Test public void taskReturnsInterruptedIfStoppedAtFirstCheckpoint() throws IOException { task.stop(); assertEquals(BackgroundTask.RETURN_INTERRUPTED, task.start(progress)); verify(progress, times(0)).incrementProgress(1); }
@Test public void taskReturnsInterruptedIfCancelIsRequestedAtSecondCheckpoint() throws IOException { when(progress.isCancelRequested()).thenReturn(false); Mockito.doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) { when(progress.isCancelRequested()).thenReturn(true); return null; } }).when(uploader).handleSubmissionResponse(); assertEquals(BackgroundTask.RETURN_INTERRUPTED, task.start(progress)); verify(progress, times(1)).incrementProgress(1); }
@Test public void taskReturnsFailureIfAnExceptionIsThrown() throws IOException { when(progress.isCancelRequested()).thenReturn(false); doThrow(new IOException()).when(uploader).zipProjects(); assertEquals(BackgroundTask.RETURN_FAILURE, task.start(progress)); }