@Test
public void testTakeWhileProtectsPredicateCall() {

    TestObservable source = new TestObservable(mock(Subscription.class), "one");
    final RuntimeException testException = new RuntimeException("test exception");
    @SuppressWarnings("unchecked")
    Observer<String> observer = mock(Observer.class);
    Observable<String> take = Observable.create(takeWhile(Observable.create(source), new Func1<String, Boolean>() {
        @Override
        public Boolean call(String s) {
            throw testException;
        }
    }));
    take.subscribe(observer);
    // wait for the Observable to complete
    try {
        source.t.join();
    } catch (Throwable e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    verify(observer, never()).onNext(any(String.class));
    verify(observer, times(1)).onError(testException);
}