Search in sources :

Example 1 with ManifestIdentifier

use of org.robolectric.internal.ManifestIdentifier in project robolectric by robolectric.

the class ManifestFactoryTest method whenConfigSpecified_overridesValuesFromFile.

@Test
public void whenConfigSpecified_overridesValuesFromFile() throws Exception {
    final Properties properties = new Properties();
    properties.setProperty("android_sdk_home", "");
    properties.setProperty("android_merged_manifest", "/path/to/MergedManifest.xml");
    properties.setProperty("android_merged_resources", "/path/to/merged-resources");
    properties.setProperty("android_merged_assets", "/path/to/merged-assets");
    RobolectricTestRunner testRunner = new RobolectricTestRunner(ManifestFactoryTest.class) {

        Properties getBuildSystemApiProperties() {
            return properties;
        }
    };
    Config.Implementation config = Config.Builder.defaults().setManifest("/TestAndroidManifest.xml").setPackageName("another.package").build();
    ManifestFactory manifestFactory = testRunner.getManifestFactory(config);
    assertThat(manifestFactory).isInstanceOf(DefaultManifestFactory.class);
    ManifestIdentifier manifestIdentifier = manifestFactory.identify(config);
    assertThat(manifestIdentifier.getManifestFile()).isEqualTo(Fs.fileFromPath(getClass().getResource("/TestAndroidManifest.xml").getPath()));
    assertThat(manifestIdentifier.getResDir()).isEqualTo(Fs.fileFromPath("/path/to/merged-resources"));
    assertThat(manifestIdentifier.getAssetDir()).isEqualTo(Fs.fileFromPath("/path/to/merged-assets"));
    assertThat(manifestIdentifier.getLibraryDirs()).isEmpty();
    assertThat(manifestIdentifier.getPackageName()).isEqualTo("another.package");
}
Also used : Config(org.robolectric.annotation.Config) ManifestIdentifier(org.robolectric.internal.ManifestIdentifier) Properties(java.util.Properties) ManifestFactory(org.robolectric.internal.ManifestFactory) DefaultManifestFactory(org.robolectric.internal.DefaultManifestFactory) Test(org.junit.Test)

Example 2 with ManifestIdentifier

use of org.robolectric.internal.ManifestIdentifier in project robolectric by robolectric.

the class ManifestFactoryTest method whenBuildSystemApiPropertiesFileIsPresent_shouldUseDefaultManifestFactory.

@Test
public void whenBuildSystemApiPropertiesFileIsPresent_shouldUseDefaultManifestFactory() throws Exception {
    final Properties properties = new Properties();
    properties.setProperty("android_sdk_home", "");
    properties.setProperty("android_merged_manifest", "/path/to/MergedManifest.xml");
    properties.setProperty("android_merged_resources", "/path/to/merged-resources");
    properties.setProperty("android_merged_assets", "/path/to/merged-assets");
    RobolectricTestRunner testRunner = new RobolectricTestRunner(ManifestFactoryTest.class) {

        Properties getBuildSystemApiProperties() {
            return properties;
        }
    };
    Config.Implementation config = Config.Builder.defaults().build();
    ManifestFactory manifestFactory = testRunner.getManifestFactory(config);
    assertThat(manifestFactory).isInstanceOf(DefaultManifestFactory.class);
    ManifestIdentifier manifestIdentifier = manifestFactory.identify(config);
    assertThat(manifestIdentifier.getManifestFile()).isEqualTo(Fs.fileFromPath("/path/to/MergedManifest.xml"));
    assertThat(manifestIdentifier.getResDir()).isEqualTo(Fs.fileFromPath("/path/to/merged-resources"));
    assertThat(manifestIdentifier.getAssetDir()).isEqualTo(Fs.fileFromPath("/path/to/merged-assets"));
    assertThat(manifestIdentifier.getLibraryDirs()).isEmpty();
    assertThat(manifestIdentifier.getPackageName()).isNull();
    AndroidManifest androidManifest = manifestFactory.create(manifestIdentifier);
    assertThat(androidManifest.getAndroidManifestFile()).isEqualTo(Fs.fileFromPath("/path/to/MergedManifest.xml"));
    assertThat(androidManifest.getResDirectory()).isEqualTo(Fs.fileFromPath("/path/to/merged-resources"));
    assertThat(androidManifest.getAssetsDirectory()).isEqualTo(Fs.fileFromPath("/path/to/merged-assets"));
}
Also used : Config(org.robolectric.annotation.Config) ManifestIdentifier(org.robolectric.internal.ManifestIdentifier) AndroidManifest(org.robolectric.manifest.AndroidManifest) Properties(java.util.Properties) ManifestFactory(org.robolectric.internal.ManifestFactory) DefaultManifestFactory(org.robolectric.internal.DefaultManifestFactory) Test(org.junit.Test)

Aggregations

Properties (java.util.Properties)2 Test (org.junit.Test)2 Config (org.robolectric.annotation.Config)2 DefaultManifestFactory (org.robolectric.internal.DefaultManifestFactory)2 ManifestFactory (org.robolectric.internal.ManifestFactory)2 ManifestIdentifier (org.robolectric.internal.ManifestIdentifier)2 AndroidManifest (org.robolectric.manifest.AndroidManifest)1