okhttp icon indicating copy to clipboard operation
okhttp copied to clipboard

Remove "final" modifier from MockResponse

Open SFerrazLeite opened this issue 10 years ago • 1 comments

  • [x] Feature Request. Start by telling us what problem you’re trying to solve. Often a solution already exists! Don’t send pull requests to implement new features without first getting our support. Sometimes we leave features out on purpose to keep the project small.

As I am developing my software test suite, I am very happy about the MockWebServer, and I am using it extensively to write integration tests. I implemented my own dispatcher and it is programmable at runtime. So, I can set expectations and verify the calls - as you would do with a common mocking framework. To make my tests crisp, I wrote the classes such that I can use a builder pattern - as you can do with MockResponse. Optimally, I would love my Expection class to extend the MockResponse so that I can write stuff like

dispatcher.expect(params...).addHeader(...).andReturn(body...).times(3)

where you can see that I would like to mix the build instructions for the actual MockResponse and the Expectation. Since I don't see an obvious reason why the MockResponse class is final, I would propose to remove the "final" modifier to allow for better reusability of the code.

SFerrazLeite avatar Jun 28 '16 07:06 SFerrazLeite

Could you do this by delegation or composition? Making classes extendable is a big burden on maintainability so I’d prefer to not.

swankjesse avatar Jun 28 '16 11:06 swankjesse