コード例 #1
0
  @Test
  public void testScanWithRequestOne() {
    Observable<Integer> o =
        Observable.just(1, 2)
            .scan(
                0,
                new BiFunction<Integer, Integer, Integer>() {

                  @Override
                  public Integer apply(Integer t1, Integer t2) {
                    return t1 + t2;
                  }
                })
            .take(1);
    TestSubscriber<Integer> subscriber = new TestSubscriber<>();
    o.subscribe(subscriber);
    subscriber.assertValue(0);
    subscriber.assertTerminated();
    subscriber.assertNoErrors();
  }
コード例 #2
0
  @Test
  public void testInitialValueEmittedWithProducer() {
    Observable<Integer> source = Observable.never();

    TestSubscriber<Integer> ts = new TestSubscriber<>();

    source
        .scan(
            0,
            new BiFunction<Integer, Integer, Integer>() {
              @Override
              public Integer apply(Integer t1, Integer t2) {
                return t1 + t2;
              }
            })
        .subscribe(ts);

    ts.assertNoErrors();
    ts.assertNotComplete();
    ts.assertValue(0);
  }