Created
October 3, 2016 11:45
-
-
Save rwoloszyn/adc289dd596283c2d635658af59ac3b2 to your computer and use it in GitHub Desktop.
Reset singleton field during JUnit tests, roboelectric junit tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@After | |
public void teaddown() { | |
setting.clear(); | |
resetSingleton(ErgoSettings.class, "sInstance"); | |
} | |
public static void resetSingleton(Class clazz, String fieldName) { | |
Field instance; | |
try { | |
instance = clazz.getDeclaredField(fieldName); | |
instance.setAccessible(true); | |
instance.set(null, null); | |
} catch (Exception e) { | |
throw new RuntimeException(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment