Reputation: 140
def expectError() {
StepVerifier.create(readDB())
.expectError(RuntimeException.class)
.verify();
}
private Mono<String> readDB() {
// try {
return Mono.just(externalService.get())
.onErrorResume(throwable -> Mono.error(throwable));
// } catch (Exception e) {
// return Mono.error(e);
// }
}
unable to make it work if externalService.get throws Exception instead of return Mono.error. Is is always recommended to transform to Mono/Flow using try catch or is there any better way to verify such thrown exception?
Upvotes: 3
Views: 14207
Reputation: 28301
Most of the time, if the user-provided code that throws an exception is provided as a lambda, exceptions can be translated to onError
. But here you're directly throwing in the main thread, so that cannot happen
Upvotes: 2