Java JUnit: Reset a singleton
28 February 2018
Java singleton's are hard to unit test because the state of the singleton is altered as each test runs. But for testing sake you can reset the singleton's state use reflection. Here is an example that worked for me.
@Before public void setup() throws NoSuchFieldException, IllegalAccessException { Field instance = RemoteMessageTranslation.class.getDeclaredField("set"); instance.setAccessible(true); instance.setBoolean(null, false); }
I hope this helps
Read : Java JUnit: Reset a singleton