@Test
public void testUsingWithSubscribingTwice() {

    // When subscribe is called, a new resource should be created.
    Func0<Resource> resourceFactory = new Func0<Resource>() {
        @Override
        public Resource call() {
            return new Resource() {
                boolean first = true;
                @Override
                public String getTextFromWeb() {
                    if (first) {
                        first = false;
                        return "Hello world!";
                    }
                    return "Nothing";
                }
                @Override
                public void unsubscribe() {
                }
                @Override
                public boolean isUnsubscribed() {
                    return false;
                }
            };
        }
    };
    Func1<Resource, Observable<String>> observableFactory = new Func1<Resource, Observable<String>>() {
        @Override
        public Observable<String> call(Resource resource) {
            return Observable.from(resource.getTextFromWeb().split(" "));
        }
    };
    @SuppressWarnings("unchecked")
    Observer<String> observer = (Observer<String>) mock(Observer.class);
    Observable<String> observable = Observable.create(using(
            resourceFactory, observableFactory));
    observable.subscribe(observer);
    observable.subscribe(observer);
    InOrder inOrder = inOrder(observer);
    inOrder.verify(observer, times(1)).onNext("Hello");
    inOrder.verify(observer, times(1)).onNext("world!");
    inOrder.verify(observer, times(1)).onCompleted();
    inOrder.verify(observer, times(1)).onNext("Hello");
    inOrder.verify(observer, times(1)).onNext("world!");
    inOrder.verify(observer, times(1)).onCompleted();
    inOrder.verifyNoMoreInteractions();
}