示例#1
0
  @Test
  public void testViewObservable() {
    RxPresenter<Integer> presenter = new RxPresenter<>();
    presenter.onCreate(null);

    TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();
    presenter.view().subscribe(testSubscriber);
    testSubscriber.assertValueCount(0);

    List<Integer> values = new ArrayList<>();

    presenter.onTakeView(1);
    values.add(1);
    assertValues(values, testSubscriber);

    presenter.onDropView();
    values.add(null);
    assertValues(values, testSubscriber);

    presenter.onTakeView(2);
    values.add(2);
    assertValues(values, testSubscriber);

    presenter.onDestroy();
    assertValues(values, testSubscriber);
    testSubscriber.assertCompleted();
  }
 @Test
 public void shouldEmmitGroundOverlay() throws Exception {
   TestSubscriber<GroundOverlay> testSubscriber = new TestSubscriber<>();
   new GroundOverlayClickFunc().call(googleMap).subscribe(testSubscriber);
   verify(googleMap).setOnGroundOverlayClickListener(argumentCaptor.capture());
   argumentCaptor.getValue().onGroundOverlayClick(null);
   testSubscriber.assertNoErrors();
   testSubscriber.assertValueCount(1);
   testSubscriber.assertValue(null);
 }
示例#3
0
  @Test
  public void testAsSetAction() throws Exception {
    final Value<String> value = Value.create("1");
    assertEquals(value.get(), "1");
    TestSubscriber<String> testSubscriber = new TestSubscriber<>();
    Subscription subscribe = value.asObservable().subscribe(testSubscriber);

    value.asSetAction().call("2");

    testSubscriber.assertValueCount(2);
    testSubscriber.assertValues("1", "2");
  }
示例#4
0
  @Test
  public void testCreatePublish() throws Exception {

    final Value<String> value = Value.createPublish("1");
    assertEquals(value.get(), "1");
    TestSubscriber<String> testSubscriber = new TestSubscriber<>();
    Subscription subscribe = value.asObservable().subscribe(testSubscriber);

    testSubscriber.assertValueCount(0);

    value.set("2");

    testSubscriber.assertValueCount(1);
    testSubscriber.assertValues("2");

    subscribe.unsubscribe();

    testSubscriber = new TestSubscriber<>();
    value.asObservable().subscribe(testSubscriber);

    testSubscriber.assertValueCount(0);
  }
示例#5
0
  @Test
  public void rxBindingSingleValue() {
    when(cursor.getCount()).thenReturn(1);
    when(cursor.moveToNext()).thenReturn(true, false);
    when(cursor.getString(0)).thenReturn("Yo");

    TestSubscriber<String> testSubscriber = new TestSubscriber<>();

    Fetcher fetcher = Fetcher.of(cursor);
    fetcher.subscribe(Converter.STRING, testSubscriber);

    testSubscriber.requestMore(1);
    testSubscriber.assertValueCount(1);
    testSubscriber.assertValue("Yo");
  }
示例#6
0
  @Test
  public void flatMapTwoNestedSync() {
    for (final int n : new int[] {1, 1000, 1000000}) {
      TestSubscriber<Integer> ts = new TestSubscriber<Integer>();

      Observable.just(1, 2)
          .flatMap(
              new Func1<Integer, Observable<Integer>>() {
                @Override
                public Observable<Integer> call(Integer t) {
                  return Observable.range(1, n);
                }
              })
          .subscribe(ts);

      System.out.println("flatMapTwoNestedSync >> @ " + n);
      ts.assertNoErrors();
      ts.assertCompleted();
      ts.assertValueCount(n * 2);
    }
  }
示例#7
0
  @Test
  public void flatMapIntPassthruAsync() {
    for (int i = 0; i < 1000; i++) {
      TestSubscriber<Integer> ts = new TestSubscriber<Integer>();

      Observable.range(1, 1000)
          .flatMap(
              new Func1<Integer, Observable<Integer>>() {
                @Override
                public Observable<Integer> call(Integer t) {
                  return Observable.just(1).subscribeOn(Schedulers.computation());
                }
              })
          .subscribe(ts);

      ts.awaitTerminalEvent(5, TimeUnit.SECONDS);
      ts.assertNoErrors();
      ts.assertCompleted();
      ts.assertValueCount(1000);
    }
  }