### Question:
RegionResolversImpl implements RegionResolvers { @Override public DataFetcher<Region> createRegionDataFetcher() { return environment -> { long countryId = util.getLongArg(environment, "countryId"); String regionCode = util.getStringArg(environment, "regionCode"); String name = util.getStringArg(environment, "name"); boolean active = util.getBooleanArg(environment, "active"); return regionService.addRegion( countryId, regionCode, name, active); }; }  @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 createRegionDataFetcher_should_return_new_object() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("countryId", COUNTRY_ID); arguments.put("regionCode", REGION_CODE); arguments.put("name", NAME); arguments.put("active", ACTIVE); DataFetchingEnvironment environment = getTestEnvironment(arguments); Region expectedResult = mock(Region.class); expectedResult.setRegionId(REGION_ID); expectedResult.setCountryId(COUNTRY_ID); expectedResult.setRegionCode(REGION_CODE); expectedResult.setName(NAME); expectedResult.setActive(ACTIVE); useMockGraphQLUtil(environment, true); when(localService.addRegion(eq(COUNTRY_ID), eq(REGION_CODE), eq(NAME), eq(ACTIVE))) .thenReturn(expectedResult); Region result = resolvers.createRegionDataFetcher() .get(environment); assertNotNull(result); assertEquals(expectedResult, result); }
@Test(expected = PortalException.class) public void createRegionDataFetcher_without_args_should_throw_validation_exception() throws Exception { DataFetchingEnvironment environment = getTestEnvironment(null); useMockGraphQLUtil(environment, false); when(localService.addRegion(anyLong(), anyString(), anyString(), anyBoolean())) .thenThrow(PortalException.class); Region result = resolvers.createRegionDataFetcher() .get(environment); assertNull(result); }