Esempio n. 1
0
  @Test
  public void testIgnoreElements() {
    Observable<Integer> observable = Observable.just(1, 2, 3).ignoreElements();

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

    observable.subscribe(observer);

    verify(observer, never()).onNext(any(Integer.class));
    verify(observer, never()).onError(any(Throwable.class));
    verify(observer, times(1)).onComplete();
  }
Esempio n. 2
0
  @Test
  public void testMaterializeDematerializeChaining() {
    Observable<Integer> obs = Observable.just(1);
    Observable<Integer> chained = obs.materialize().dematerialize();

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

    chained.subscribe(observer);

    verify(observer, times(1)).onNext(1);
    verify(observer, times(1)).onComplete();
    verify(observer, times(0)).onError(any(Throwable.class));
  }
Esempio n. 3
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();
  }
Esempio n. 4
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();
  }
Esempio n. 5
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();
  }
Esempio n. 6
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();
  }
Esempio n. 7
0
  @Test
  public void testCreate() {

    Observable<String> observable = Observable.just("one", "two", "three");

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

    observable.subscribe(observer);

    verify(observer, times(1)).onNext("one");
    verify(observer, times(1)).onNext("two");
    verify(observer, times(1)).onNext("three");
    verify(observer, never()).onError(any(Throwable.class));
    verify(observer, times(1)).onComplete();
  }
Esempio n. 8
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();
  }
Esempio n. 9
0
  @Test
  public void testJustWithScheduler() {
    TestScheduler scheduler = new TestScheduler();
    Observable<Integer> observable = Observable.fromArray(1, 2).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(1);
    inOrder.verify(observer, times(1)).onNext(2);
    inOrder.verify(observer, times(1)).onComplete();
    inOrder.verifyNoMoreInteractions();
  }
Esempio n. 10
0
  @Ignore // FIXME throwing is not allowed from the create?!
  @Test
  public void testOnSubscribeFails() {
    Subscriber<String> observer = TestHelper.mockSubscriber();

    final RuntimeException re = new RuntimeException("bad impl");
    Observable<String> o =
        Observable.create(
            s -> {
              throw re;
            });

    o.subscribe(observer);
    verify(observer, times(0)).onNext(anyString());
    verify(observer, times(0)).onComplete();
    verify(observer, times(1)).onError(re);
  }
Esempio n. 11
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();
  }
Esempio n. 12
0
 @Before
 public void before() {
   w = TestHelper.mockSubscriber();
 }