rxjava: thenReturn Single.error vs thenThrow Exception

31 Views Asked by At

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

0

There are 0 best solutions below