Search in sources :

Example 56 with AndroidManifest

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();
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) AndroidManifest(org.robolectric.manifest.AndroidManifest) ShadowApplication(org.robolectric.shadows.ShadowApplication) Application(android.app.Application) TestApplication(org.robolectric.shadows.testing.TestApplication) Test(org.junit.Test)

Example 57 with AndroidManifest

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_"));
}
Also used : AndroidManifest(org.robolectric.manifest.AndroidManifest) Properties(java.util.Properties) Test(org.junit.Test)

Example 58 with AndroidManifest

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");
}
Also used : AndroidManifest(org.robolectric.manifest.AndroidManifest) Properties(java.util.Properties) Test(org.junit.Test)

Example 59 with AndroidManifest

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");
}
Also used : AndroidManifest(org.robolectric.manifest.AndroidManifest) Properties(java.util.Properties) Test(org.junit.Test)

Example 60 with AndroidManifest

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_"));
}
Also used : AndroidManifest(org.robolectric.manifest.AndroidManifest) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

AndroidManifest (org.robolectric.manifest.AndroidManifest)62 Test (org.junit.Test)28 ArrayList (java.util.ArrayList)10 ResourcePath (org.robolectric.res.ResourcePath)9 Properties (java.util.Properties)8 ActivityData (org.robolectric.manifest.ActivityData)8 Context (android.content.Context)6 BuildConfig (org.robolectric.gradleapp.BuildConfig)6 IntentFilterData (org.robolectric.manifest.IntentFilterData)6 FileFsFile (org.robolectric.res.FileFsFile)5 FsFile (org.robolectric.res.FsFile)5 Config (org.robolectric.annotation.Config)4 ActivityInfo (android.content.pm.ActivityInfo)3 File (java.io.File)3 DefaultManifestFactory (org.robolectric.internal.DefaultManifestFactory)3 ManifestFactory (org.robolectric.internal.ManifestFactory)3 Application (android.app.Application)2 ManifestIdentifier (org.robolectric.internal.ManifestIdentifier)2 ContentProviderData (org.robolectric.manifest.ContentProviderData)2 Sdk (org.robolectric.pluginapi.Sdk)2