### Question:
RegionUtils { public static Region getRegionByEndpoint(String endpoint) { URI targetEndpointUri = getUriByEndpoint(endpoint); String targetHost = targetEndpointUri.getHost(); for (Region region : getRegions()) { for (String serviceEndpoint : region.getServiceEndpoints().values()) { URI serviceEndpointUrl = getUriByEndpoint(serviceEndpoint); if (serviceEndpointUrl.getHost().equals(targetHost)) return region; } } throw new IllegalArgumentException("No region found with any service for endpoint " + endpoint); }  static synchronized List<Region> getRegions(); @SuppressWarnings("checkstyle:hiddenfield") static synchronized List<Region> getRegionsForService(String serviceAbbreviation); static Region getRegion(String regionName); static Region getRegionByEndpoint(String endpoint); static synchronized void init();  }### Answer:
@Test public void testGetRegionByEndpoint() { Region usWest2 = RegionUtils.getRegionByEndpoint("s3.us-west-2.amazonaws.com"); Region standard = RegionUtils.getRegionByEndpoint("s3.amazonaws.com"); assertEquals(usWest2.getName(), "us-west-2"); assertEquals(usWest2.getServiceEndpoint(ServiceAbbreviations.S3), "s3.us-west-2.amazonaws.com"); assertEquals(standard.getName(), "us-east-1"); assertEquals(standard.getServiceEndpoint(ServiceAbbreviations.S3), "s3.amazonaws.com"); }
@Test(expected = IllegalArgumentException.class) public void testGetRegionByEndpointWithBogusEndpoint() { Region standard = RegionUtils.getRegionByEndpoint("bogus.amazonaws.com"); }