Пример #1
0
  @Test
  public void fromArityArgs1() {
    Observable<String> items = Observable.just("one");

    assertEquals((Long) 1L, items.count().toBlocking().single());
    assertEquals("one", items.takeLast(1).toBlocking().single());
  }
Пример #2
0
  @Test
  public void testCountError() {
    Observable<String> o = Observable.error(() -> new RuntimeException());

    o.count().subscribe(w);
    verify(w, never()).onNext(anyInt());
    verify(w, never()).onComplete();
    verify(w, times(1)).onError(any(RuntimeException.class));
  }
Пример #3
0
 @Test
 public void testCountZeroItems() {
   Observable<String> observable = Observable.empty();
   observable.count().subscribe(w);
   // we should be called only once
   verify(w, times(1)).onNext(anyLong());
   verify(w).onNext(0L);
   verify(w, never()).onError(any(Throwable.class));
   verify(w, times(1)).onComplete();
 }
Пример #4
0
  @Test
  public void testCountAFewItems() {
    Observable<String> observable = Observable.just("a", "b", "c", "d");

    observable.count().subscribe(w);

    // we should be called only once
    verify(w, times(1)).onNext(anyLong());
    verify(w).onNext(4L);
    verify(w, never()).onError(any(Throwable.class));
    verify(w, times(1)).onComplete();
  }