### Question:
AddressResolversImpl implements AddressResolvers { @Override public DataFetcher<CompletableFuture<Address>> getAddressDataFetcher() { return environment -> { long addressId = util.getLongArg(environment, "addressId"); if (addressId <= 0) { return null; } DataLoader<Long, Address> dataLoader = environment.getDataLoader(AddressBatchLoader.KEY); return dataLoader.load(addressId); }; }  @Reference(unbind = "-") void setAddressLocalService(AddressLocalService addressLocalService); @Reference void setUtil(GraphQLUtil util); @Override DataFetcher<List<Address>> getAddressesDataFetcher(); @Override DataFetcher<List<Address>> getAddressesForEntityDataFetcher(); @Override DataFetcher<CompletableFuture<Address>> getAddressDataFetcher(); @Override DataFetcher<Address> createAddressDataFetcher(); @Override DataFetcher<Address> updateAddressDataFetcher(); @Override DataFetcher<Address> deleteAddressDataFetcher();  }### Answer:
@Test public void getAddressDataFetcher_should_return_the_searched_object() throws Exception { Address expectedResult = mock(Address.class); expectedResult.setAddressId(ADDRESS_ID); useSimpleGraphQLUtil(); when(mockEnvironment.getArgument("addressId")) .thenReturn(ADDRESS_ID); when(dataLoader.load(ADDRESS_ID)) .thenReturn(CompletableFuture.supplyAsync(() -> expectedResult)); CompletableFuture<Address> asyncResult = resolvers.getAddressDataFetcher() .get(mockEnvironment); assertNotNull(asyncResult); Address result = asyncResult.get(); assertNotNull(result); assertEquals(expectedResult, result); }
@Test public void getAddressDataFetcher_no_specified_id_should_return_null() throws Exception { when(mockEnvironment.getArgument("addressId")) .thenReturn(0L); CompletableFuture<Address> asyncResult = resolvers.getAddressDataFetcher() .get(mockEnvironment); assertNull(asyncResult); }
@Test public void getAddressDataFetcher_with_unknown_id_should_return_null() throws Exception { useSimpleGraphQLUtil(); when(mockEnvironment.getArgument("addressId")) .thenReturn(ADDRESS_ID); when(dataLoader.load(ADDRESS_ID)) .thenReturn(CompletableFuture.supplyAsync(() -> null)); CompletableFuture<Address> asyncResult = resolvers.getAddressDataFetcher() .get(mockEnvironment); assertNotNull(asyncResult); Address result = asyncResult.get(); assertNull(result); }