Mockito: Mock private field initialization

Mockito comes with a helper class to save you some reflection boiler plate code: import org.mockito.internal.util.reflection.Whitebox; //… @Mock private Person mockedPerson; private Test underTest; // … @Test public void testMethod() { Whitebox.setInternalState(underTest, “person”, mockedPerson); // … } Update: Unfortunately the mockito team decided to remove the class in Mockito 2. So you are back to … Read more