Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the okhttp3.Response class final

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?

like image 454
vap78 Avatar asked Dec 29 '16 09:12

vap78


1 Answers

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.

like image 112
Jake Wharton Avatar answered Nov 12 '22 22:11

Jake Wharton