assertHandlesException
fun <T : Any> assertHandlesException(throwable: Throwable, mockSetup: () -> Unit, verificationBlock: () -> T)
A test utility to verify that a block of code correctly handles an exception.
This function will:
Set up a mock to throw a given throwable.
Execute the verificationBlock which is expected to contain a try-catch block.
Assert that the verificationBlock does not throw an unhandled exception.
Parameters
T
The return type of the function being tested.
throwable
The exception to be thrown by the mock.
mockSetup
A lambda that defines the mock behavior that will throw the throwable.
verificationBlock
The main block of code to be executed, which should handle the exception.