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