Closed achals closed 3 years ago
This might help? https://github.com/powermock/powermock/wiki/MockFinal
Yes, that would have been great if we didn't have a way of changing the underlying library - do you think Powermock works better than just removing the finals, generally?
Yeah. We used to use PowerMock and Mockito together. Each of them cover some cases. You should be able to test almost all cases with one of them.
PowerMock for the win. Do not forget to use the proper runner so that the classes can be mocked.
I'm trying to integrate tchannel-java into an application, injecting the
SubChannel
into a Class to interact with another tchannel service.But, there's effectively no way for me to test this class - I can't mock final classes, or make my own in-memory implementation of the
SubChannel
class.I tried creating a non-final Wrapper for
SubChannel
, only exposing the relevant methods I intend to use, and a delegating to the actualSubChannel
, but that's a rabbit hole sinceTFuture
,ThriftResponse
are all final.I propose making all these class non-final - it would be a backwards compatible change, allow end users to integrate with the libraries with tests for their logic, and let users customize the implementations as needed.