FirstRegion implements ImplicitLocationSupplier { @Override public Location get() { Set<? extends Location> locations = locationsSupplier.get(); try { return find(locations, isRegion()); } catch (NoSuchElementException e) { throw new NoSuchElementException("none to of the locations are scope REGION: " + transform(locations, ToIdAndScope.INSTANCE)); } } @Inject  FirstRegion(@Memoized Supplier<Set<? extends Location>> locationsSupplier); @Override Location get();  }
@Test public void testDidntFindRegionThrowsNSEEWithReasonableMessage() { Supplier<Set<? extends Location>> supplier = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet .<Location> of(provider, zone)); FirstRegion fn = new FirstRegion(supplier); try { fn.get(); fail("Expected NoSuchElementException"); } catch (NoSuchElementException e) { assertEquals(e.getMessage(), "none to of the locations are scope REGION: [servo:PROVIDER, servo-z:ZONE]"); } }