@Test
public void testConcatUnsubscribe() {

    final CountDownLatch callOnce = new CountDownLatch(1);
    final CountDownLatch okToContinue = new CountDownLatch(1);
    final TestObservable<String> w1 = new TestObservable<String>("one", "two", "three");
    final TestObservable<String> w2 = new TestObservable<String>(callOnce, okToContinue, "four", "five", "six");
    @SuppressWarnings("unchecked")
    final Observer<String> observer = mock(Observer.class);
    @SuppressWarnings("unchecked")
    final Observable<String> concat = Observable.create(concat(Observable.create(w1), Observable.create(w2)));
    try {
        // Subscribe
        Subscription s1 = concat.subscribe(observer);
        //Block main thread to allow observable "w1" to complete and observable "w2" to call onNext once.
        callOnce.await();
        // Unsubcribe
        s1.unsubscribe();
        //Unblock the observable to continue.
        okToContinue.countDown();
        w1.t.join();
        w2.t.join();
    } catch (Throwable e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    InOrder inOrder = inOrder(observer);
    inOrder.verify(observer, times(1)).onNext("one");
    inOrder.verify(observer, times(1)).onNext("two");
    inOrder.verify(observer, times(1)).onNext("three");
    inOrder.verify(observer, times(1)).onNext("four");
    inOrder.verify(observer, never()).onNext("five");
    inOrder.verify(observer, never()).onNext("six");
    inOrder.verify(observer, never()).onCompleted();
}