@Override public List<String> getChildren(String path) { try { return client.getChildren().forPath(path); } catch (NoNodeException e) { return null; } catch (Exception e) { throw new IllegalStateException(e.getMessage(), e); } }
@Override protected void execute() { try { drainQueue(); } catch (Exception e) { e.printStackTrace(); } } });
@Override public Object apply(Long aLong) throws Exception { throw new Exception(); } });
private Exception test() { Exception e = new Exception(); try { Thread.sleep(50); } catch (Exception ex) { e = ex; } e.printStackTrace(); return e; } }
public void testCheckedThrowableSync(CacheableService<?> service) throws Exception { String arg = UUID.randomUUID().toString(); try { service.throwCheckedSync(arg); fail("Excepted exception"); } catch (Exception ex) { ex.printStackTrace(); assertEquals("Wrong exception type", IOException.class, ex.getClass()); assertEquals(arg, ex.getMessage()); } }
@Test @Ignore("Observers can't throw") public void onCompleteSuccessWithUnsubscribeFailure() { Subscriber<String> subscriber = subscriberSuccess(); try { subscriber.onSubscribe(THROWING_DISPOSABLE); new SafeSubscriber<String>(subscriber).onComplete(); fail("expects exception to be thrown"); } catch (Exception e) { e.printStackTrace(); // FIXME no longer assertable // assertTrue(o.isUnsubscribed()); // assertTrue(e instanceof UnsubscribeFailedException); assertTrue(e.getCause() instanceof SafeSubscriberTestException); assertEquals("failure from unsubscribe", e.getMessage()); // expected since onError fails so SafeSubscriber can't help } }
@Test public void handleClientMessageProcessingError() throws Exception { Exception ex = new Exception("fake exception"); Message<byte[]> actual = this.handler.handleClientMessageProcessingError(null, ex); StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(actual, StompHeaderAccessor.class); assertNotNull(accessor); assertEquals(StompCommand.ERROR, accessor.getCommand()); assertEquals(ex.getMessage(), accessor.getMessage()); assertArrayEquals(new byte[0], actual.getPayload()); }
public void testGetRootCause_Loop() { Exception cause = new Exception(); Exception exception = new Exception(cause); cause.initCause(exception); try { Throwables.getRootCause(cause); fail("Should have throw IAE"); } catch (IllegalArgumentException expected) { assertThat(expected).hasCauseThat().isSameAs(cause); } }
private void assertIsCompiled(Expression expression) { try { Field field = SpelExpression.class.getDeclaredField("compiledAst"); field.setAccessible(true); Object object = field.get(expression); assertNotNull(object); } catch (Exception ex) { fail(ex.toString()); } }
@Override public TestException apply(Exception from) { if (from instanceof ExecutionException) { return new TestException(from.getCause()); } else { assertTrue( "got " + from.getClass(), from instanceof InterruptedException || from instanceof CancellationException); return new TestException(from); } } };
public ClassNode getClassNode(Class<?> clazz) { try { File jar = getJarForClass(clazz); return getClassNodeFromFile(jar, clazz.getName()); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } return null; }
@Test @Ignore("Observers can't throw") public void onCompleteSuccessWithUnsubscribeFailure() { Observer<String> o = OBSERVER_SUCCESS(); try { o.onSubscribe(THROWING_DISPOSABLE); new SafeObserver<String>(o).onComplete(); fail("expects exception to be thrown"); } catch (Exception e) { e.printStackTrace(); // FIXME no longer assertable // assertTrue(o.isUnsubscribed()); // assertTrue(e instanceof UnsubscribeFailedException); assertTrue(e.getCause() instanceof SafeObserverTestException); assertEquals("failure from unsubscribe", e.getMessage()); // expected since onError fails so SafeObserver can't help } }
public void testGetCasualChainLoop() { Exception cause = new Exception(); Exception exception = new Exception(cause); cause.initCause(exception); try { Throwables.getCausalChain(cause); fail("Should have throw IAE"); } catch (IllegalArgumentException expected) { assertThat(expected).hasCauseThat().isSameAs(cause); } }
@Test @Ignore("Observers can't throw") public void onErrorNotImplementedFailureSafe() { try { new SafeObserver<String>(OBSERVER_ONERROR_NOTIMPLEMENTED()).onError(new SafeObserverTestException("error!")); fail("expects exception to be thrown"); } catch (Exception e) { // assertTrue(e instanceof OnErrorNotImplementedException); assertTrue(e.getCause() instanceof SafeObserverTestException); assertEquals("error!", e.getCause().getMessage()); } }
@Override public String doGetContent(String path) { try { byte[] dataBytes = client.getData().forPath(path); return (dataBytes == null || dataBytes.length == 0) ? null : new String(dataBytes, charset); } catch (NoNodeException e) { // ignore NoNode Exception. } catch (Exception e) { throw new IllegalStateException(e.getMessage(), e); } return null; }
protected void generateClsCode(ClassNode cls) { try { new CodeGen().visit(cls); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
private void logParsingError(Element element, Class<? extends Annotation> annotation, Exception e) { StringWriter stackTrace = new StringWriter(); e.printStackTrace(new PrintWriter(stackTrace)); error(element, "Unable to parse @%s binding.\n\n%s", annotation.getSimpleName(), stackTrace); }
@Override public Object apply(Long aLong) throws Exception { throw new Exception(); } });
@Test @Ignore("Observers can't throw") public void onErrorNotImplementedFailureSafe() { try { new SafeSubscriber<String>(subscriberOnErrorNotImplemented()).onError(new SafeSubscriberTestException("error!")); fail("expects exception to be thrown"); } catch (Exception e) { // assertTrue(e instanceof OnErrorNotImplementedException); assertTrue(e.getCause() instanceof SafeSubscriberTestException); assertEquals("error!", e.getCause().getMessage()); } }
@Override public String handleException(Exception exception) { return exception.getMessage(); } }