Search in sources :

Example 36 with AndroidManifest

use of org.robolectric.manifest.AndroidManifest 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 37 with AndroidManifest

use of org.robolectric.manifest.AndroidManifest 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)

Example 38 with AndroidManifest

use of org.robolectric.manifest.AndroidManifest in project robolectric by robolectric.

the class OverrideSdkVersionTest method whenNotOverridden_shouldUseTargetSdkVersionFromAppManifest.

@Test
public void whenNotOverridden_shouldUseTargetSdkVersionFromAppManifest() {
    AndroidManifest appManifest = ShadowApplication.getInstance().getAppManifest();
    assertThat(Build.VERSION.SDK_INT).isEqualTo(appManifest.getTargetSdkVersion());
}
Also used : AndroidManifest(org.robolectric.manifest.AndroidManifest) Test(org.junit.Test)

Example 39 with AndroidManifest

use of org.robolectric.manifest.AndroidManifest in project robolectric by robolectric.

the class ParallelUniverseTest method setUpApplicationState.

private void setUpApplicationState(Config defaultConfig) {
    ResourceTable sdkResourceProvider = ResourceTableFactory.newFrameworkResourceTable(new ResourcePath(android.R.class, null, null));
    final RoutingResourceTable routingResourceTable = new RoutingResourceTable(ResourceTableFactory.newResourceTable("org.robolectric", new ResourcePath(R.class, null, null)));
    pu.setUpApplicationState(null, new DefaultTestLifecycle(), new AndroidManifest(null, null, null, "package"), defaultConfig, sdkResourceProvider, routingResourceTable, RuntimeEnvironment.getSystemResourceTable());
}
Also used : R(org.robolectric.R) DefaultTestLifecycle(org.robolectric.DefaultTestLifecycle) AndroidManifest(org.robolectric.manifest.AndroidManifest)

Example 40 with AndroidManifest

use of org.robolectric.manifest.AndroidManifest in project algoliasearch-client-android by algolia.

the class CustomRunner method getAppManifest.

@Override
protected AndroidManifest getAppManifest(Config config) {
    final String cwd = System.getProperty("user.dir");
    Logger.debug("Current working directory: " + cwd);
    if (config.constants() == Void.class) {
        Logger.error("Field 'constants' not specified in @Config annotation");
        Logger.error("This is required when using RobolectricGradleTestRunner!");
        throw new RuntimeException("No 'constants' field in @Config annotation!");
    }
    final String type = getType(config);
    final String flavor = getFlavor(config);
    final String packageName = getPackageName(config);
    final FileFsFile res;
    final FileFsFile assets;
    final FileFsFile manifest;
    if (FileFsFile.from(BUILD_OUTPUT, "res").exists()) {
        res = FileFsFile.from(BUILD_OUTPUT, "res", flavor, type);
    } else {
        res = FileFsFile.from(BUILD_OUTPUT, "bundles", flavor, type, "res");
    }
    if (FileFsFile.from(BUILD_OUTPUT, "assets").exists()) {
        assets = FileFsFile.from(BUILD_OUTPUT, "assets", flavor, type);
    } else {
        assets = FileFsFile.from(BUILD_OUTPUT, "bundles", flavor, type, "assets");
    }
    if (FileFsFile.from(BUILD_OUTPUT, "manifests").exists()) {
        // [CUSTOMIZED] The default implementation uses `full` instead of `aapt`.
        manifest = FileFsFile.from(BUILD_OUTPUT, "manifests", "aapt", flavor, type, "AndroidManifest.xml");
    } else {
        manifest = FileFsFile.from(BUILD_OUTPUT, "bundles", flavor, type, "AndroidManifest.xml");
    }
    Logger.debug("Robolectric assets directory: " + assets.getPath());
    Logger.debug("   Robolectric res directory: " + res.getPath());
    Logger.debug("   Robolectric manifest path: " + manifest.getPath());
    Logger.debug("    Robolectric package name: " + packageName);
    return new AndroidManifest(manifest, res, assets, packageName);
}
Also used : FileFsFile(org.robolectric.res.FileFsFile) AndroidManifest(org.robolectric.manifest.AndroidManifest)

Aggregations

AndroidManifest (org.robolectric.manifest.AndroidManifest)40 Test (org.junit.Test)21 Config (org.robolectric.annotation.Config)6 BuildConfig (org.robolectric.gradleapp.BuildConfig)6 FsFile (org.robolectric.res.FsFile)5 FileFsFile (org.robolectric.res.FileFsFile)4 ActivityInfo (android.content.pm.ActivityInfo)3 ArrayList (java.util.ArrayList)3 Properties (java.util.Properties)3 DefaultManifestFactory (org.robolectric.internal.DefaultManifestFactory)3 ManifestFactory (org.robolectric.internal.ManifestFactory)3 ContentProviderData (org.robolectric.manifest.ContentProviderData)3 File (java.io.File)2 ActivityData (org.robolectric.manifest.ActivityData)2 ResourcePath (org.robolectric.res.ResourcePath)2 Application (android.app.Application)1 ContentProvider (android.content.ContentProvider)1 ProviderInfo (android.content.pm.ProviderInfo)1 ResolveInfo (android.content.pm.ResolveInfo)1 ServiceInfo (android.content.pm.ServiceInfo)1