예제 #1
0
  /**
   * A reduce on an empty Observable and a seed should just pass the seed through.
   *
   * <p>This is confirmed at https://github.com/ReactiveX/RxJava/issues/423#issuecomment-27642456
   */
  @Test
  public void testReduceWithEmptyObservableAndSeed() {
    Observable<Integer> observable = Observable.range(1, 0);
    int value = observable.reduce(1, (t1, t2) -> t1 + t2).toBlocking().last();

    assertEquals(1, value);
  }
예제 #2
0
  /** A reduce should fail with an NoSuchElementException if done on an empty Observable. */
  @Test(expected = NoSuchElementException.class)
  public void testReduceWithEmptyObservable() {
    Observable<Integer> observable = Observable.range(1, 0);
    observable
        .reduce((t1, t2) -> t1 + t2)
        .toBlocking()
        .forEach(
            t1 -> {
              // do nothing ... we expect an exception instead
            });

    fail("Expected an exception to be thrown");
  }
예제 #3
0
  @Test
  public void testRangeWithScheduler() {
    TestScheduler scheduler = new TestScheduler();
    Observable<Integer> observable = Observable.range(3, 4).subscribeOn(scheduler);

    Subscriber<Integer> observer = TestHelper.mockSubscriber();

    observable.subscribe(observer);

    scheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS);

    InOrder inOrder = inOrder(observer);
    inOrder.verify(observer, times(1)).onNext(3);
    inOrder.verify(observer, times(1)).onNext(4);
    inOrder.verify(observer, times(1)).onNext(5);
    inOrder.verify(observer, times(1)).onNext(6);
    inOrder.verify(observer, times(1)).onComplete();
    inOrder.verifyNoMoreInteractions();
  }