/** * Cast the given Throwable to CompositeException and returns its inner * Throwable list. * @param ex the target Throwable * @return the list of Throwables */ public static List<Throwable> compositeList(Throwable ex) { if (ex instanceof UndeliverableException) { ex = ex.getCause(); } return ((CompositeException)ex).getExceptions(); }
/** * Cast the given Throwable to CompositeException and returns its inner * Throwable list. * @param ex the target Throwable * @return the list of Throwables */ public static List<Throwable> compositeList(Throwable ex) { if (ex instanceof UndeliverableException) { ex = ex.getCause(); } return ((CompositeException)ex).getExceptions(); }
public static void assertError(TestSubscriber<?> ts, int index, Class<? extends Throwable> clazz) { Throwable ex = ts.errors().get(0); if (ex instanceof CompositeException) { CompositeException ce = (CompositeException) ex; List<Throwable> cel = ce.getExceptions(); assertTrue(cel.get(index).toString(), clazz.isInstance(cel.get(index))); } else { fail(ex.toString() + ": not a CompositeException"); } }
public static void assertError(TestSubscriber<?> ts, int index, Class<? extends Throwable> clazz) { Throwable ex = ts.errors().get(0); if (ex instanceof CompositeException) { CompositeException ce = (CompositeException) ex; List<Throwable> cel = ce.getExceptions(); assertTrue(cel.get(index).toString(), clazz.isInstance(cel.get(index))); } else { fail(ex.toString() + ": not a CompositeException"); } }
public static void assertError(TestSubscriber<?> ts, int index, Class<? extends Throwable> clazz, String message) { Throwable ex = ts.errors().get(0); if (ex instanceof CompositeException) { CompositeException ce = (CompositeException) ex; List<Throwable> cel = ce.getExceptions(); assertTrue(cel.get(index).toString(), clazz.isInstance(cel.get(index))); assertEquals(message, cel.get(index).getMessage()); } else { fail(ex.toString() + ": not a CompositeException"); } }
public static void assertError(TestObserver<?> ts, int index, Class<? extends Throwable> clazz, String message) { Throwable ex = ts.errors().get(0); if (ex instanceof CompositeException) { CompositeException ce = (CompositeException) ex; List<Throwable> cel = ce.getExceptions(); assertTrue(cel.get(index).toString(), clazz.isInstance(cel.get(index))); assertEquals(message, cel.get(index).getMessage()); } else { fail(ex.toString() + ": not a CompositeException"); } }
public static void assertError(TestObserver<?> ts, int index, Class<? extends Throwable> clazz, String message) { Throwable ex = ts.errors().get(0); if (ex instanceof CompositeException) { CompositeException ce = (CompositeException) ex; List<Throwable> cel = ce.getExceptions(); assertTrue(cel.get(index).toString(), clazz.isInstance(cel.get(index))); assertEquals(message, cel.get(index).getMessage()); } else { fail(ex.toString() + ": not a CompositeException"); } }
public static void assertError(TestSubscriber<?> ts, int index, Class<? extends Throwable> clazz, String message) { Throwable ex = ts.errors().get(0); if (ex instanceof CompositeException) { CompositeException ce = (CompositeException) ex; List<Throwable> cel = ce.getExceptions(); assertTrue(cel.get(index).toString(), clazz.isInstance(cel.get(index))); assertEquals(message, cel.get(index).getMessage()); } else { fail(ex.toString() + ": not a CompositeException"); } }
public static void assertError(TestObserver<?> ts, int index, Class<? extends Throwable> clazz) { Throwable ex = ts.errors().get(0); try { if (ex instanceof CompositeException) { CompositeException ce = (CompositeException) ex; List<Throwable> cel = ce.getExceptions(); assertTrue(cel.get(index).toString(), clazz.isInstance(cel.get(index))); } else { fail(ex.toString() + ": not a CompositeException"); } } catch (AssertionError e) { ex.printStackTrace(); throw e; } }
@Test public void constructorWithNull() { assertTrue(new CompositeException((Throwable[])null).getExceptions().get(0) instanceof NullPointerException); assertTrue(new CompositeException((Iterable<Throwable>)null).getExceptions().get(0) instanceof NullPointerException); assertTrue(new CompositeException(null, new TestException()).getExceptions().get(0) instanceof NullPointerException); }
@Test(timeout = 1000) public void testMultipleWithSameCause() { Throwable rootCause = new Throwable("RootCause"); Throwable e1 = new Throwable("1", rootCause); Throwable e2 = new Throwable("2", rootCause); Throwable e3 = new Throwable("3", rootCause); CompositeException ce = new CompositeException(e1, e2, e3); System.err.println("----------------------------- print composite stacktrace"); ce.printStackTrace(); assertEquals(3, ce.getExceptions().size()); assertNoCircularReferences(ce); assertNotNull(getRootCause(ce)); System.err.println("----------------------------- print cause stacktrace"); ce.getCause().printStackTrace(); }
@Test(timeout = 5000) public void doOnErrorThrows() { Completable c = error.completable.doOnError(new Consumer<Throwable>() { @Override public void accept(Throwable e) { throw new IllegalStateException(); } }); try { c.blockingAwait(); } catch (CompositeException ex) { List<Throwable> a = ex.getExceptions(); Assert.assertEquals(2, a.size()); Assert.assertTrue(a.get(0) instanceof TestException); Assert.assertTrue(a.get(1) instanceof IllegalStateException); } }
@Test(timeout = 1000) public void testCompositeExceptionFromParentThenChild() { CompositeException cex = new CompositeException(ex1, ex2); System.err.println("----------------------------- print composite stacktrace"); cex.printStackTrace(); assertEquals(2, cex.getExceptions().size()); assertNoCircularReferences(cex); assertNotNull(getRootCause(cex)); System.err.println("----------------------------- print cause stacktrace"); cex.getCause().printStackTrace(); }
@Test(timeout = 1000) public void testCompositeExceptionFromTwoDuplicateComposites() { List<Throwable> exs = new ArrayList<Throwable>(); exs.add(getNewCompositeExceptionWithEx123()); exs.add(getNewCompositeExceptionWithEx123()); CompositeException cex = new CompositeException(exs); System.err.println("----------------------------- print composite stacktrace"); cex.printStackTrace(); assertEquals(3, cex.getExceptions().size()); assertNoCircularReferences(cex); assertNotNull(getRootCause(cex)); System.err.println("----------------------------- print cause stacktrace"); cex.getCause().printStackTrace(); }
@Test(timeout = 1000) public void testCompositeExceptionFromChildThenParent() { CompositeException cex = new CompositeException(ex2, ex1); System.err.println("----------------------------- print composite stacktrace"); cex.printStackTrace(); assertEquals(2, cex.getExceptions().size()); assertNoCircularReferences(cex); assertNotNull(getRootCause(cex)); System.err.println("----------------------------- print cause stacktrace"); cex.getCause().printStackTrace(); }
@Test(timeout = 1000) public void testCompositeExceptionFromCompositeAndChild() { CompositeException cex = new CompositeException(getNewCompositeExceptionWithEx123(), ex1); System.err.println("----------------------------- print composite stacktrace"); cex.printStackTrace(); assertEquals(3, cex.getExceptions().size()); assertNoCircularReferences(cex); assertNotNull(getRootCause(cex)); System.err.println("----------------------------- print cause stacktrace"); cex.getCause().printStackTrace(); }
@Test(timeout = 1000) public void testCompositeExceptionFromChildAndComposite() { CompositeException cex = new CompositeException(ex1, getNewCompositeExceptionWithEx123()); System.err.println("----------------------------- print composite stacktrace"); cex.printStackTrace(); assertEquals(3, cex.getExceptions().size()); assertNoCircularReferences(cex); assertNotNull(getRootCause(cex)); System.err.println("----------------------------- print cause stacktrace"); cex.getCause().printStackTrace(); }
@Test public void onErrorResumeNextFunctionReturnsNull() { try { error.onErrorResumeNext(new Function<Throwable, Single<Integer>>() { @Override public Single<Integer> apply(Throwable e) { return null; } }).blockingGet(); } catch (CompositeException ex) { assertTrue(ex.toString(), ex.getExceptions().get(1) instanceof NullPointerException); } }
@SuppressWarnings("unchecked") @Test public void arrayDelayError() { Publisher<Integer>[] sources = new Publisher[] { Flowable.just(1), null, Flowable.range(2, 3), Flowable.error(new TestException()), Flowable.empty() }; TestSubscriber<Integer> ts = Flowable.concatArrayDelayError(sources).test(); ts.assertFailure(CompositeException.class, 1, 2, 3, 4); CompositeException composite = (CompositeException)ts.errors().get(0); List<Throwable> list = composite.getExceptions(); assertTrue(list.get(0).toString(), list.get(0) instanceof NullPointerException); assertTrue(list.get(1).toString(), list.get(1) instanceof TestException); }
@SuppressWarnings("unchecked") @Test public void concatDelayErrorIterableError() { TestSubscriber<Integer> ts = TestSubscriber.create(); Flowable.concatDelayError( Arrays.asList(withError(Flowable.just(1)), withError(Flowable.just(2)))) .subscribe(ts); ts.assertValues(1, 2); ts.assertError(CompositeException.class); ts.assertNotComplete(); assertEquals(2, ((CompositeException)ts.errors().get(0)).getExceptions().size()); }