private DocumentBuilder newDocumentBuilder() { try { return documentFactoryBuilder.newDocumentBuilder(); } catch (ParserConfigurationException e) { throw ExceptionImposter.imposterize(e); } }
public static RuntimeException imposterize(Throwable t) { if (t instanceof RuntimeException) { return ( RuntimeException ) t; } return new ExceptionImposter(t); }
public ExceptionImposter(Throwable e) { super(e.getMessage(), e.getCause()); imposterized = e; setStackTrace(e.getStackTrace()); }
@Test public void testShouldImposterizeCheckedExceptionsAndKeepAReference() { original = new Exception(); RuntimeException imposter = ExceptionImposter.imposterize(original); assertTrue(imposter instanceof ExceptionImposter); assertSame(original, ( ( ExceptionImposter ) imposter ).getRealException()); }
public T newInstance(Object... args) { try { return type.cast(factoryMethod.invoke(null, args)); } catch (IllegalAccessException e) { throw ExceptionImposter.imposterize(e); } catch (InvocationTargetException e) { throw ExceptionImposter.imposterize(e.getCause()); } }
private DocumentBuilder newDocumentBuilder() { try { return documentFactoryBuilder.newDocumentBuilder(); } catch (ParserConfigurationException e) { LOG.error(LOG_ERROR, e); throw ExceptionImposter.imposterize(e); } }
private String getStyleContent() { try { InputStream is = RestRemoteRunner.class.getResource("style.css").openStream(); byte[] bytes = new byte[is.available()]; if (is.read(bytes) > 0) { return new String(bytes); } throw new IOException("Cannot read style.css resource from jar"); } catch (IOException ex) { throw ExceptionImposter.imposterize(ex); } } }
@Override public void specificationDone(Example spec, Statistics statistics) { try { String[] args1 = args(definitionRef); URI location = URI.create(URIUtil.raw(definitionRef.get(1))); List<Serializable> args = CollectionUtil.toList(args1[1], args1[2], (ArrayList<String>) CollectionUtil .toList(location.getFragment(), definitionRef.get(4), sut, XmlReport.toXml(documentRef))); String msg = getRestClient().saveExecutionResult(args); if (!("<success>".equals(msg))) { throw new IllegalStateException(msg); } } catch (LivingDocServerException e) { // Old server / incompatible method ? if (e.getMessage().indexOf(NoSuchMethodException.class.getName()) == -1) { // @todo : Log ? Critical ? Do we want the test execution to // fail if we can't post the result back ? throw ExceptionImposter.imposterize(e); } } catch (IllegalStateException e) { // @todo : Log ? Critical ? Do we want the test execution to // fail if we can't post the result back ? throw ExceptionImposter.imposterize(e); } catch (IOException e) { // @todo : Log ? Critical ? Do we want the test execution to // fail if we can't post the result back ? throw ExceptionImposter.imposterize(e); } } }
@Test public void testShouldCopyImposterizedExceptionStackTrace() { original = new Exception("Detail message"); original.fillInStackTrace(); RuntimeException imposter = ExceptionImposter.imposterize(original); assertTrue(Arrays.toString(imposter.getStackTrace()), Arrays.equals(original.getStackTrace(), imposter .getStackTrace())); }
@Test public void testShouldMimicImposterizedExceptionToStringOutput() { original = new Exception("Detail message"); RuntimeException imposter = ExceptionImposter.imposterize(original); assertEquals(original.toString(), imposter.toString()); }
@Test public void testShouldNotImposterizeUncheckedExceptions() { original = new RuntimeException(); assertSame(original, ExceptionImposter.imposterize(original)); }
@Test public void testShouldMimicImposterizedExceptionStackTraceOutput() { original = new Exception("Detail message"); original.fillInStackTrace(); RuntimeException imposter = ExceptionImposter.imposterize(original); assertEquals(captureStackTrace(original), captureStackTrace(imposter)); }