### Question:
RegionResolversImpl implements RegionResolvers { @Override public DataFetcher<Region> getRegionDataFetcher() { return environment -> { long regionId = getRegionId(environment); if (regionId <= 0) { return null; } return regionService.getRegion(regionId); }; }  @Reference(unbind = "-") void setRegionService(RegionService regionService); @Reference void setUtil(GraphQLUtil util); @Override DataFetcher<List<Region>> getRegionsDataFetcher(); @Override DataFetcher<Region> getRegionDataFetcher(); @Override DataFetcher<Region> getRegionByCodeDataFetcher(); @Override DataFetcher<Region> createRegionDataFetcher();  }### Answer:
@Test public void getRegionDataFetcher_should_return_the_searched_object() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("regionId", REGION_ID); DataFetchingEnvironment environment = getTestEnvironment(arguments); Region expectedResult = mock(Region.class); expectedResult.setRegionId(REGION_ID); useSimpleGraphQLUtil(); when(localService.getRegion(REGION_ID)) .thenReturn(expectedResult); Region result = resolvers.getRegionDataFetcher() .get(environment); assertNotNull(result); assertEquals(expectedResult, result); }
@Test public void getRegionDataFetcher_no_specified_id_should_return_null() throws Exception { DataFetchingEnvironment environment = getTestEnvironment(null); useSimpleGraphQLUtil(); Region result = resolvers.getRegionDataFetcher() .get(environment); assertNull(result); }
@Test(expected = NoSuchRegionException.class) public void getRegionDataFetcher_with_unknown_id_should_return_null_with_exception() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("regionId", 789456L); DataFetchingEnvironment environment = getTestEnvironment(arguments); useSimpleGraphQLUtil(); when(localService.getRegion(789456L)) .thenThrow(NoSuchRegionException.class); Region result = resolvers.getRegionDataFetcher() .get(environment); assertNull(result); }