### Question:
TaskMonitor implements TaskRunner.Listener, Closeable { @Override public void failed(final Throwable th, String containerError) { if (th instanceof InterruptedException) { return; } if (th instanceof ImageNotFoundException) { imageFailure(IMAGE_MISSING); } else if (th instanceof ImagePullFailedException) { imageFailure(IMAGE_PULL_FAILED); } statusUpdater.setState(FAILED); statusUpdater.setContainerError(containerError); try { statusUpdater.update(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } TaskMonitor(final JobId jobId, final FlapController flapController,
                     final StatusUpdater statusUpdater); ThrottleState throttle(); @Override void close(); @Override void failed(final Throwable th, String containerError); @Override void pulling(); @Override void pulled(); @Override void pullFailed(); @Override void creating(); @Override void created(final String containerId); @Override void starting(); @Override void started(); @Override void healthChecking(); @Override void running(); @Override void exited(final long code);  }### Answer:
@Test public void verifyMonitorPropagatesImagePullFailed() throws Exception { sut.failed(new ImagePullFailedException("foobar", "failure"), "container error"); verify(statusUpdater).setThrottleState(IMAGE_PULL_FAILED); verify(statusUpdater).setState(FAILED); verify(statusUpdater).setContainerError("container error"); verify(statusUpdater).update(); }
@Test public void verifyMonitorPropagatesImageMissing() throws Exception { sut.failed(new ImageNotFoundException("foobar", "not found"), "container error"); verify(statusUpdater).setThrottleState(IMAGE_MISSING); verify(statusUpdater).setState(FAILED); verify(statusUpdater).setContainerError("container error"); verify(statusUpdater).update(); }
@Test public void verifyImagePullFailureTrumpsFlappingState() throws Exception { when(flapController.isFlapping()).thenReturn(true); sut.failed(new ImagePullFailedException("foobar", "failure"), "container error"); verify(statusUpdater).setThrottleState(IMAGE_PULL_FAILED); verify(statusUpdater).setState(FAILED); verify(statusUpdater).setContainerError("container error"); verify(statusUpdater).update(); }
@Test public void verifyImageMissingTrumpsFlappingState() throws Exception { when(flapController.isFlapping()).thenReturn(true); sut.failed(new ImageNotFoundException("foobar", "not found"), "container error"); verify(statusUpdater).setThrottleState(IMAGE_MISSING); verify(statusUpdater).setState(FAILED); verify(statusUpdater).setContainerError("container error"); verify(statusUpdater).update(); }