### Question:
AssetCategoryResolversImpl implements AssetCategoryResolvers { @Override public DataFetcher<List<AssetCategory>> getAssetCategoriesDataFetcher() { return environment -> { int start = util.getIntArg(environment, "start", 0); int end = util.getIntArg(environment, "end", 10); return assetCategoryLocalService.getAssetCategories(start, end); }; }  @Reference(unbind = "-") void setAssetCategoryLocalService(AssetCategoryLocalService assetCategoryLocalService); @Reference void setUtil(GraphQLUtil util); @Override DataFetcher<List<AssetCategory>> getAssetCategoriesDataFetcher(); @Override DataFetcher<List<AssetCategory>> getAssetCategoriesForAssetDataFetcher(); @Override DataFetcher<CompletableFuture<AssetCategory>> getAssetCategoryDataFetcher(); @Override DataFetcher<AssetCategory> createAssetCategoryDataFetcher(); @Override DataFetcher<AssetCategory> updateAssetCategoryDataFetcher(); @Override DataFetcher<AssetCategory> deleteAssetCategoryDataFetcher();  }### Answer:
@Test public void getAssetCategoriesDataFetcher_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<AssetCategory> availableObjects = new ArrayList<>(); IntStream.rangeClosed(1, 20) .forEach(value -> { AssetCategory entity = mock(AssetCategory.class); entity.setCategoryId(value); availableObjects.add(entity); }); List<AssetCategory> expectedResults = availableObjects.stream() .skip(3) .limit(3) .collect(Collectors.toList()); useSimpleGraphQLUtil(); when(localService.getAssetCategories(3, 3)) .thenReturn(expectedResults); List<AssetCategory> results = resolvers.getAssetCategoriesDataFetcher() .get(environment); assertNotNull(results); assertEquals(expectedResults, results); }
@Test public void getAssetCategoriesDataFetcher_without_args_should_return_10_first_objects() throws Exception { DataFetchingEnvironment environment = getTestEnvironment(null); List<AssetCategory> availableObjects = new ArrayList<>(); IntStream.rangeClosed(1, 20) .forEach(value -> { AssetCategory entity = mock(AssetCategory.class); entity.setCategoryId(value); availableObjects.add(entity); }); List<AssetCategory> expectedResults = availableObjects.stream() .skip(0) .limit(10) .collect(Collectors.toList()); useSimpleGraphQLUtil(); when(localService.getAssetCategories(0, 10)) .thenReturn(expectedResults); List<AssetCategory> results = resolvers.getAssetCategoriesDataFetcher() .get(environment); assertNotNull(results); assertEquals(expectedResults, results); }
@Test public void getAssetCategoriesDataFetcher_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<AssetCategory> expectedResults = new ArrayList<>(); IntStream.rangeClosed(1, 20) .forEach(value -> { AssetCategory entity = mock(AssetCategory.class); entity.setCategoryId(value); expectedResults.add(entity); }); useSimpleGraphQLUtil(); when(localService.getAssetCategories(0, 100)) .thenReturn(expectedResults); List<AssetCategory> results = resolvers.getAssetCategoriesDataFetcher() .get(environment); assertNotNull(results); assertEquals(expectedResults, results); }
@Test public void getAssetCategoriesDataFetcher_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<AssetCategory> expectedResults = new ArrayList<>(); useSimpleGraphQLUtil(); when(localService.getAssetCategories(0, 100)) .thenReturn(expectedResults); List<AssetCategory> results = resolvers.getAssetCategoriesDataFetcher() .get(environment); assertNotNull(results); assertEquals(expectedResults, results); }