### Question:
GroupResolversImpl implements GroupResolvers { @Override public DataFetcher<List<Group>> getGroupsDataFetcher() { return environment -> { int start = util.getIntArg(environment, "start", 0); int end = util.getIntArg(environment, "end", 10); return groupLocalService.getGroups(start, end); }; }  @Reference(unbind = "-") void setGroupLocalService(GroupLocalService groupLocalService); @Reference void setUtil(GraphQLUtil util); @Override DataFetcher<List<Group>> getGroupsDataFetcher(); @Override DataFetcher<CompletableFuture<Group>> getGroupDataFetcher(); @Override DataFetcher<Group> getGroupByKeyDataFetcher(); @Override DataFetcher<Group> createGroupDataFetcher(); @Override DataFetcher<Group> updateGroupDataFetcher(); @Override DataFetcher<Group> deleteGroupDataFetcher();  }### Answer:
@Test public void getGroupsDataFetcher_should_return_the_specified_number_of_objects() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("start", 3); arguments.put("end", 3); DataFetchingEnvironment environment = getTestEnvironment(arguments); List<Group> availableObjects = new ArrayList<>(); IntStream.rangeClosed(1, 20) .forEach(value -> { Group entity = mock(Group.class); entity.setGroupId(value); availableObjects.add(entity); }); List<Group> expectedResults = availableObjects.stream() .skip(3) .limit(3) .collect(Collectors.toList()); useSimpleGraphQLUtil(); when(localService.getGroups(3, 3)) .thenReturn(expectedResults); List<Group> results = resolvers.getGroupsDataFetcher() .get(environment); assertNotNull(results); assertEquals(expectedResults, results); }
@Test public void getGroupsDataFetcher_without_args_should_return_10_first_objects() throws Exception { DataFetchingEnvironment environment = getTestEnvironment(null); List<Group> availableObjects = new ArrayList<>(); IntStream.rangeClosed(1, 20) .forEach(value -> { Group entity = mock(Group.class); entity.setGroupId(value); availableObjects.add(entity); }); List<Group> expectedResults = availableObjects.stream() .skip(0) .limit(10) .collect(Collectors.toList()); useSimpleGraphQLUtil(); when(localService.getGroups(0, 10)) .thenReturn(expectedResults); List<Group> results = resolvers.getGroupsDataFetcher() .get(environment); assertNotNull(results); assertEquals(expectedResults, results); }
@Test public void getGroupsDataFetcher_with_big_range_args_should_return_only_available_objects() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("start", 0); arguments.put("end", 100); DataFetchingEnvironment environment = getTestEnvironment(arguments); List<Group> expectedResults = new ArrayList<>(); IntStream.rangeClosed(1, 20) .forEach(value -> { Group entity = mock(Group.class); entity.setGroupId(value); expectedResults.add(entity); }); useSimpleGraphQLUtil(); when(localService.getGroups(0, 100)) .thenReturn(expectedResults); List<Group> results = resolvers.getGroupsDataFetcher() .get(environment); assertNotNull(results); assertEquals(expectedResults, results); }
@Test public void getGroupsDataFetcher_no_objects_available_should_return_empty_list() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("start", 0); arguments.put("end", 100); DataFetchingEnvironment environment = getTestEnvironment(arguments); List<Group> expectedResults = new ArrayList<>(); useSimpleGraphQLUtil(); when(localService.getGroups(0, 100)) .thenReturn(expectedResults); List<Group> results = resolvers.getGroupsDataFetcher() .get(environment); assertNotNull(results); assertEquals(expectedResults, results); }