FindLocationForResource implements Function<ReferenceType, Location> { public Location apply(ReferenceType resource) { for (Location input : locations.get()) { do { if (URI.create(input.getId()).equals(resource.getHref())) return input; } while ((input = input.getParent()) != null); } throw new NoSuchElementException(String.format("resource: %s not found in locations: %s", resource, locations.get())); } @Inject  FindLocationForResource(@Memoized Supplier<Set<? extends Location>> locations); Location apply(ReferenceType resource);  }
@Test(expectedExceptions = NoSuchElementException.class) public void testGracefulWhenHrefIsntLocationId() { FindLocationForResource converter = new FindLocationForResource( Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet.<Location> of(new LocationBuilder() .id("http: converter.apply(new ReferenceTypeImpl("name", "type", URI.create("http: }
@Test(expectedExceptions = NoSuchElementException.class) public void testGracefulWhenLocationIdIsntURI() { FindLocationForResource converter = new FindLocationForResource( Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet.<Location> of(new LocationBuilder().id("1") .description("description").scope(LocationScope.PROVIDER).build()))); converter.apply(new ReferenceTypeImpl("name", "type", URI.create("http: }