### Question:
UserResolversImpl implements UserResolvers { @Override public DataFetcher<User> deleteUserDataFetcher() { return environment -> { long userId = util.getLongArg(environment, "userId"); return userLocalService.deleteUser(userId); }; }  @Reference(unbind = "-") void setUserLocalService(UserLocalService userLocalService); @Reference void setUtil(GraphQLUtil util); @Override DataFetcher<List<User>> getUsersDataFetcher(); @Override DataFetcher<CompletableFuture<List<User>>> getBulkUsersDataFetcher(); @Override DataFetcher<CompletableFuture<User>> getUserDataFetcher(); @Override DataFetcher<User> getUserByEmailDataFetcher(); @Override DataFetcher<User> getUserByScreenNameDataFetcher(); @Override DataFetcher<User> createUserDataFetcher(); @Override DataFetcher<User> updateUserDataFetcher(); @Override DataFetcher<User> deleteUserDataFetcher();  }### Answer:
@Test public void deleteUserDataFetcher_should_return_deleted_object() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("userId", USER_ID); DataFetchingEnvironment environment = getTestEnvironment(arguments); User expectedResult = mock(User.class); expectedResult.setUserId(USER_ID); useMockGraphQLUtil(environment, CREATOR_ID, true); when(localService.deleteUser(eq(USER_ID))) .thenReturn(expectedResult); User result = resolvers.deleteUserDataFetcher() .get(environment); assertNotNull(result); assertEquals(expectedResult, result); }
@Test(expected = NoSuchUserException.class) public void deleteUserDataFetcher_without_args_should_return_null_with_exception() throws Exception { DataFetchingEnvironment environment = getTestEnvironment(null); User expectedResult = mock(User.class); expectedResult.setUserId(USER_ID); useMockGraphQLUtil(environment, CREATOR_ID, true); when(localService.deleteUser(eq(USER_ID))) .thenThrow(NoSuchUserException.class); User result = resolvers.deleteUserDataFetcher() .get(environment); assertNull(result); }
@Test(expected = NoSuchUserException.class) public void deleteUserDataFetcher_with_invalid_id_should_return_null_with_exception() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("userId", 789456L); DataFetchingEnvironment environment = getTestEnvironment(arguments); User expectedResult = mock(User.class); expectedResult.setUserId(USER_ID); useMockGraphQLUtil(environment, CREATOR_ID, false); when(graphQLUtil.getLongArg(eq(environment), eq("userId"))) .thenReturn(789456L); when(localService.deleteUser(eq(789456L))) .thenThrow(NoSuchUserException.class); User result = resolvers.deleteUserDataFetcher() .get(environment); assertNull(result); }