Skip to content

Instantly share code, notes, and snippets.

@mrkeuz
Created March 1, 2018 14:11
Show Gist options
  • Save mrkeuz/8b4e1e67ac959f6db398b744dd86f6e9 to your computer and use it in GitHub Desktop.
Save mrkeuz/8b4e1e67ac959f6db398b744dd86f6e9 to your computer and use it in GitHub Desktop.
Blocking/Non blocking observable
import io.reactivex.Observable;
import io.reactivex.Single;
import org.junit.Test;
public class TestObservableExceptions {
@Test(expected = Exception.class)
public void throws_exception_from_onNext_onError_blocking1() throws Exception {
Observable
.just(1)
.doOnNext(e -> {
throw new Exception();
}
)
.blockingSubscribe();
}
@Test(expected = Exception.class)
public void throws_exception_from_onNext_onError_blocking3() throws Exception {
Single
.just(1)
.map(e -> {
throw new Exception();
}
)
.blockingGet();
}
@Test(expected = Exception.class)
public void throws_exception_blocking_sub_callable() throws Exception {
Observable.fromCallable(() -> 1 / 0).blockingSubscribe();
}
@Test(expected = Exception.class)
public void throws_exception_blocking_sub() throws Exception {
Observable
.just(1)
.doOnNext(i -> {
throw new Exception();
})
.blockingSubscribe();
}
@Test()
public void throws_exception_from_onNext_onError() throws Exception {
Observable
.just(1)
.doOnNext(e -> {
throw new Exception();
}
)
.subscribe(
integer -> {
}, throwable -> {
throw new Exception();
});
}
@Test()
public void throws_exception_from_onNext_onError_blocking() throws Exception {
Observable
.just(1)
.doOnNext(e -> {
throw new Exception();
}
)
.blockingSubscribe(
integer -> {
}, throwable -> {
throw new Exception();
});
}
@Test()
public void throws_exception_from_switchMap_onError() throws Exception {
Observable
.just(1)
.switchMap(integer -> Observable.error(new Exception()))
.subscribe(
integer -> {
}, throwable -> {
throw new Exception();
});
}
@Test()
public void throws_exception_from_flatMap_onError() throws Exception {
Observable
.just(1)
.flatMap(integer -> Observable.error(new Exception()))
.subscribe(
integer -> {
}, throwable -> {
throw new Exception();
});
}
@Test()
public void throws_exception_from_groupBy_onError() throws Exception {
Observable
.just(1)
.groupBy(integer -> {
throw new Exception();
})
.subscribe(
integerIntegerGroupedObservable -> {
}, throwable -> {
throw new Exception();
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment