I want to mock my java class in such a ways so that each and every new instance of it should return the mocked response.
There are two mocking libraries which support this: PowerMock (as shown in Matthias' answer), and JMockit.
In the second case, the test only needs to declare a mock field or mock parameter using the @Mocked
annotation.
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