A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://stackoverflow.com/questions/76838452/rxjava-thenreturn-single-error-vs-thenthrow-exception below:

java - rxjava: thenReturn Single.error vs thenThrow Exception

I am writing an unit test for methodOne and am trying to simulate an exception scenario.

 Single<String> methodOne() {
     methodTwo();
     return Single.just("Hello");
}

Single<String> methodTwo() {
//some network calls
return Single.just("World");
}

I see that there are two ways to do this
when(test.methodTwo()).thenReturn(Single.error(new BadRequestException("bad request"));

when(test.methodTwo()).thenThrow(new BadRequestException("bad request"));

What is the difference between the two?

Trying to understand the difference between the above


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4