### Question:
CountryResolversImpl implements CountryResolvers { @Override public DataFetcher<Country> getCountryDataFetcher() { return environment -> { long countryId = getCountryId(environment); if (countryId <= 0) { return null; } return countryService.getCountry(countryId); }; }  @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 getCountryDataFetcher_should_return_the_searched_object() throws Exception { Country expectedResult = mock(Country.class); expectedResult.setCountryId(COUNTRY_ID); useSimpleGraphQLUtil(); when(mockEnvironment.getArgument("countryId")) .thenReturn(COUNTRY_ID); when(localService.getCountry(COUNTRY_ID)) .thenReturn(expectedResult); Country result = resolvers.getCountryDataFetcher() .get(mockEnvironment); assertNotNull(result); assertEquals(expectedResult, result); }
@Test public void getCountryDataFetcher_no_specified_id_should_return_null() throws Exception { when(mockEnvironment.getArgument("countryId")) .thenReturn(0L); Country result = resolvers.getCountryDataFetcher() .get(mockEnvironment); assertNull(result); }
@Test(expected = NoSuchCountryException.class) public void getCountryDataFetcher_with_unknown_id_should_return_null_with_exception() throws Exception { useSimpleGraphQLUtil(); when(mockEnvironment.getArgument("countryId")) .thenReturn(COUNTRY_ID); when(localService.getCountry(COUNTRY_ID)) .thenThrow(NoSuchCountryException.class); Country result = resolvers.getCountryDataFetcher() .get(mockEnvironment); assertNull(result); }