@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")); } }
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); } }
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); } } }
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); }
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);  }
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);   }