### Question:
UriForResource implements Function<Object, URI> { @Override public URI apply(Object input) { checkArgument(checkNotNull(input, "input") instanceof Resource, "This function can only be applied to Resource objects"); return ((Resource) input).getUrl(); }  @Override URI apply(Object input);  }### Answer:
@Test public void testWithValidResource() { Function<Object, URI> function = new UriForResource(); Resource res = Resource.builder().name("test").url(URI.create("http: URI result = function.apply(res); assertEquals(res.getUrl().toString(), result.toString()); }
@Test(expectedExceptions = NullPointerException.class) public void testWithNullInput() { Function<Object, URI> function = new UriForResource(); function.apply(null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testWithInvalidInput() { Function<Object, URI> function = new UriForResource(); function.apply(new Object()); }
@Test public void testWithValidResource() { Function<Object, URI> function = new UriForResource(); Resource res = new Resource("test", URI.create("http: URI result = function.apply(res); assertEquals(res.getUrl().toString(), result.toString()); }