IgnoreTaskStrategy implements ITaskProcessStrategy { @Override public void process(final ITaskExecutionState state) throws TaskExecutionException, InvalidArgumentException, TaskProcessException { try { state.getTaskAs(IShutdownAwareTask.class).notifyIgnored(); } catch (InvalidArgumentException ignore) { } catch (ShutdownAwareTaskNotificationException e) { throw new TaskProcessException(e); } }  @Override void process(final ITaskExecutionState state);  }
@Test public void Should_doNothingWithTaskThatIsNotAwareOfShutdownRequests() throws Exception { when(taskExecutionState.getTaskAs(same(IShutdownAwareTask.class))) .thenThrow(InvalidArgumentException.class); new IgnoreTaskStrategy().process(taskExecutionState); verify(taskExecutionState).getTaskAs(same(IShutdownAwareTask.class)); verifyNoMoreInteractions(taskExecutionState); }
@Test public void Should_notifyTheTskThatItIsIgnored() throws Exception { when(taskExecutionState.getTaskAs(same(IShutdownAwareTask.class))) .thenReturn(shutdownAwareTask); new IgnoreTaskStrategy().process(taskExecutionState); verify(shutdownAwareTask).notifyIgnored(); }
@Test(expected = TaskProcessException.class) public void Should_wrapExceptionsOccurredOnNotification() throws Exception { when(taskExecutionState.getTaskAs(same(IShutdownAwareTask.class))) .thenReturn(shutdownAwareTask); doThrow(ShutdownAwareTaskNotificationException.class) .when(shutdownAwareTask).notifyIgnored(); new IgnoreTaskStrategy().process(taskExecutionState); }