I have class which I need test:
class MyClass {
private final static MyOtherClass myOtherClass = OtherClassFactory.get();
public void doSomething() {}
}
How to mock myOtherClass in unit test?
You can use the Deencapsulation.setField method from the JMockit mocking library; it supports setting of final fields as well (as long as the field is not initialized to a compile-time constant, which is not the case here).
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