### Question:
EmailAddressResolversImpl implements EmailAddressResolvers { @Override public DataFetcher<CompletableFuture<EmailAddress>> getEmailAddressDataFetcher() { return environment -> { long emailAddressId = util.getLongArg(environment, "emailAddressId"); if (emailAddressId <= 0) { return null; } DataLoader<Long, EmailAddress> dataLoader = environment.getDataLoader(EmailAddressBatchLoader.KEY); return dataLoader.load(emailAddressId); }; }  @Reference(unbind = "-") void setEmailAddressLocalService(EmailAddressLocalService emailaddressLocalService); @Reference void setUtil(GraphQLUtil util); @Override DataFetcher<List<EmailAddress>> getEmailAddressesDataFetcher(); @Override DataFetcher<List<EmailAddress>> getEmailAddressesForEntityDataFetcher(); @Override DataFetcher<CompletableFuture<EmailAddress>> getEmailAddressDataFetcher(); @Override DataFetcher<EmailAddress> createEmailAddressDataFetcher(); @Override DataFetcher<EmailAddress> updateEmailAddressDataFetcher(); @Override DataFetcher<EmailAddress> deleteEmailAddressDataFetcher();  }### Answer:
@Test public void getEmailAddressDataFetcher_should_return_the_searched_object() throws Exception { EmailAddress expectedResult = mock(EmailAddress.class); expectedResult.setEmailAddressId(EMAIL_ADDRESS_ID); useSimpleGraphQLUtil(); when(mockEnvironment.getArgument("emailAddressId")) .thenReturn(EMAIL_ADDRESS_ID); when(dataLoader.load(EMAIL_ADDRESS_ID)) .thenReturn(CompletableFuture.supplyAsync(() -> expectedResult)); CompletableFuture<EmailAddress> asyncResult = resolvers.getEmailAddressDataFetcher() .get(mockEnvironment); assertNotNull(asyncResult); EmailAddress result = asyncResult.get(); assertNotNull(result); assertEquals(expectedResult, result); }
@Test public void getEmailAddressDataFetcher_no_specified_id_should_return_null() throws Exception { when(mockEnvironment.getArgument("emailAddressId")) .thenReturn(0L); CompletableFuture<EmailAddress> asyncResult = resolvers.getEmailAddressDataFetcher() .get(mockEnvironment); assertNull(asyncResult); }
@Test public void getEmailAddressDataFetcher_with_unknown_id_should_return_null() throws Exception { useSimpleGraphQLUtil(); when(mockEnvironment.getArgument("emailAddressId")) .thenReturn(EMAIL_ADDRESS_ID); when(dataLoader.load(EMAIL_ADDRESS_ID)) .thenReturn(CompletableFuture.supplyAsync(() -> null)); CompletableFuture<EmailAddress> asyncResult = resolvers.getEmailAddressDataFetcher() .get(mockEnvironment); assertNotNull(asyncResult); EmailAddress result = asyncResult.get(); assertNull(result); }