### Question:
ListTypeResolversImpl implements ListTypeResolvers { @Override public DataFetcher<List<ListType>> getListTypesDataFetcher() { return environment -> { int start = util.getIntArg(environment, "start", 0); int end = util.getIntArg(environment, "end", 10); return listtypeLocalService.getListTypes(start, end); }; }  @Reference(unbind = "-") void setListTypeLocalService(ListTypeLocalService listtypeLocalService); @Reference void setUtil(GraphQLUtil util); @Override DataFetcher<List<ListType>> getListTypesDataFetcher(); @Override DataFetcher<List<ListType>> getListTypesByTypeDataFetcher(); @Override DataFetcher<CompletableFuture<ListType>> getListTypeDataFetcher(); @Override DataFetcher<ListType> createListTypeDataFetcher(); @Override DataFetcher<ListType> deleteListTypeDataFetcher();  }### Answer:
@Test public void getListTypesDataFetcher_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<ListType> availableObjects = new ArrayList<>(); IntStream.rangeClosed(1, 20) .forEach(value -> { ListType entity = mock(ListType.class); entity.setListTypeId(value); availableObjects.add(entity); }); List<ListType> expectedResults = availableObjects.stream() .skip(3) .limit(3) .collect(Collectors.toList()); useSimpleGraphQLUtil(); when(localService.getListTypes(3, 3)) .thenReturn(expectedResults); List<ListType> results = resolvers.getListTypesDataFetcher() .get(environment); assertNotNull(results); assertEquals(expectedResults, results); }
@Test public void getListTypesDataFetcher_without_args_should_return_10_first_objects() throws Exception { DataFetchingEnvironment environment = getTestEnvironment(null); List<ListType> availableObjects = new ArrayList<>(); IntStream.rangeClosed(1, 20) .forEach(value -> { ListType entity = mock(ListType.class); entity.setListTypeId(value); availableObjects.add(entity); }); List<ListType> expectedResults = availableObjects.stream() .skip(0) .limit(10) .collect(Collectors.toList()); useSimpleGraphQLUtil(); when(localService.getListTypes(0, 10)) .thenReturn(expectedResults); List<ListType> results = resolvers.getListTypesDataFetcher() .get(environment); assertNotNull(results); assertEquals(expectedResults, results); }
@Test public void getListTypesDataFetcher_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<ListType> expectedResults = new ArrayList<>(); IntStream.rangeClosed(1, 20) .forEach(value -> { ListType entity = mock(ListType.class); entity.setListTypeId(value); expectedResults.add(entity); }); useSimpleGraphQLUtil(); when(localService.getListTypes(0, 100)) .thenReturn(expectedResults); List<ListType> results = resolvers.getListTypesDataFetcher() .get(environment); assertNotNull(results); assertEquals(expectedResults, results); }
@Test public void getListTypesDataFetcher_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<ListType> expectedResults = new ArrayList<>(); useSimpleGraphQLUtil(); when(localService.getListTypes(0, 100)) .thenReturn(expectedResults); List<ListType> results = resolvers.getListTypesDataFetcher() .get(environment); assertNotNull(results); assertEquals(expectedResults, results); }