예제 #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
 @Test
 public void testReduceWithInitialValue() {
   Observable<Integer> observable = Observable.just(1, 2, 3, 4);
   observable.reduce(50, (t1, t2) -> t1 + t2).subscribe(w);
   // we should be called only once
   verify(w, times(1)).onNext(anyInt());
   verify(w).onNext(60);
 }
예제 #3
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");
  }