'Test throw case in RxJava 3

I'm trying to test case when my rx chain should throw an exception but facing problem with it. When I'm trying to call assertError(error) it says that no error found. Here's example:

fun isAvailable(): Single<String> {
    return mapper.getSymbol().map { symbol ->
       if (repository.isAvailable(symbol)) {
          symbol
       } else {
          throw Exception("Symbol is not available")
       }
    }
}

In test I mock repository to return false and after do something like:

val error = Exception("Symbol is not available")
whenever(mapper.getSymbol()).thenReturn(
    Single.just(
        symbol
    )
)
whenever(repository.isAvailable(symbol)).thenReturn(false)
val test = symbolsRepository.isAvailable().test()

test.await()
    .assertError(error)

But when I run test I see Error not present (latch = 0, values = 0, errors = 1, completions = 0) Caused by: java.lang.Exception: Symbol is not available



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source