### Question:
ContactResolversImpl implements ContactResolvers { @Override public DataFetcher<CompletableFuture<Contact>> getContactDataFetcher() { return environment -> { long contactId = getContactId(environment); if (contactId <= 0) { return null; } DataLoader<Long, Contact> dataLoader = environment.getDataLoader(ContactBatchLoader.KEY); return dataLoader.load(contactId); }; }  @Reference(unbind = "-") void setContactLocalService(ContactLocalService contactLocalService); @Reference void setUtil(GraphQLUtil util); @Override DataFetcher<List<Contact>> getContactsDataFetcher(); @Override DataFetcher<CompletableFuture<Contact>> getContactDataFetcher(); @Override DataFetcher<Contact> createContactDataFetcher(); @Override DataFetcher<Contact> updateContactDataFetcher(); @Override DataFetcher<Contact> deleteContactDataFetcher();  }### Answer:
@Test public void getContactDataFetcher_should_return_the_searched_object() throws Exception { Contact expectedResult = mock(Contact.class); expectedResult.setContactId(CONTACT_ID); useSimpleGraphQLUtil(); when(mockEnvironment.getArgument("contactId")) .thenReturn(CONTACT_ID); when(dataLoader.load(CONTACT_ID)) .thenReturn(CompletableFuture.supplyAsync(() -> expectedResult)); CompletableFuture<Contact> asyncResult = resolvers.getContactDataFetcher() .get(mockEnvironment); assertNotNull(asyncResult); Contact result = asyncResult.get(); assertNotNull(result); assertEquals(expectedResult, result); }
@Test public void getContactDataFetcher_no_specified_id_should_return_null() throws Exception { when(mockEnvironment.getArgument("contactId")) .thenReturn(0L); CompletableFuture<Contact> asyncResult = resolvers.getContactDataFetcher() .get(mockEnvironment); assertNull(asyncResult); }
@Test public void getContactDataFetcher_with_unknown_id_should_return_null() throws Exception { useSimpleGraphQLUtil(); when(mockEnvironment.getArgument("contactId")) .thenReturn(CONTACT_ID); when(dataLoader.load(CONTACT_ID)) .thenReturn(CompletableFuture.supplyAsync(() -> null)); CompletableFuture<Contact> asyncResult = resolvers.getContactDataFetcher() .get(mockEnvironment); assertNotNull(asyncResult); Contact result = asyncResult.get(); assertNull(result); }