Search in sources :

Example 11 with LooperMode

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);
}
Also used : Scheduler(org.robolectric.util.Scheduler) Test(org.junit.Test) LooperMode(org.robolectric.annotation.LooperMode)

Example 12 with LooperMode

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();
    }
}
Also used : Looper(android.os.Looper) LooperMode(org.robolectric.annotation.LooperMode) ArrayList(java.util.ArrayList) Resetter(org.robolectric.annotation.Resetter)

Example 13 with LooperMode

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);
}
Also used : TestRunnable(org.robolectric.util.TestRunnable) Test(org.junit.Test) LooperMode(org.robolectric.annotation.LooperMode)

Example 14 with LooperMode

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);
}
Also used : ShadowLooper(org.robolectric.shadows.ShadowLooper) LooperMode(org.robolectric.annotation.LooperMode) Test(org.junit.Test) LooperMode(org.robolectric.annotation.LooperMode)

Example 15 with LooperMode

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);
}
Also used : ResourcesMode(org.robolectric.internal.ResourcesMode) InstrumentationConfiguration(org.robolectric.internal.bytecode.InstrumentationConfiguration) AssumptionViolatedException(org.junit.AssumptionViolatedException) Mode(org.robolectric.annotation.LooperMode.Mode) SQLiteMode(org.robolectric.annotation.SQLiteMode) ResourcesMode(org.robolectric.internal.ResourcesMode) LooperMode(org.robolectric.annotation.LooperMode) Sdk(org.robolectric.pluginapi.Sdk) LooperMode(org.robolectric.annotation.LooperMode) Mode(org.robolectric.annotation.LooperMode.Mode) Nonnull(javax.annotation.Nonnull)

Aggregations

LooperMode (org.robolectric.annotation.LooperMode)18 Test (org.junit.Test)15 Scheduler (org.robolectric.util.Scheduler)5 BroadcastReceiver (android.content.BroadcastReceiver)2 Intent (android.content.Intent)2 Handler (android.os.Handler)2 HandlerThread (android.os.HandlerThread)2 Looper (android.os.Looper)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Resetter (org.robolectric.annotation.Resetter)2 ShadowLooper (org.robolectric.shadows.ShadowLooper)2 TestRunnable (org.robolectric.util.TestRunnable)2 Dialog (android.app.Dialog)1 Context (android.content.Context)1 ArrayList (java.util.ArrayList)1 Nonnull (javax.annotation.Nonnull)1 AssumptionViolatedException (org.junit.AssumptionViolatedException)1 InterstitialView (org.prebid.mobile.rendering.bidding.display.InterstitialView)1 VideoCreative (org.prebid.mobile.rendering.video.VideoCreative)1