### Question:
TokenDataStore { public void update(T obj) throws NotFoundException, ServerException { SyncResultHandler<Token> handler = new SyncResultHandler<Token>(); Token token = adapter.toToken(obj); try { read(token.getTokenId()); taskExecutor.execute(token.getTokenId(), taskFactory.update(token, handler)); handler.getResults(); } catch (ServerException e) { throw e; } catch (NotFoundException 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 testUpdate() throws Exception { final Token token = new Token("123", TokenType.GENERIC); final Task readTask = mock(Task.class); final Task updateTask = mock(Task.class); when(adapter.toToken(anyObject())).thenReturn(token); when(taskFactory.read(eq("123"), any(ResultHandler.class))).thenAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { ((ResultHandler) invocation.getArguments()[1]).processResults(token); return readTask; } }); when(taskFactory.update(any(Token.class), any(ResultHandler.class))).thenAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { ((ResultHandler) invocation.getArguments()[1]).processResults(token); return updateTask; } }); store.update(new Object()); verify(taskFactory).update(eq(token), any(ResultHandler.class)); verify(taskExecutor).execute("123", readTask); verify(taskExecutor).execute("123", updateTask); }