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