Whitebox.setInternalState()

PowerMockito allows you to inject value to globally declared member fields, this is also a wrapper around Java Reflection API's.

Whitebox.setInternalState(classUnderTest, "mCustomClassObject", (CustomClass) null);

Note: You should not set values left and wright with setInternalState() method, this should only be used when there is some if condition that is always true and you need to test else condition. for example, a null check when that object cannot be null at that time.

Last updated