### Question:
RoleResolversImpl implements RoleResolvers { @Override public DataFetcher<Role> deleteRoleDataFetcher() { return environment -> { long roleId = util.getLongArg(environment, "roleId"); return roleLocalService.deleteRole(roleId); }; }  @Reference(unbind = "-") void setRoleLocalService(RoleLocalService roleLocalService); @Reference void setUtil(GraphQLUtil util); @Override DataFetcher<List<Role>> getRolesDataFetcher(); @Override DataFetcher<CompletableFuture<Role>> getRoleDataFetcher(); @Override DataFetcher<Role> getRoleByNameDataFetcher(); @Override DataFetcher<Role> createRoleDataFetcher(); @Override DataFetcher<Role> updateRoleDataFetcher(); @Override DataFetcher<Role> deleteRoleDataFetcher();  }### Answer:
@Test public void deleteRoleDataFetcher_should_return_deleted_object() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("roleId", ROLE_ID); DataFetchingEnvironment environment = getTestEnvironment(arguments); Role expectedResult = mock(Role.class); expectedResult.setRoleId(ROLE_ID); useMockGraphQLUtil(environment, USER_ID, true); when(localService.deleteRole(eq(ROLE_ID))) .thenReturn(expectedResult); Role result = resolvers.deleteRoleDataFetcher() .get(environment); assertNotNull(result); assertEquals(expectedResult, result); }
@Test(expected = NoSuchRoleException.class) public void deleteRoleDataFetcher_without_args_should_return_null_with_exception() throws Exception { DataFetchingEnvironment environment = getTestEnvironment(null); Role expectedResult = mock(Role.class); expectedResult.setRoleId(ROLE_ID); useMockGraphQLUtil(environment, USER_ID, true); when(localService.deleteRole(eq(ROLE_ID))) .thenThrow(NoSuchRoleException.class); Role result = resolvers.deleteRoleDataFetcher() .get(environment); assertNull(result); }
@Test(expected = NoSuchRoleException.class) public void deleteRoleDataFetcher_with_invalid_id_should_return_null_with_exception() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("roleId", 789456L); DataFetchingEnvironment environment = getTestEnvironment(arguments); Role expectedResult = mock(Role.class); expectedResult.setRoleId(ROLE_ID); useMockGraphQLUtil(environment, USER_ID, false); when(graphQLUtil.getLongArg(eq(environment), eq("roleId"))) .thenReturn(789456L); when(localService.deleteRole(eq(789456L))) .thenThrow(NoSuchRoleException.class); Role result = resolvers.deleteRoleDataFetcher() .get(environment); assertNull(result); }