Search in sources :

Example 1 with ManifestFactory

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

the class ManifestFactoryTest method shouldLoadAllResourcesForExistingLibraries.

@Test
public void shouldLoadAllResourcesForExistingLibraries() throws Exception {
    Properties properties = new Properties();
    properties.setProperty("manifest", resourceFile("TestAndroidManifest.xml").toString());
    properties.setProperty("resourceDir", "res");
    properties.setProperty("assetDir", "assets");
    Config config = Config.Implementation.fromProperties(properties);
    ManifestFactory manifestFactory = new RobolectricTestRunner(ManifestFactoryTest.class).getManifestFactory(config);
    AndroidManifest appManifest = manifestFactory.create(manifestFactory.identify(config));
    // This intentionally loads from the non standard resources/project.properties
    List<String> resourcePaths = stringify(appManifest.getIncludedResourcePaths());
    assertEquals(asList(joinPath(".", "src", "test", "resources", "res"), joinPath(".", "src", "test", "resources", "lib1", "res"), joinPath(".", "src", "test", "resources", "lib1", "..", "lib3", "res"), joinPath(".", "src", "test", "resources", "lib1", "..", "lib2", "res")), resourcePaths);
}
Also used : Config(org.robolectric.annotation.Config) AndroidManifest(org.robolectric.manifest.AndroidManifest) Properties(java.util.Properties) ManifestFactory(org.robolectric.internal.ManifestFactory) DefaultManifestFactory(org.robolectric.internal.DefaultManifestFactory) Test(org.junit.Test)

Example 2 with ManifestFactory

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

the class RobolectricTestRunner method getAppManifest.

private AndroidManifest getAppManifest(Configuration configuration) {
    Config config = configuration.get(Config.class);
    ManifestFactory manifestFactory = getManifestFactory(config);
    ManifestIdentifier identifier = manifestFactory.identify(config);
    return cachedCreateAppManifest(identifier);
}
Also used : Config(org.robolectric.annotation.Config) ManifestIdentifier(org.robolectric.internal.ManifestIdentifier) MavenManifestFactory(org.robolectric.internal.MavenManifestFactory) ManifestFactory(org.robolectric.internal.ManifestFactory) BuckManifestFactory(org.robolectric.internal.BuckManifestFactory) DefaultManifestFactory(org.robolectric.internal.DefaultManifestFactory)

Example 3 with ManifestFactory

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

the class ManifestFactoryTest method shouldLoadLibraryManifests.

@Test
public void shouldLoadLibraryManifests() throws Exception {
    Properties properties = new Properties();
    properties.setProperty("manifest", resourceFile("TestAndroidManifest.xml").toString());
    properties.setProperty("libraries", "lib1");
    Config config = Config.Implementation.fromProperties(properties);
    ManifestFactory manifestFactory = new RobolectricTestRunner(ManifestFactoryTest.class).getManifestFactory(config);
    AndroidManifest manifest = manifestFactory.create(manifestFactory.identify(config));
    List<AndroidManifest> libraryManifests = manifest.getLibraryManifests();
    assertEquals(1, libraryManifests.size());
    assertEquals("org.robolectric.lib1", libraryManifests.get(0).getPackageName());
}
Also used : Config(org.robolectric.annotation.Config) AndroidManifest(org.robolectric.manifest.AndroidManifest) Properties(java.util.Properties) ManifestFactory(org.robolectric.internal.ManifestFactory) DefaultManifestFactory(org.robolectric.internal.DefaultManifestFactory) Test(org.junit.Test)

Example 4 with ManifestFactory

use of org.robolectric.internal.ManifestFactory 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) {

        @Override
        protected 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(Paths.get("/path/to/MergedManifest.xml"));
    assertThat(manifestIdentifier.getResDir()).isEqualTo(Paths.get("/path/to/merged-resources"));
    assertThat(manifestIdentifier.getAssetDir()).isEqualTo(Paths.get("/path/to/merged-assets"));
    assertThat(manifestIdentifier.getLibraries()).isEmpty();
    assertThat(manifestIdentifier.getPackageName()).isNull();
    AndroidManifest androidManifest = RobolectricTestRunner.createAndroidManifest(manifestIdentifier);
    assertThat(androidManifest.getAndroidManifestFile()).isEqualTo(Paths.get("/path/to/MergedManifest.xml"));
    assertThat(androidManifest.getResDirectory()).isEqualTo(Paths.get("/path/to/merged-resources"));
    assertThat(androidManifest.getAssetsDirectory()).isEqualTo(Paths.get("/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)

Example 5 with ManifestFactory

use of org.robolectric.internal.ManifestFactory 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) {

        @Override
        protected 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);
    URL expectedUrl = getClass().getClassLoader().getResource("TestAndroidManifest.xml");
    assertThat(manifestIdentifier.getManifestFile()).isEqualTo(Fs.fromUrl(expectedUrl));
    assertThat(manifestIdentifier.getResDir()).isEqualTo(Paths.get("/path/to/merged-resources"));
    assertThat(manifestIdentifier.getAssetDir()).isEqualTo(Paths.get("/path/to/merged-assets"));
    assertThat(manifestIdentifier.getLibraries()).isEmpty();
    assertThat(manifestIdentifier.getPackageName()).isEqualTo("another.package");
}
Also used : Config(org.robolectric.annotation.Config) ManifestIdentifier(org.robolectric.internal.ManifestIdentifier) Properties(java.util.Properties) URL(java.net.URL) ManifestFactory(org.robolectric.internal.ManifestFactory) DefaultManifestFactory(org.robolectric.internal.DefaultManifestFactory) Test(org.junit.Test)

Aggregations

Config (org.robolectric.annotation.Config)5 DefaultManifestFactory (org.robolectric.internal.DefaultManifestFactory)5 ManifestFactory (org.robolectric.internal.ManifestFactory)5 Properties (java.util.Properties)4 Test (org.junit.Test)4 ManifestIdentifier (org.robolectric.internal.ManifestIdentifier)3 AndroidManifest (org.robolectric.manifest.AndroidManifest)3 URL (java.net.URL)1 BuckManifestFactory (org.robolectric.internal.BuckManifestFactory)1 MavenManifestFactory (org.robolectric.internal.MavenManifestFactory)1