Exemplo n.º 1
0
  @Test
  public void testContainsWithEmptyObservable() {
    Observable<Boolean> observable = Observable.<String>empty().contains("a");

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

    observable.subscribe(observer);

    verify(observer, times(1)).onNext(false);
    verify(observer, never()).onNext(true);
    verify(observer, never()).onError(org.mockito.Matchers.any(Throwable.class));
    verify(observer, times(1)).onComplete();
  }
Exemplo n.º 2
0
  @Test
  @Ignore("null values are not allowed")
  public void testContainsWithNull() {
    Observable<Boolean> observable = Observable.just("a", "b", null).contains(null);

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

    observable.subscribe(observer);

    verify(observer, times(1)).onNext(true);
    verify(observer, never()).onNext(false);
    verify(observer, never()).onError(org.mockito.Matchers.any(Throwable.class));
    verify(observer, times(1)).onComplete();
  }
Exemplo n.º 3
0
  @Test
  public void testContainsWithInexistence() {
    Observable<Boolean> observable =
        Observable.just("a", "b").contains("c"); // FIXME null values are not allowed, removed

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

    observable.subscribe(observer);

    verify(observer, times(1)).onNext(false);
    verify(observer, never()).onNext(true);
    verify(observer, never()).onError(org.mockito.Matchers.any(Throwable.class));
    verify(observer, times(1)).onComplete();
  }
Exemplo n.º 4
0
  @Test
  public void testContains() {
    Observable<Boolean> observable =
        Observable.just("a", "b", "c").contains("b"); // FIXME nulls not allowed, changed to "c"

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

    observable.subscribe(observer);

    verify(observer, times(1)).onNext(true);
    verify(observer, never()).onNext(false);
    verify(observer, never()).onError(org.mockito.Matchers.any(Throwable.class));
    verify(observer, times(1)).onComplete();
  }
Exemplo n.º 5
0
  @Test
  public void testOfType() {
    Observable<String> observable = Observable.just(1, "abc", false, 2L).ofType(String.class);

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

    observable.subscribe(observer);

    verify(observer, never()).onNext(1);
    verify(observer, times(1)).onNext("abc");
    verify(observer, never()).onNext(false);
    verify(observer, never()).onNext(2L);
    verify(observer, never()).onError(org.mockito.Matchers.any(Throwable.class));
    verify(observer, times(1)).onComplete();
  }
Exemplo n.º 6
0
  @Test
  public void testOfTypeWithPolymorphism() {
    ArrayList<Integer> l1 = new ArrayList<>();
    l1.add(1);
    LinkedList<Integer> l2 = new LinkedList<>();
    l2.add(2);

    @SuppressWarnings("rawtypes")
    Observable<List> observable = Observable.<Object>just(l1, l2, "123").ofType(List.class);

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

    observable.subscribe(observer);

    verify(observer, times(1)).onNext(l1);
    verify(observer, times(1)).onNext(l2);
    verify(observer, never()).onNext("123");
    verify(observer, never()).onError(org.mockito.Matchers.any(Throwable.class));
    verify(observer, times(1)).onComplete();
  }