### Question:
PhoneResolversImpl implements PhoneResolvers { @Override public DataFetcher<CompletableFuture<Phone>> getPhoneDataFetcher() { return environment -> { long phoneId = util.getLongArg(environment, "phoneId"); if (phoneId <= 0) { return null; } DataLoader<Long, Phone> dataLoader = environment.getDataLoader(PhoneBatchLoader.KEY); return dataLoader.load(phoneId); }; }  @Reference(unbind = "-") void setPhoneLocalService(PhoneLocalService phoneLocalService); @Reference void setUtil(GraphQLUtil util); @Override DataFetcher<List<Phone>> getPhonesDataFetcher(); @Override DataFetcher<List<Phone>> getPhonesForEntityDataFetcher(); @Override DataFetcher<CompletableFuture<Phone>> getPhoneDataFetcher(); @Override DataFetcher<Phone> createPhoneDataFetcher(); @Override DataFetcher<Phone> updatePhoneDataFetcher(); @Override DataFetcher<Phone> deletePhoneDataFetcher();  }### Answer:
@Test public void getPhoneDataFetcher_should_return_the_searched_object() throws Exception { Phone expectedResult = mock(Phone.class); expectedResult.setPhoneId(PHONE_ID); useSimpleGraphQLUtil(); when(mockEnvironment.getArgument("phoneId")) .thenReturn(PHONE_ID); when(dataLoader.load(PHONE_ID)) .thenReturn(CompletableFuture.supplyAsync(() -> expectedResult)); CompletableFuture<Phone> asyncResult = resolvers.getPhoneDataFetcher() .get(mockEnvironment); assertNotNull(asyncResult); Phone result = asyncResult.get(); assertNotNull(result); assertEquals(expectedResult, result); }
@Test public void getPhoneDataFetcher_no_specified_id_should_return_null() throws Exception { when(mockEnvironment.getArgument("phoneId")) .thenReturn(0L); CompletableFuture<Phone> asyncResult = resolvers.getPhoneDataFetcher() .get(mockEnvironment); assertNull(asyncResult); }
@Test public void getPhoneDataFetcher_with_unknown_id_should_return_null() throws Exception { useSimpleGraphQLUtil(); when(mockEnvironment.getArgument("phoneId")) .thenReturn(PHONE_ID); when(dataLoader.load(PHONE_ID)) .thenReturn(CompletableFuture.supplyAsync(() -> null)); CompletableFuture<Phone> asyncResult = resolvers.getPhoneDataFetcher() .get(mockEnvironment); assertNotNull(asyncResult); Phone result = asyncResult.get(); assertNull(result); }