예제 #1
0
  @Test
  public void shouldRemoveCallbacksFromHandlerWhenUnsubscribedSubscription() {
    Handler handler = spy(new Handler());
    Observable.OnSubscribe<Integer> onSubscribe = mock(Observable.OnSubscribe.class);
    Subscription subscription =
        Observable.create(onSubscribe).subscribeOn(AndroidSchedulers.from(handler)).subscribe();

    verify(onSubscribe).call(any(Subscriber.class));

    subscription.unsubscribe();

    verify(handler).removeCallbacks(any(Runnable.class));
  }
예제 #2
0
  @Test
  public void shouldScheduleDelayedActionOnHandlerThread() {
    Handler handler = mock(Handler.class);
    Action0 action = mock(Action0.class);

    Scheduler scheduler = AndroidSchedulers.from(handler);
    Worker inner = scheduler.createWorker();
    inner.schedule(action, 1, SECONDS);

    // verify that we post to the given Handler
    ArgumentCaptor<Runnable> runnable = ArgumentCaptor.forClass(Runnable.class);
    verify(handler).postDelayed(runnable.capture(), eq(1000L));

    // verify that the given handler delegates to our action
    runnable.getValue().run();
    verify(action).call();
  }