Ejemplo n.º 1
0
 @Test
 public void testAwaitTerminalEventWithDuration() {
   TestSubscriber<Object> ts = new TestSubscriber<Object>();
   Observable.just(1).subscribe(ts);
   ts.awaitTerminalEvent(1, TimeUnit.SECONDS);
   ts.assertTerminalEvent();
 }
Ejemplo n.º 2
0
  @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();
  }
Ejemplo n.º 3
0
  @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();
  }
Ejemplo n.º 4
0
  @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();
  }
Ejemplo n.º 5
0
  @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();
  }