### Question:
UserResolversImpl implements UserResolvers { @Override public DataFetcher<CompletableFuture<User>> getUserDataFetcher() { return environment -> { long userId = getUserId(environment); if (userId <= 0) { return null; } DataLoader<Long, User> dataLoader = environment.getDataLoader(UserBatchLoader.KEY); return dataLoader.load(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 getUserDataFetcher_should_return_the_searched_object() throws Exception { User expectedResult = mock(User.class); expectedResult.setUserId(USER_ID); useSimpleGraphQLUtil(); when(mockEnvironment.getArgument("userId")) .thenReturn(USER_ID); when(dataLoader.load(USER_ID)) .thenReturn(CompletableFuture.supplyAsync(() -> expectedResult)); CompletableFuture<User> asyncResult = resolvers.getUserDataFetcher() .get(mockEnvironment); assertNotNull(asyncResult); User result = asyncResult.get(); assertNotNull(result); assertEquals(expectedResult, result); }
@Test public void getUserDataFetcher_no_specified_id_should_return_null() throws Exception { when(mockEnvironment.getArgument("userId")) .thenReturn(0L); CompletableFuture<User> asyncResult = resolvers.getUserDataFetcher() .get(mockEnvironment); assertNull(asyncResult); }
@Test public void getUserDataFetcher_with_unknown_id_should_return_null() throws Exception { useSimpleGraphQLUtil(); when(mockEnvironment.getArgument("userId")) .thenReturn(USER_ID); when(dataLoader.load(USER_ID)) .thenReturn(CompletableFuture.supplyAsync(() -> null)); CompletableFuture<User> asyncResult = resolvers.getUserDataFetcher() .get(mockEnvironment); assertNotNull(asyncResult); User result = asyncResult.get(); assertNull(result); }