I am writing unit tests (using JUnit and Mockito) for a singleton Java class. I cannot change the class implementation itself.
With PowerMockito, it was like this (and works):
@Mock
private TheSingleton theSingleton;
@Before
public final void setUp()
throws Exception
{
MockitoAnnotations.initMocks( this );
PowerMockito.mockStatic( TheSingleton.class );
when( TheSingleton.getInstance() ).thenReturn( theSingleton );
...
}
The ask is to rewrite the test without using PowerMock or PowerMockito or any other static mocking API. Since I cannot change the singleton class to instead use dependency injection, I am not sure what would be a good way of doing this.
Any help will be greatly appreciated.