### Question:
PhoneResolversImpl implements PhoneResolvers { @Override public DataFetcher<Phone> deletePhoneDataFetcher() { return environment -> { long phoneId = util.getLongArg(environment, "phoneId"); return phoneLocalService.deletePhone(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 deletePhoneDataFetcher_should_return_deleted_object() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("phoneId", PHONE_ID); DataFetchingEnvironment environment = getTestEnvironment(arguments); Phone expectedResult = mock(Phone.class); expectedResult.setPhoneId(PHONE_ID); useMockGraphQLUtil(environment, USER_ID, true); when(localService.deletePhone(eq(PHONE_ID))) .thenReturn(expectedResult); Phone result = resolvers.deletePhoneDataFetcher() .get(environment); assertNotNull(result); assertEquals(expectedResult, result); }
@Test(expected = NoSuchPhoneException.class) public void deletePhoneDataFetcher_without_args_should_return_null_with_exception() throws Exception { DataFetchingEnvironment environment = getTestEnvironment(null); Phone expectedResult = mock(Phone.class); expectedResult.setPhoneId(PHONE_ID); useMockGraphQLUtil(environment, USER_ID, true); when(localService.deletePhone(eq(PHONE_ID))) .thenThrow(NoSuchPhoneException.class); Phone result = resolvers.deletePhoneDataFetcher() .get(environment); assertNull(result); }
@Test(expected = NoSuchPhoneException.class) public void deletePhoneDataFetcher_with_invalid_id_should_return_null_with_exception() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("phoneId", 789456L); DataFetchingEnvironment environment = getTestEnvironment(arguments); Phone expectedResult = mock(Phone.class); expectedResult.setPhoneId(PHONE_ID); useMockGraphQLUtil(environment, USER_ID, false); when(graphQLUtil.getLongArg(eq(environment), eq("phoneId"))) .thenReturn(789456L); when(localService.deletePhone(eq(789456L))) .thenThrow(NoSuchPhoneException.class); Phone result = resolvers.deletePhoneDataFetcher() .get(environment); assertNull(result); }