@Test public void testCompositeErrorDelayed2() { final Flowable<String> o1 = Flowable.unsafeCreate(new TestErrorFlowable("four", null, "six")); // we expect to lose "six" from the source (and it should never be sent by the source since onError was called final Flowable<String> o2 = Flowable.unsafeCreate(new TestErrorFlowable("one", "two", null)); Flowable<String> m = Flowable.mergeDelayError(o1, o2); CaptureObserver w = new CaptureObserver(); m.subscribe(w); assertNotNull(w.e); int size = ((CompositeException)w.e).size(); if (size != 2) { w.e.printStackTrace(); } assertEquals(2, size); // if (w.e instanceof CompositeException) { // assertEquals(2, ((CompositeException) w.e).getExceptions().size()); // w.e.printStackTrace(); // } else { // fail("Expecting CompositeException"); // } }
@Test public void testMultipleErrors() { TestSubscriber<Integer> ts = new TestSubscriber<Integer>(); ts.onSubscribe(EmptySubscription.INSTANCE); ts.onError(new TestException()); ts.onError(new TestException()); try { ts.assertNoErrors(); } catch (AssertionError ex) { Throwable e = ex.getCause(); if (!(e instanceof CompositeException)) { fail("Multiple Error present but the reported error doesn't have a composite cause!"); } CompositeException ce = (CompositeException)e; if (ce.size() != 2) { ce.printStackTrace(); } assertEquals(2, ce.size()); // expected return; } fail("Multiple Error present but no assertion error!"); }
@Test public void testCompositeErrorDelayed2() { final Observable<String> o1 = Observable.unsafeCreate(new TestErrorObservable("four", null, "six")); // we expect to lose "six" from the source (and it should never be sent by the source since onError was called final Observable<String> o2 = Observable.unsafeCreate(new TestErrorObservable("one", "two", null)); Observable<String> m = Observable.mergeDelayError(o1, o2); CaptureObserver w = new CaptureObserver(); m.subscribe(w); assertNotNull(w.e); assertEquals(2, ((CompositeException)w.e).size()); // if (w.e instanceof CompositeException) { // assertEquals(2, ((CompositeException) w.e).getExceptions().size()); // w.e.printStackTrace(); // } else { // fail("Expecting CompositeException"); // } }
@Test public void testNoTerminalEventBut2Errors() { TestSubscriber<Integer> ts = new TestSubscriber<Integer>(); ts.onSubscribe(EmptySubscription.INSTANCE); ts.onError(new TestException()); ts.onError(new TestException()); try { ts.assertNotTerminated(); fail("Failed to report there were terminal event(s)!"); } catch (AssertionError ex) { // expected Throwable e = ex.getCause(); if (!(e instanceof CompositeException)) { fail("Multiple Error present but the reported error doesn't have a composite cause!"); } CompositeException ce = (CompositeException)e; assertEquals(2, ce.size()); } }
@Test public void testMultipleErrors2() { TestSubscriber<Integer> ts = new TestSubscriber<Integer>(); ts.onSubscribe(EmptySubscription.INSTANCE); ts.onError(new TestException()); ts.onError(new TestException()); try { ts.assertError(TestException.class); } catch (AssertionError ex) { Throwable e = ex.getCause(); if (!(e instanceof CompositeException)) { fail("Multiple Error present but the reported error doesn't have a composite cause!"); } CompositeException ce = (CompositeException)e; assertEquals(2, ce.size()); // expected return; } fail("Multiple Error present but no assertion error!"); }
@Test public void testMultipleErrors3() { TestSubscriber<Integer> ts = new TestSubscriber<Integer>(); ts.onSubscribe(EmptySubscription.INSTANCE); ts.onError(new TestException()); ts.onError(new TestException()); try { ts.assertError(new TestException()); } catch (AssertionError ex) { Throwable e = ex.getCause(); if (!(e instanceof CompositeException)) { fail("Multiple Error present but the reported error doesn't have a composite cause!"); } CompositeException ce = (CompositeException)e; assertEquals(2, ce.size()); // expected return; } fail("Multiple Error present but no assertion error!"); }
@Test public void testMultipleErrors4() { TestSubscriber<Integer> ts = new TestSubscriber<Integer>(); ts.onSubscribe(EmptySubscription.INSTANCE); ts.onError(new TestException()); ts.onError(new TestException()); try { ts.assertError(Functions.<Throwable>alwaysTrue()); } catch (AssertionError ex) { Throwable e = ex.getCause(); if (!(e instanceof CompositeException)) { fail("Multiple Error present but the reported error doesn't have a composite cause!"); } CompositeException ce = (CompositeException)e; assertEquals(2, ce.size()); // expected return; } fail("Multiple Error present but no assertion error!"); }