### Question:
TypeAdapter { T adapt(S value) { try { T result = resultClass.cast(adapterMethod.invoke(null, value)); if(result==null) { throw new IllegalStateException(getAdapterFailureMessage("could not adapt value '%s",value)); } return result; } catch (IllegalArgumentException e) { throw new IllegalStateException(getAdapterFailureMessage("should accept '%s'",value.getClass().getCanonicalName()),e); } catch (IllegalAccessException e) { throw new IllegalStateException(getAdapterFailureMessage("should be accesible"),e); } catch (InvocationTargetException e) { throw new IllegalStateException(getAdapterFailureMessage("failed while adapting value '%s'",value),e); } } private  TypeAdapter(Method adapterMethod, Class<? extends T> resultClass);   }### Answer:
@Test public void testAdapt$URI() { assertThat(TypeAdapter.adapt(RDF.TYPE,URI.class),equalTo(URI.create(RDF.TYPE.qualifiedEntityName()))); }
@Test public void testAdapt$QName() { assertThat(TypeAdapter.adapt(RDF.TYPE,QName.class),equalTo(new QName(RDF.NAMESPACE,RDF.TYPE.entityName(),RDF.NS_PREFIX))); }
@Test public void testAdapt$notFound() { try { TypeAdapter.adapt("uri",URI.class); fail("Should not adapt String to URI"); } catch (CannotAdaptClassesException e) { assertThat(e.getMessage(),equalTo("Could not find adapter of adapting class 'java.lang.String' to 'java.net.URI'")); } }
@Test public void testAdapt$nullResult() { new MockUp<TypeAdapter.URIAdapter>() { @Mock public URI adaptTo(Term term) { return null; } }; try { TypeAdapter.adapt(RDF.TYPE,URI.class); fail("Should not adapt Term to URI if null is returned"); } catch (IllegalStateException e) { assertThat(e.getMessage(),equalTo(COULD_NOT_ADAPT)); } }
@Test public void testAdapt$invocationTargetException() { new MockUp<TypeAdapter.URIAdapter>() { @Mock public URI adaptTo(Term term) { throw new IllegalArgumentException("FAILURE"); } }; try { TypeAdapter.adapt(RDF.TYPE,URI.class); fail("Should not adapt Term to URI if InvocationTargetException is thrown"); } catch (IllegalStateException e) { assertThat(e.getMessage(),equalTo(ADAPTER_FAILED)); Throwable rootCause = Throwables.getRootCause(e); assertThat(rootCause,instanceOf(IllegalArgumentException.class)); assertThat(rootCause.getMessage(),equalTo("FAILURE")); } }