### Question:
ContactResolversImpl implements ContactResolvers { @Override public DataFetcher<Contact> deleteContactDataFetcher() { return environment -> { long contactId = util.getLongArg(environment, "contactId"); return contactLocalService.deleteContact(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 deleteContactDataFetcher_should_return_deleted_object() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("contactId", CONTACT_ID); DataFetchingEnvironment environment = getTestEnvironment(arguments); Contact expectedResult = mock(Contact.class); expectedResult.setContactId(CONTACT_ID); useMockGraphQLUtil(environment, USER_ID, true); when(localService.deleteContact(eq(CONTACT_ID))) .thenReturn(expectedResult); Contact result = resolvers.deleteContactDataFetcher() .get(environment); assertNotNull(result); assertEquals(expectedResult, result); }
@Test(expected = NoSuchContactException.class) public void deleteContactDataFetcher_without_args_should_return_null_with_exception() throws Exception { DataFetchingEnvironment environment = getTestEnvironment(null); Contact expectedResult = mock(Contact.class); expectedResult.setContactId(CONTACT_ID); useMockGraphQLUtil(environment, USER_ID, true); when(localService.deleteContact(eq(CONTACT_ID))) .thenThrow(NoSuchContactException.class); Contact result = resolvers.deleteContactDataFetcher() .get(environment); assertNull(result); }
@Test(expected = NoSuchContactException.class) public void deleteContactDataFetcher_with_invalid_id_should_return_null_with_exception() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("contactId", 789456L); DataFetchingEnvironment environment = getTestEnvironment(arguments); Contact expectedResult = mock(Contact.class); expectedResult.setContactId(CONTACT_ID); useMockGraphQLUtil(environment, USER_ID, false); when(graphQLUtil.getLongArg(eq(environment), eq("contactId"))) .thenReturn(789456L); when(localService.deleteContact(eq(789456L))) .thenThrow(NoSuchContactException.class); Contact result = resolvers.deleteContactDataFetcher() .get(environment); assertNull(result); }