### Question:
DeleteOnQueryResultHandler implements ResultHandler<Collection<PartialToken>, CoreTokenException> { @Override public void processResults(Collection<PartialToken> results) { String tokenId = null; for (PartialToken result : results) { try { tokenId = result.getValue(CoreTokenField.TOKEN_ID); taskDispatcher.delete(tokenId, resultHandlerFactory.getDeleteHandler()); } catch (CoreTokenException ex) { debug.error(String.format("Unable to submit delete task for token ID {0}", tokenId), ex); } } } @Inject  DeleteOnQueryResultHandler(TaskDispatcher taskDispatcher, ResultHandlerFactory resultHandlerFactory,
            @Named(CoreTokenConstants.CTS_DEBUG) Debug debug); @Override Collection<PartialToken> getResults(); @Override void processResults(Collection<PartialToken> results); @Override void processError(Exception exception);  }### Answer:
@Test public void shouldInvokeDeleteForEachHit() throws Exception { Collection<PartialToken> hits = getHits(5); handler.processResults(hits); for (PartialToken hit : hits) { verify(mockTaskDispatcher).delete(eq(hit.<String>getValue(CoreTokenField.TOKEN_ID)), nullable(ResultHandler.class)); } }
@Test public void shouldInvokeDeleteForEachHitEvenIfThereWasAnException() throws Exception { Collection<PartialToken> hits = getHits(5); handler.processResults(hits); willThrow(new CoreTokenException("")).willDoNothing().given(mockTaskDispatcher) .delete(anyString(), any(ResultHandler.class)); for (PartialToken hit : hits) { verify(mockTaskDispatcher).delete(eq(hit.<String>getValue(CoreTokenField.TOKEN_ID)), nullable(ResultHandler.class)); } }
@Test public void shouldInvokeDeleteForEachHit() throws Exception { Collection<PartialToken> hits = getHits(5); handler.processResults(hits); for (PartialToken hit : hits) { verify(mockTaskDispatcher).delete(eq(hit.<String>getValue(CoreTokenField.TOKEN_ID)), any(ResultHandler.class)); } }
@Test public void shouldInvokeDeleteForEachHitEvenIfThereWasAnException() throws Exception { Collection<PartialToken> hits = getHits(5); handler.processResults(hits); willThrow(new CoreTokenException("")).willNothing().given(mockTaskDispatcher) .delete(anyString(), any(ResultHandler.class)); for (PartialToken hit : hits) { verify(mockTaskDispatcher).delete(eq(hit.<String>getValue(CoreTokenField.TOKEN_ID)), any(ResultHandler.class)); } }