Search in sources :

Example 1 with ShadowApplication

use of org.robolectric.shadows.ShadowApplication in project robolectric by robolectric.

the class ParallelUniverseTest method setUpApplicationState_setsBackgroundScheduler_toBeSameAsForeground_whenAdvancedScheduling.

@Test
public void setUpApplicationState_setsBackgroundScheduler_toBeSameAsForeground_whenAdvancedScheduling() {
    RoboSettings.setUseGlobalScheduler(true);
    try {
        setUpApplicationState(getDefaultConfig());
        final ShadowApplication shadowApplication = Shadows.shadowOf(RuntimeEnvironment.application);
        assertThat(shadowApplication.getBackgroundThreadScheduler()).isSameAs(shadowApplication.getForegroundThreadScheduler()).isSameAs(RuntimeEnvironment.getMasterScheduler());
    } finally {
        RoboSettings.setUseGlobalScheduler(false);
    }
}
Also used : ShadowApplication(org.robolectric.shadows.ShadowApplication) Test(org.junit.Test)

Example 2 with ShadowApplication

use of org.robolectric.shadows.ShadowApplication in project robolectric by robolectric.

the class ParallelUniverseTest method setUpApplicationState_setsBackgroundScheduler_toBeDifferentToForeground_byDefault.

@Test
public void setUpApplicationState_setsBackgroundScheduler_toBeDifferentToForeground_byDefault() {
    setUpApplicationState(getDefaultConfig());
    final ShadowApplication shadowApplication = Shadows.shadowOf(RuntimeEnvironment.application);
    assertThat(shadowApplication.getBackgroundThreadScheduler()).isNotSameAs(shadowApplication.getForegroundThreadScheduler());
}
Also used : ShadowApplication(org.robolectric.shadows.ShadowApplication) Test(org.junit.Test)

Example 3 with ShadowApplication

use of org.robolectric.shadows.ShadowApplication in project scdl by passy.

the class TestSCDLApplication method beforeTest.

@Override
public void beforeTest(Method method) {
    // GMS tries to bind to non-existent services, causing NPEs all over the place.
    ShadowApplication shadowApplication = Robolectric.shadowOf(Robolectric.application);
    shadowApplication.declareActionUnbindable("com.google.android.gms.analytics.service.START");
}
Also used : ShadowApplication(org.robolectric.shadows.ShadowApplication)

Example 4 with ShadowApplication

use of org.robolectric.shadows.ShadowApplication in project robolectric by robolectric.

the class AppSingletonizer method getInstance.

public synchronized T getInstance(Context context) {
    Application applicationContext = (Application) context.getApplicationContext();
    ShadowApplication shadowApplication = (ShadowApplication) shadowOf(applicationContext);
    T instance = get(shadowApplication);
    if (instance == null) {
        instance = createInstance(applicationContext);
        set(shadowApplication, instance);
    }
    return instance;
}
Also used : ShadowApplication(org.robolectric.shadows.ShadowApplication) ShadowApplication(org.robolectric.shadows.ShadowApplication) Application(android.app.Application)

Example 5 with ShadowApplication

use of org.robolectric.shadows.ShadowApplication in project robolectric by robolectric.

the class DefaultPackageManagerTest method shouldAssignTheAppMetaDataFromTheManifest.

@Test
@Config(manifest = "src/test/resources/TestAndroidManifestWithAppMetaData.xml")
public void shouldAssignTheAppMetaDataFromTheManifest() throws Exception {
    ShadowApplication app = ShadowApplication.getInstance();
    String packageName = app.getAppManifest().getPackageName();
    ApplicationInfo info = packageManager.getApplicationInfo(packageName, 0);
    Bundle meta = info.metaData;
    Object metaValue = meta.get("org.robolectric.metaName1");
    assertTrue(String.class.isInstance(metaValue));
    assertEquals("metaValue1", metaValue);
    metaValue = meta.get("org.robolectric.metaName2");
    assertTrue(String.class.isInstance(metaValue));
    assertEquals("metaValue2", metaValue);
    metaValue = meta.get("org.robolectric.metaFalse");
    assertTrue(Boolean.class.isInstance(metaValue));
    assertEquals(false, metaValue);
    metaValue = meta.get("org.robolectric.metaTrue");
    assertTrue(Boolean.class.isInstance(metaValue));
    assertEquals(true, metaValue);
    metaValue = meta.get("org.robolectric.metaInt");
    assertTrue(Integer.class.isInstance(metaValue));
    assertEquals(123, metaValue);
    metaValue = meta.get("org.robolectric.metaFloat");
    assertTrue(Float.class.isInstance(metaValue));
    assertEquals(new Float(1.23), metaValue);
    metaValue = meta.get("org.robolectric.metaColor");
    assertTrue(Integer.class.isInstance(metaValue));
    assertEquals(Color.WHITE, metaValue);
    metaValue = meta.get("org.robolectric.metaBooleanFromRes");
    assertTrue(Boolean.class.isInstance(metaValue));
    assertEquals(RuntimeEnvironment.application.getResources().getBoolean(R.bool.false_bool_value), metaValue);
    metaValue = meta.get("org.robolectric.metaIntFromRes");
    assertTrue(Integer.class.isInstance(metaValue));
    assertEquals(RuntimeEnvironment.application.getResources().getInteger(R.integer.test_integer1), metaValue);
    metaValue = meta.get("org.robolectric.metaColorFromRes");
    assertTrue(Integer.class.isInstance(metaValue));
    assertEquals(RuntimeEnvironment.application.getResources().getColor(R.color.clear), metaValue);
    metaValue = meta.get("org.robolectric.metaStringFromRes");
    assertTrue(String.class.isInstance(metaValue));
    assertEquals(RuntimeEnvironment.application.getString(R.string.app_name), metaValue);
    metaValue = meta.get("org.robolectric.metaStringOfIntFromRes");
    assertTrue(String.class.isInstance(metaValue));
    assertEquals(RuntimeEnvironment.application.getString(R.string.str_int), metaValue);
    metaValue = meta.get("org.robolectric.metaStringRes");
    assertTrue(Integer.class.isInstance(metaValue));
    assertEquals(R.string.app_name, metaValue);
}
Also used : Bundle(android.os.Bundle) ShadowApplication(org.robolectric.shadows.ShadowApplication) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Aggregations

ShadowApplication (org.robolectric.shadows.ShadowApplication)6 Test (org.junit.Test)4 Application (android.app.Application)1 ComponentName (android.content.ComponentName)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 Config (org.robolectric.annotation.Config)1