@Test public void testAssert() { Observable<Integer> oi = Observable.from(Arrays.asList(1, 2)); TestSubscriber<Integer> o = new TestSubscriber<Integer>(); oi.subscribe(o); o.assertReceivedOnNext(Arrays.asList(1, 2)); assertEquals(2, o.getOnNextEvents().size()); o.assertTerminalEvent(); }
@Test public void testAssertNotMatchValue() { Observable<Integer> oi = Observable.from(Arrays.asList(1, 2)); TestSubscriber<Integer> o = new TestSubscriber<Integer>(); oi.subscribe(o); thrown.expect(AssertionError.class); thrown.expectMessage("Value at index: 1 expected to be [3] (Integer) but was: [2] (Integer)"); o.assertReceivedOnNext(Arrays.asList(1, 3)); assertEquals(2, o.getOnNextEvents().size()); o.assertTerminalEvent(); }
@Test public void testAssertNotMatchCount() { Observable<Integer> oi = Observable.from(Arrays.asList(1, 2)); TestSubscriber<Integer> o = new TestSubscriber<Integer>(); oi.subscribe(o); thrown.expect(AssertionError.class); thrown.expectMessage("Number of items does not match. Provided: 1 Actual: 2"); o.assertReceivedOnNext(Arrays.asList(1)); assertEquals(2, o.getOnNextEvents().size()); o.assertTerminalEvent(); }
@Test public void testAssertTerminalEventNotReceived() { PublishSubject<Integer> p = PublishSubject.create(); TestSubscriber<Integer> o = new TestSubscriber<Integer>(); p.subscribe(o); p.onNext(1); p.onNext(2); thrown.expect(AssertionError.class); thrown.expectMessage("No terminal events received."); o.assertReceivedOnNext(Arrays.asList(1, 2)); assertEquals(2, o.getOnNextEvents().size()); o.assertTerminalEvent(); }