gmazzo/okhttp-client-mock

Throw exception

Closed this issue · 3 comments

Hi there,

I would like to throw an exception when httpClient.newCall(request).execute() runs as part of my unit tests. How can I do this with your mock?

Cheers,
Olga

You can archive that with the RuleAnswer pattern:

    rule(get) {
        respond { throw IllegalStateException("an IO error") }
    }

and in java?

In java will be:

interceptor.addRule()
        .answer(request -> throw new IllegalStateException("an IO error"))