use of org.robolectric.manifest.AndroidManifest in project robolectric by robolectric.
the class AndroidTestEnvironmentCreateApplicationTest method shouldRegisterReceiversFromTheManifest.
@Test
// preexisting when check was enabled
@SuppressWarnings("RobolectricSystemContext")
public void shouldRegisterReceiversFromTheManifest() throws Exception {
// gross:
shadowOf((Application) ApplicationProvider.getApplicationContext()).clearRegisteredReceivers();
AndroidManifest appManifest = newConfigWith("<application>" + " <receiver android:name=\"org.robolectric.fakes.ConfigTestReceiver\">" + " <intent-filter>\n" + " <action android:name=\"org.robolectric.ACTION_SUPERSET_PACKAGE\"/>\n" + " </intent-filter>" + " </receiver>" + "</application>");
Application application = AndroidTestEnvironment.createApplication(appManifest, null, new ApplicationInfo());
shadowOf(application).callAttach(RuntimeEnvironment.systemContext);
registerBroadcastReceivers(application, appManifest);
List<ShadowApplication.Wrapper> receivers = shadowOf(application).getRegisteredReceivers();
assertThat(receivers).hasSize(1);
assertThat(receivers.get(0).intentFilter.matchAction("org.robolectric.ACTION_SUPERSET_PACKAGE")).isTrue();
}
use of org.robolectric.manifest.AndroidManifest in project robolectric by robolectric.
the class DefaultManifestFactoryTest method identify_withMissingValues.
@Test
public void identify_withMissingValues() {
Properties properties = new Properties();
properties.put("android_merged_manifest", "");
properties.put("android_merged_assets", "gradle/assets");
properties.put("android_resource_apk", "gradle/resources.ap_");
DefaultManifestFactory factory = new DefaultManifestFactory(properties);
ManifestIdentifier identifier = factory.identify(Config.Builder.defaults().build());
AndroidManifest manifest = RobolectricTestRunner.createAndroidManifest(identifier);
assertThat(manifest.getAndroidManifestFile()).isNull();
assertThat(manifest.getResDirectory()).isNull();
assertThat(manifest.getAssetsDirectory()).isEqualTo(Paths.get("gradle/assets"));
assertThat(manifest.getApkFile()).isEqualTo(Paths.get("gradle/resources.ap_"));
}
use of org.robolectric.manifest.AndroidManifest in project robolectric by robolectric.
the class DefaultManifestFactoryTest method identify_configNoneShouldBeIgnored.
@Test
public void identify_configNoneShouldBeIgnored() throws Exception {
Properties properties = new Properties();
properties.put("android_merged_manifest", "gradle/AndroidManifest.xml");
properties.put("android_merged_resources", "gradle/res");
properties.put("android_merged_assets", "gradle/assets");
properties.put("android_custom_package", "com.example.app");
DefaultManifestFactory factory = new DefaultManifestFactory(properties);
ManifestIdentifier identifier = factory.identify(Config.Builder.defaults().setManifest(Config.NONE).build());
AndroidManifest manifest = RobolectricTestRunner.createAndroidManifest(identifier);
assertThat(manifest.getAndroidManifestFile()).isEqualTo(Paths.get("gradle/AndroidManifest.xml"));
assertThat(manifest.getResDirectory()).isEqualTo(Paths.get("gradle/res"));
assertThat(manifest.getAssetsDirectory()).isEqualTo(Paths.get("gradle/assets"));
assertThat(manifest.getRClassName()).isEqualTo("com.example.app.R");
}
use of org.robolectric.manifest.AndroidManifest in project robolectric by robolectric.
the class DefaultManifestFactoryTest method identify_packageCanBeOverridenFromConfig.
@Test
public void identify_packageCanBeOverridenFromConfig() throws Exception {
Properties properties = new Properties();
properties.put("android_merged_manifest", "gradle/AndroidManifest.xml");
properties.put("android_merged_resources", "gradle/res");
properties.put("android_merged_assets", "gradle/assets");
DefaultManifestFactory factory = new DefaultManifestFactory(properties);
ManifestIdentifier identifier = factory.identify(Config.Builder.defaults().setPackageName("overridden.package").build());
AndroidManifest manifest = RobolectricTestRunner.createAndroidManifest(identifier);
assertThat(manifest.getAndroidManifestFile()).isEqualTo(Paths.get("gradle/AndroidManifest.xml"));
assertThat(manifest.getResDirectory()).isEqualTo(Paths.get("gradle/res"));
assertThat(manifest.getAssetsDirectory()).isEqualTo(Paths.get("gradle/assets"));
assertThat(manifest.getRClassName()).isEqualTo("overridden.package.R");
}
use of org.robolectric.manifest.AndroidManifest in project robolectric by robolectric.
the class DefaultManifestFactoryTest method identify_withResourceApk.
@Test
public void identify_withResourceApk() {
Properties properties = new Properties();
properties.put("android_merged_manifest", "gradle/AndroidManifest.xml");
properties.put("android_merged_resources", "gradle/res");
properties.put("android_merged_assets", "gradle/assets");
properties.put("android_resource_apk", "gradle/resources.ap_");
DefaultManifestFactory factory = new DefaultManifestFactory(properties);
ManifestIdentifier identifier = factory.identify(Config.Builder.defaults().build());
AndroidManifest manifest = RobolectricTestRunner.createAndroidManifest(identifier);
assertThat(manifest.getAndroidManifestFile()).isEqualTo(Paths.get("gradle/AndroidManifest.xml"));
assertThat(manifest.getResDirectory()).isEqualTo(Paths.get("gradle/res"));
assertThat(manifest.getAssetsDirectory()).isEqualTo(Paths.get("gradle/assets"));
assertThat(manifest.getApkFile()).isEqualTo(Paths.get("gradle/resources.ap_"));
}
Aggregations