@Test
public void testUnsubscribeAfterTake() {

    Subscription s = mock(Subscription.class);
    TestObservable w = new TestObservable(s, "one", "two", "three");
    @SuppressWarnings("unchecked")
    Observer<String> observer = mock(Observer.class);
    Observable<String> take = Observable.create(takeWhileWithIndex(Observable.create(w), new Func2<String, Integer, Boolean>() {
        @Override
        public Boolean call(String s, Integer index) {
            return index < 1;
        }
    }));
    take.subscribe(observer);
    // wait for the Observable to complete
    try {
        w.t.join();
    } catch (Throwable e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    System.out.println("TestObservable thread finished");
    verify(observer, times(1)).onNext("one");
    verify(observer, never()).onNext("two");
    verify(observer, never()).onNext("three");
    verify(s, times(1)).unsubscribe();
}