### Question:
AddressResolversImpl implements AddressResolvers { @Override public DataFetcher<Address> deleteAddressDataFetcher() { return environment -> { long addressId = util.getLongArg(environment, "addressId"); return addressLocalService.deleteAddress(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 deleteAddressDataFetcher_should_return_deleted_object() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("addressId", ADDRESS_ID); DataFetchingEnvironment environment = getTestEnvironment(arguments); Address expectedResult = mock(Address.class); expectedResult.setAddressId(ADDRESS_ID); useMockGraphQLUtil(environment, USER_ID, true); when(localService.deleteAddress(eq(ADDRESS_ID))) .thenReturn(expectedResult); Address result = resolvers.deleteAddressDataFetcher() .get(environment); assertNotNull(result); assertEquals(expectedResult, result); }
@Test(expected = NoSuchAddressException.class) public void deleteAddressDataFetcher_without_args_should_return_null_with_exception() throws Exception { DataFetchingEnvironment environment = getTestEnvironment(null); Address expectedResult = mock(Address.class); expectedResult.setAddressId(ADDRESS_ID); useMockGraphQLUtil(environment, USER_ID, true); when(localService.deleteAddress(eq(ADDRESS_ID))) .thenThrow(NoSuchAddressException.class); Address result = resolvers.deleteAddressDataFetcher() .get(environment); assertNull(result); }
@Test(expected = NoSuchAddressException.class) public void deleteAddressDataFetcher_with_invalid_id_should_return_null_with_exception() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("addressId", 789456L); DataFetchingEnvironment environment = getTestEnvironment(arguments); Address expectedResult = mock(Address.class); expectedResult.setAddressId(ADDRESS_ID); useMockGraphQLUtil(environment, USER_ID, false); when(graphQLUtil.getLongArg(eq(environment), eq("addressId"))) .thenReturn(789456L); when(localService.deleteAddress(eq(789456L))) .thenThrow(NoSuchAddressException.class); Address result = resolvers.deleteAddressDataFetcher() .get(environment); assertNull(result); }