UseCase { @SuppressWarnings("unchecked") public void execute(Subscriber UseCaseSubscriber) { this.subscription = this.buildUseCaseObservable() .subscribeOn(Schedulers.from(threadExecutor)) .observeOn(postExecutionThread.getScheduler()) .subscribe(UseCaseSubscriber); } protected  UseCase(ThreadExecutor threadExecutor,PostExecutionThread postExecutionThread); @SuppressWarnings("unchecked") void execute(Subscriber UseCaseSubscriber); @SuppressWarnings("unchecked") Observable execute(); void unsubscribe();  }
@Test public void testSubscriptionWhenExecutingUseCase() { TestSubscriber<Integer> testSubscriber = new TestSubscriber<>(); useCase.execute(testSubscriber); Mockito.when(!testSubscriber.isUnsubscribed()) .thenThrow(new NullPointerException("scheduler must be not null")); }