use of org.robolectric.internal.ShadowProvider in project robolectric by robolectric.
the class RobolectricTest method reset_shouldResetShadows_beforeClearingPackageManager.
@Test
public void reset_shouldResetShadows_beforeClearingPackageManager() {
Iterable<ShadowProvider> oldProviders = ReflectionHelpers.getStaticField(Robolectric.class, "providers");
;
ShadowProvider mockProvider = new MockProvider();
List<ShadowProvider> mockProviders = Collections.singletonList(mockProvider);
ReflectionHelpers.setStaticField(Robolectric.class, "providers", mockProviders);
RobolectricPackageManager mockManager = mock(RobolectricPackageManager.class);
doAnswer(new Answer<Void>() {
public Void answer(InvocationOnMock invocation) {
order.add("packageManager");
return null;
}
}).when(mockManager).reset();
RuntimeEnvironment.setRobolectricPackageManager(mockManager);
try {
Robolectric.reset();
} finally {
// Make sure we clean up after ourselves
ReflectionHelpers.setStaticField(Robolectric.class, "providers", oldProviders);
}
assertThat(order).as("reset order").containsExactly("shadowProvider", "packageManager");
assertThat(RuntimeEnvironment.application).as("app after reset").isNull();
assertThat(RuntimeEnvironment.getRobolectricPackageManager()).as("packageManager after reset").isNull();
assertThat(RuntimeEnvironment.getActivityThread()).as("activityThread after reset").isNull();
}
use of org.robolectric.internal.ShadowProvider in project robolectric by robolectric.
the class Robolectric method reset.
public static void reset() {
if (providers == null) {
providers = ServiceLoader.load(ShadowProvider.class);
}
for (ShadowProvider provider : providers) {
provider.reset();
}
RuntimeEnvironment.application = null;
RuntimeEnvironment.setRobolectricPackageManager(null);
RuntimeEnvironment.setActivityThread(null);
}
Aggregations