### Question:
TokenDataStore { public void delete(String id) throws NotFoundException, ServerException { SyncResultHandler<String> handler = new SyncResultHandler<String>(); try { taskExecutor.execute(id, taskFactory.delete(id, handler)); handler.getResults(); } catch (ServerException e) { throw e; } catch (DataLayerException e) { if (debug.warningEnabled()) { debug.warning("Unable to create token corresponding", e); } throw new ServerException("Could not create token in token data store: " + e.getMessage()); } } TokenDataStore(JavaBeanAdapter<T> adapter, TaskExecutor taskExecutor, TaskFactory taskFactory); @VisibleForTesting  TokenDataStore(JavaBeanAdapter<T> adapter, TaskExecutor taskExecutor, TaskFactory taskFactory, Debug debug); void create(T obj); T read(String id); void update(T obj); void delete(String id); Set<T> query(QueryFilter<String> query);  }### Answer:
@Test public void testDelete() throws Exception { final Task task = mock(Task.class); when(taskFactory.delete(anyString(), any(ResultHandler.class))).thenAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { ((ResultHandler) invocation.getArguments()[1]).processResults(new Object()); return task; } }); store.delete("123"); verify(taskFactory).delete(eq("123"), any(ResultHandler.class)); verify(taskExecutor).execute("123", task); }
@Test(expectedExceptions = ServerException.class) public void testDeleteError() throws Exception { final Task task = mock(Task.class); when(taskFactory.delete(anyString(), any(ResultHandler.class))).thenAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { ((ResultHandler) invocation.getArguments()[1]).processError(new Exception()); return task; } }); store.delete("123"); }
@Test(expectedExceptions = ServerException.class) public void testDeleteExecutorError() throws Exception { final Task task = mock(Task.class); when(taskFactory.delete(anyString(), any(ResultHandler.class))).thenReturn(task); doThrow(DataLayerException.class).when(taskExecutor).execute("123", task); store.delete("123"); }