### Question:
UserGroupResolversImpl implements UserGroupResolvers { @Override public DataFetcher<CompletableFuture<UserGroup>> getUserGroupDataFetcher() { return environment -> { long userGroupId = getUserGroupId(environment); if (userGroupId <= 0) { return null; } DataLoader<Long, UserGroup> dataLoader = environment.getDataLoader(UserGroupBatchLoader.KEY); return dataLoader.load(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 getUserGroupDataFetcher_should_return_the_searched_object() throws Exception { UserGroup expectedResult = mock(UserGroup.class); expectedResult.setUserGroupId(USER_GROUP_ID); useSimpleGraphQLUtil(); when(mockEnvironment.getArgument("userGroupId")) .thenReturn(USER_GROUP_ID); when(dataLoader.load(USER_GROUP_ID)) .thenReturn(CompletableFuture.supplyAsync(() -> expectedResult)); CompletableFuture<UserGroup> asyncResult = resolvers.getUserGroupDataFetcher() .get(mockEnvironment); assertNotNull(asyncResult); UserGroup result = asyncResult.get(); assertNotNull(result); assertEquals(expectedResult, result); }
@Test public void getUserGroupDataFetcher_no_specified_id_should_return_null() throws Exception { when(mockEnvironment.getArgument("userGroupId")) .thenReturn(0L); CompletableFuture<UserGroup> asyncResult = resolvers.getUserGroupDataFetcher() .get(mockEnvironment); assertNull(asyncResult); }
@Test public void getUserGroupDataFetcher_with_unknown_id_should_return_null() throws Exception { useSimpleGraphQLUtil(); when(mockEnvironment.getArgument("userGroupId")) .thenReturn(USER_GROUP_ID); when(dataLoader.load(USER_GROUP_ID)) .thenReturn(CompletableFuture.supplyAsync(() -> null)); CompletableFuture<UserGroup> asyncResult = resolvers.getUserGroupDataFetcher() .get(mockEnvironment); assertNotNull(asyncResult); UserGroup result = asyncResult.get(); assertNull(result); }