### Question:
UriBuilder implements SpecimenBuilder { @Override public Object create(Object request, SpecimenContext context) { if (!request.equals(URI.class)) { return new NoSpecimen(); } Object specimen = context.resolve(URL.class); if (!(specimen instanceof URL)) { return new NoSpecimen(); } URL url = (URL) specimen; try { return url.toURI(); } catch (URISyntaxException e) { return new NoSpecimen(); } }  @Override Object create(Object request, SpecimenContext context);  }### Answer:
@Test public void non_uri_type_request_returns_no_specimen() { Object result = this.uriBuilder.create(Integer.class, this.mockSpecimenContext); assertEquals(new NoSpecimen(), result); }
@Test public void uri_type_request_asks_context_for_url() { this.uriBuilder.create(URI.class, this.mockSpecimenContext); verify(this.mockSpecimenContext).resolve(URL.class); }
@Test public void returns_no_specimen_if_context_returns_non_url_object() { when(this.mockSpecimenContext.resolve(URL.class)).thenReturn("string"); Object specimen = this.uriBuilder.create(URI.class, this.mockSpecimenContext); assertEquals(new NoSpecimen(), specimen); }
@Test public void returns_uri_if_context_returns_url_object() throws MalformedURLException { when(this.mockSpecimenContext.resolve(URL.class)).thenReturn(new URL("http: Object specimen = this.uriBuilder.create(URI.class, this.mockSpecimenContext); assertTrue(specimen instanceof URI); }
@Test public void returns_url_as_uri_if_context_returns_url_object() throws MalformedURLException { URL expectedUrl = new URL("http: when(this.mockSpecimenContext.resolve(URL.class)).thenReturn(expectedUrl); URI uri = (URI) this.uriBuilder.create(URI.class, this.mockSpecimenContext); assertEquals(expectedUrl, uri.toURL()); }