### Question:
UserGroupResolversImpl implements UserGroupResolvers { @Override public DataFetcher<UserGroup> deleteUserGroupDataFetcher() { return environment -> { long userGroupId = util.getLongArg(environment, "userGroupId"); return usergroupLocalService.deleteUserGroup(userGroupId); }; }  @Reference(unbind = "-") void setUserGroupLocalService(UserGroupLocalService usergroupLocalService); @Reference void setUtil(GraphQLUtil util); @Override DataFetcher<List<UserGroup>> getUserGroupsDataFetcher(); @Override DataFetcher<CompletableFuture<UserGroup>> getUserGroupDataFetcher(); @Override DataFetcher<UserGroup> getUserGroupByNameDataFetcher(); @Override DataFetcher<UserGroup> createUserGroupDataFetcher(); @Override DataFetcher<UserGroup> updateUserGroupDataFetcher(); @Override DataFetcher<UserGroup> deleteUserGroupDataFetcher();  }### Answer:
@Test public void deleteUserGroupDataFetcher_should_return_deleted_object() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("userGroupId", USER_GROUP_ID); DataFetchingEnvironment environment = getTestEnvironment(arguments); UserGroup expectedResult = mock(UserGroup.class); expectedResult.setUserGroupId(USER_GROUP_ID); useMockGraphQLUtil(environment, USER_ID, true); when(localService.deleteUserGroup(eq(USER_GROUP_ID))) .thenReturn(expectedResult); UserGroup result = resolvers.deleteUserGroupDataFetcher() .get(environment); assertNotNull(result); assertEquals(expectedResult, result); }
@Test(expected = NoSuchUserGroupException.class) public void deleteUserGroupDataFetcher_without_args_should_return_null_with_exception() throws Exception { DataFetchingEnvironment environment = getTestEnvironment(null); UserGroup expectedResult = mock(UserGroup.class); expectedResult.setUserGroupId(USER_GROUP_ID); useMockGraphQLUtil(environment, USER_ID, true); when(localService.deleteUserGroup(eq(USER_GROUP_ID))) .thenThrow(NoSuchUserGroupException.class); UserGroup result = resolvers.deleteUserGroupDataFetcher() .get(environment); assertNull(result); }
@Test(expected = NoSuchUserGroupException.class) public void deleteUserGroupDataFetcher_with_invalid_id_should_return_null_with_exception() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("userGroupId", 789456L); DataFetchingEnvironment environment = getTestEnvironment(arguments); UserGroup expectedResult = mock(UserGroup.class); expectedResult.setUserGroupId(USER_GROUP_ID); useMockGraphQLUtil(environment, USER_ID, false); when(graphQLUtil.getLongArg(eq(environment), eq("userGroupId"))) .thenReturn(789456L); when(localService.deleteUserGroup(eq(789456L))) .thenThrow(NoSuchUserGroupException.class); UserGroup result = resolvers.deleteUserGroupDataFetcher() .get(environment); assertNull(result); }