RxWrapper { public T unwrap(Observable<T> observable) throws IOException { final Holder<T> holder = new Holder<>(); final Throwable[] throwable = new Throwable[1]; observable.toBlocking().subscribe(new Action1<T>() { @Override public void call(T t) { holder.obj = t; } }, new Action1<Throwable>() { @Override public void call(Throwable t) { throwable[0] = t; } }); if(throwable[0] != null) { if(throwable[0] instanceof IOException) { throw (IOException) throwable[0]; } else { throw new RuntimeException(throwable[0]); } } else { return holder.obj; } }  T unwrap(Observable<T> observable);  }
@Test public void unwrapsObservable() throws IOException { TestEntity entity = new TestEntity(10); assertThat(wrapper.unwrap(Observable.just(entity)), equalTo(entity)); }
@Test (expected = IOException.class) public void throwsExceptionOnError() throws IOException { wrapper.unwrap(Observable.<TestEntity>error(new IOException())); }
@Test public void emptyObservableReturnsNull() throws IOException { TestEntity entity = wrapper.unwrap(Observable.<TestEntity>empty()); assertThat(entity, nullValue()); }