use of org.robolectric.annotation.Resetter in project robolectric by robolectric.
the class ShadowContextImpl method reset.
@Resetter
public static void reset() {
String prefsCacheFieldName = RuntimeEnvironment.getApiLevel() >= N ? "sSharedPrefsCache" : "sSharedPrefs";
Object prefsDefaultValue = RuntimeEnvironment.getApiLevel() >= KITKAT ? null : new HashMap<>();
Class<?> contextImplClass = ReflectionHelpers.loadClass(ShadowContextImpl.class.getClassLoader(), "android.app.ContextImpl");
ReflectionHelpers.setStaticField(contextImplClass, prefsCacheFieldName, prefsDefaultValue);
if (RuntimeEnvironment.getApiLevel() <= VERSION_CODES.LOLLIPOP_MR1) {
HashMap<String, Object> fetchers = ReflectionHelpers.getStaticField(contextImplClass, "SYSTEM_SERVICE_MAP");
Class staticServiceFetcherClass = ReflectionHelpers.loadClass(ShadowContextImpl.class.getClassLoader(), "android.app.ContextImpl$StaticServiceFetcher");
for (Object o : fetchers.values()) {
if (staticServiceFetcherClass.isInstance(o)) {
ReflectionHelpers.setField(staticServiceFetcherClass, o, "mCachedInstance", null);
}
}
if (RuntimeEnvironment.getApiLevel() >= KITKAT) {
Object windowServiceFetcher = fetchers.get(Context.WINDOW_SERVICE);
ReflectionHelpers.setField(windowServiceFetcher.getClass(), windowServiceFetcher, "mDefaultDisplay", null);
}
}
}
use of org.robolectric.annotation.Resetter in project robolectric by robolectric.
the class ShadowWindowManagerImpl method reset.
@Resetter
public static void reset() {
defaultDisplayJB = null;
views.clear();
if (getApiLevel() <= VERSION_CODES.JELLY_BEAN) {
ReflectionHelpers.setStaticField(WindowManagerImpl.class, "sWindowManager", ReflectionHelpers.newInstance(WindowManagerImpl.class));
HashMap windowManagers = ReflectionHelpers.getStaticField(WindowManagerImpl.class, "sCompatWindowManagers");
windowManagers.clear();
}
}
Aggregations