HandlerThreadScheduler extends Scheduler { @Override public Subscription schedule(Action1<Inner> action) { InnerHandlerThreadScheduler inner = new InnerHandlerThreadScheduler(handler); inner.schedule(action); return inner; } HandlerThreadScheduler(Handler handler); @Override Subscription schedule(Action1<Inner> action); @Override Subscription schedule(Action1<Inner> action, long delayTime, TimeUnit unit);  }
@Test public void shouldScheduleImmediateActionOnHandlerThread() { final Handler handler = mock(Handler.class); @SuppressWarnings("unchecked") final Action1<Inner> action = mock(Action1.class); Scheduler scheduler = new HandlerThreadScheduler(handler); scheduler.schedule(action); ArgumentCaptor<Runnable> runnable = ArgumentCaptor.forClass(Runnable.class); verify(handler).postDelayed(runnable.capture(), eq(0L)); runnable.getValue().run(); verify(action).call(any(Inner.class)); }
@Test public void shouldScheduleDelayedActionOnHandlerThread() { final Handler handler = mock(Handler.class); @SuppressWarnings("unchecked") final Action1<Inner> action = mock(Action1.class); Scheduler scheduler = new HandlerThreadScheduler(handler); scheduler.schedule(action, 1L, TimeUnit.SECONDS); ArgumentCaptor<Runnable> runnable = ArgumentCaptor.forClass(Runnable.class); verify(handler).postDelayed(runnable.capture(), eq(1000L)); runnable.getValue().run(); verify(action).call(any(Inner.class)); }