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);
}
}
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());
}
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");
}
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;
}
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);
}
Aggregations