GetApiKeyTask extends DefaultTask<String> implements UserTask { @Override public String call() throws Exception { ApiKey apiKey = apiKeyRepository.get(user); return apiKey != null ? apiKey.getId() : null; } @Inject  GetApiKeyTask(ApiKeyRepository apiKeyRepository,@Assisted User user); @Override String call(); @Override User getUser();  }
@Test public void test_call() throws Exception { ArgumentCaptor<User> user = forClass(User.class); when(apiKeyRepository.get(User.local())).thenReturn(new DatashareApiKey(User.local())); assertThat(new GetApiKeyTask(apiKeyRepository, User.local()).call()).isNotNull(); verify(apiKeyRepository).get(user.capture()); assertThat(user.getValue()).isEqualTo(User.local()); }