Пример #1
0
  @Test
  public void fromIterable() {
    ArrayList<String> items = new ArrayList<>();
    items.add("one");
    items.add("two");
    items.add("three");

    assertEquals((Long) 3L, Observable.fromIterable(items).count().toBlocking().single());
    assertEquals("two", Observable.fromIterable(items).skip(1).take(1).toBlocking().single());
    assertEquals("three", Observable.fromIterable(items).takeLast(1).toBlocking().single());
  }
Пример #2
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();
  }