I'm trying to write unit tests for a class unit okhttp3 and I'm stuck at mocking the okhttp3.Response class.
It is declared final and most mocking frameworks can't mock final classes. I would rather NOT use Powermock just for this one.
Looking at the code I can see that it would be possible to create a real instance of the Response class and use it in the test but it would be much more code and much less readable compared to just mocking one method (in my case).
Any specific reasons behind the "final" modifier of the okhttp3.Response class or any plans to remove it in later releases?
Response
is a value class and thus should never be mocked. You can create instances with Response.Builder
with whatever data you want the Response
to have.
There are no plans to remove the final
modifier.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With