use of org.robolectric.annotation.LooperMode in project robolectric by robolectric.
the class ShadowApplicationTest method getBackgroundThreadScheduler_shouldDifferFromRuntimeEnvironment_withAdvancedScheduling.
@Test
@LooperMode(LEGACY)
public void getBackgroundThreadScheduler_shouldDifferFromRuntimeEnvironment_withAdvancedScheduling() {
Scheduler s = new Scheduler();
RuntimeEnvironment.setMasterScheduler(s);
assertThat(Shadows.shadowOf(context).getBackgroundThreadScheduler()).isNotSameInstanceAs(s);
}
use of org.robolectric.annotation.LooperMode in project robolectric by robolectric.
the class ShadowPausedLooper method resetLoopers.
@Resetter
public static synchronized void resetLoopers() {
// do not use looperMode() here, because its cached value might already have been reset
if (ConfigurationRegistry.get(LooperMode.Mode.class) != LooperMode.Mode.PAUSED) {
// ignore if not realistic looper
return;
}
Collection<Looper> loopersCopy = new ArrayList(loopingLoopers);
for (Looper looper : loopersCopy) {
ShadowPausedMessageQueue shadowQueue = Shadow.extract(looper.getQueue());
shadowQueue.reset();
}
}
use of org.robolectric.annotation.LooperMode in project robolectric by robolectric.
the class ShadowActivityTest method shouldExecutePostedUiTasksInRealisticLooper.
/**
* The legacy behavior spec-ed in {@link #shouldQueueUiTasksWhenUiThreadIsPaused()} is actually
* incorrect. The {@link Activity#runOnUiThread} will execute posted tasks inline.
*/
@Test
@LooperMode(Mode.PAUSED)
public void shouldExecutePostedUiTasksInRealisticLooper() throws Exception {
activity = Robolectric.setupActivity(DialogLifeCycleActivity.class);
TestRunnable runnable = new TestRunnable();
activity.runOnUiThread(runnable);
assertTrue(runnable.wasRun);
}
use of org.robolectric.annotation.LooperMode in project robolectric by robolectric.
the class LooperModeConfigurerClassTest method shouldUseLegacyShadows.
@Test
@LooperMode(Mode.LEGACY)
public void shouldUseLegacyShadows() {
assertThat(ConfigurationRegistry.get(LooperMode.Mode.class)).isSameInstanceAs(Mode.LEGACY);
ShadowLooper looper = Shadow.extract(Looper.getMainLooper());
assertThat(looper).isInstanceOf(ShadowLegacyLooper.class);
}
use of org.robolectric.annotation.LooperMode in project robolectric by robolectric.
the class RobolectricTestRunner method getSandbox.
@Override
@Nonnull
protected AndroidSandbox getSandbox(FrameworkMethod method) {
RobolectricFrameworkMethod roboMethod = (RobolectricFrameworkMethod) method;
Sdk sdk = roboMethod.getSdk();
InstrumentationConfiguration classLoaderConfig = createClassLoaderConfig(method);
ResourcesMode resourcesMode = roboMethod.getResourcesMode();
if (resourcesMode == ResourcesMode.LEGACY && sdk.getApiLevel() > Build.VERSION_CODES.P) {
throw new AssumptionViolatedException("Robolectric doesn't support legacy mode after P");
}
LooperMode.Mode looperMode = roboMethod.configuration == null ? Mode.LEGACY : roboMethod.configuration.get(LooperMode.Mode.class);
sdk.verifySupportedSdk(method.getDeclaringClass().getName());
return sandboxManager.getAndroidSandbox(classLoaderConfig, sdk, resourcesMode, looperMode);
}
Aggregations