### Question:
RoleResolversImpl implements RoleResolvers { @Override public DataFetcher<CompletableFuture<Role>> getRoleDataFetcher() { return environment -> { long roleId = util.getLongArg(environment, "roleId"); if (roleId <= 0) { return null; } DataLoader<Long, Role> dataLoader = environment.getDataLoader(RoleBatchLoader.KEY); return dataLoader.load(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 getRoleDataFetcher_should_return_the_searched_object() throws Exception { Role expectedResult = mock(Role.class); expectedResult.setRoleId(ROLE_ID); useSimpleGraphQLUtil(); when(mockEnvironment.getArgument("roleId")) .thenReturn(ROLE_ID); when(dataLoader.load(ROLE_ID)) .thenReturn(CompletableFuture.supplyAsync(() -> expectedResult)); CompletableFuture<Role> asyncResult = resolvers.getRoleDataFetcher() .get(mockEnvironment); assertNotNull(asyncResult); Role result = asyncResult.get(); assertNotNull(result); assertEquals(expectedResult, result); }
@Test public void getRoleDataFetcher_no_specified_id_should_return_null() throws Exception { when(mockEnvironment.getArgument("roleId")) .thenReturn(0L); CompletableFuture<Role> asyncResult = resolvers.getRoleDataFetcher() .get(mockEnvironment); assertNull(asyncResult); }
@Test public void getRoleDataFetcher_with_unknown_id_should_return_null() throws Exception { useSimpleGraphQLUtil(); when(mockEnvironment.getArgument("roleId")) .thenReturn(ROLE_ID); when(dataLoader.load(ROLE_ID)) .thenReturn(CompletableFuture.supplyAsync(() -> null)); CompletableFuture<Role> asyncResult = resolvers.getRoleDataFetcher() .get(mockEnvironment); assertNotNull(asyncResult); Role result = asyncResult.get(); assertNull(result); }