### Question:
EmailAddressResolversImpl implements EmailAddressResolvers { @Override public DataFetcher<EmailAddress> deleteEmailAddressDataFetcher() { return environment -> { long emailAddressId = util.getLongArg(environment, "emailAddressId"); return emailaddressLocalService.deleteEmailAddress(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 deleteEmailAddressDataFetcher_should_return_deleted_object() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("emailAddressId", EMAIL_ADDRESS_ID); DataFetchingEnvironment environment = getTestEnvironment(arguments); EmailAddress expectedResult = mock(EmailAddress.class); expectedResult.setEmailAddressId(EMAIL_ADDRESS_ID); useMockGraphQLUtil(environment, USER_ID, true); when(localService.deleteEmailAddress(eq(EMAIL_ADDRESS_ID))) .thenReturn(expectedResult); EmailAddress result = resolvers.deleteEmailAddressDataFetcher() .get(environment); assertNotNull(result); assertEquals(expectedResult, result); }
@Test(expected = NoSuchEmailAddressException.class) public void deleteEmailAddressDataFetcher_without_args_should_return_null_with_exception() throws Exception { DataFetchingEnvironment environment = getTestEnvironment(null); EmailAddress expectedResult = mock(EmailAddress.class); expectedResult.setEmailAddressId(EMAIL_ADDRESS_ID); useMockGraphQLUtil(environment, USER_ID, true); when(localService.deleteEmailAddress(eq(EMAIL_ADDRESS_ID))) .thenThrow(NoSuchEmailAddressException.class); EmailAddress result = resolvers.deleteEmailAddressDataFetcher() .get(environment); assertNull(result); }
@Test(expected = NoSuchEmailAddressException.class) public void deleteEmailAddressDataFetcher_with_invalid_id_should_return_null_with_exception() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("emailAddressId", 789456L); DataFetchingEnvironment environment = getTestEnvironment(arguments); EmailAddress expectedResult = mock(EmailAddress.class); expectedResult.setEmailAddressId(EMAIL_ADDRESS_ID); useMockGraphQLUtil(environment, USER_ID, false); when(graphQLUtil.getLongArg(eq(environment), eq("emailAddressId"))) .thenReturn(789456L); when(localService.deleteEmailAddress(eq(789456L))) .thenThrow(NoSuchEmailAddressException.class); EmailAddress result = resolvers.deleteEmailAddressDataFetcher() .get(environment); assertNull(result); }