### Question:
CountryResolversImpl implements CountryResolvers { @Override public DataFetcher<List<Country>> getCountriesDataFetcher() { return environment -> { boolean active = util.getBooleanArg(environment, "active", true); return countryService.getCountries(active); }; }  @Reference(unbind = "-") void setCountryService(CountryService countryService); @Reference void setUtil(GraphQLUtil util); @Override DataFetcher<List<Country>> getCountriesDataFetcher(); @Override DataFetcher<Country> getCountryDataFetcher(); @Override DataFetcher<Country> getCountryByA2DataFetcher(); @Override DataFetcher<Country> getCountryByA3DataFetcher(); @Override DataFetcher<Country> getCountryByNameDataFetcher(); @Override DataFetcher<Country> createCountryDataFetcher();  }### Answer:
@Test public void getCountriesDataFetcher_should_return_the_active_objects() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("active", ACTIVE); DataFetchingEnvironment environment = getTestEnvironment(arguments); List<Country> availableObjects = new ArrayList<>(); IntStream.rangeClosed(1, 20) .forEach(value -> { Country entity = mock(Country.class); entity.setCountryId(value); entity.setActive(random.nextBoolean()); availableObjects.add(entity); }); List<Country> expectedResults = availableObjects.stream() .filter(Country::getActive) .collect(Collectors.toList()); useSimpleGraphQLUtil(); when(localService.getCountries(ACTIVE)) .thenReturn(expectedResults); List<Country> results = resolvers.getCountriesDataFetcher() .get(environment); assertNotNull(results); assertEquals(expectedResults, results); }
@Test public void getCountriesDataFetcher_without_args_should_return_the_active_objects() throws Exception { DataFetchingEnvironment environment = getTestEnvironment(null); List<Country> availableObjects = new ArrayList<>(); IntStream.rangeClosed(1, 20) .forEach(value -> { Country entity = mock(Country.class); entity.setCountryId(value); entity.setActive(random.nextBoolean()); availableObjects.add(entity); }); List<Country> expectedResults = availableObjects.stream() .filter(Country::getActive) .collect(Collectors.toList()); useSimpleGraphQLUtil(); when(localService.getCountries(ACTIVE)) .thenReturn(expectedResults); List<Country> results = resolvers.getCountriesDataFetcher() .get(environment); assertNotNull(results); assertEquals(expectedResults, results); }
@Test public void getCountriesDataFetcher_no_objects_available_should_return_empty_list() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("active", ACTIVE); DataFetchingEnvironment environment = getTestEnvironment(arguments); List<Country> expectedResults = new ArrayList<>(); useSimpleGraphQLUtil(); when(localService.getCountries(ACTIVE)) .thenReturn(expectedResults); List<Country> results = resolvers.getCountriesDataFetcher() .get(environment); assertNotNull(results); assertEquals(expectedResults, results); }