@Test
public void onTerminateCalledWhenCanceled() {

    final AtomicBoolean didRunOnTerminate = new AtomicBoolean();
    UnicastProcessor<Integer> us = UnicastProcessor.create(Observable.bufferSize(), new Runnable() {
        @Override public void run() {
            didRunOnTerminate.set(true);
        }
    });
    final Disposable subscribe = us.subscribe();
    assertEquals(false, didRunOnTerminate.get());
    subscribe.dispose();
    assertEquals(true, didRunOnTerminate.get());
}