@Test
public void testUsing() {

    final Resource resource = mock(Resource.class);
    when(resource.getTextFromWeb()).thenReturn("Hello world!");
    Func0<Resource> resourceFactory = new Func0<Resource>() {
        @Override
        public Resource call() {
            return resource;
        }
    };
    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);
    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.verifyNoMoreInteractions();
    // The resouce should be closed
    verify(resource, times(1)).unsubscribe();
}