Search in sources :

Example 11 with AndroidManifest

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

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

the class RobolectricTestRunner method getChildren.

@Override
protected List<FrameworkMethod> getChildren() {
    List<FrameworkMethod> children = new ArrayList<>();
    for (FrameworkMethod frameworkMethod : super.getChildren()) {
        try {
            Config config = getConfig(frameworkMethod.getMethod());
            AndroidManifest appManifest = getAppManifest(config);
            List<SdkConfig> sdksToRun = sdkPicker.selectSdks(config, appManifest);
            RobolectricFrameworkMethod last = null;
            for (SdkConfig sdkConfig : sdksToRun) {
                last = new RobolectricFrameworkMethod(frameworkMethod.getMethod(), appManifest, sdkConfig, config);
                children.add(last);
            }
            if (last != null) {
                last.dontIncludeApiLevelInName();
            }
        } catch (IllegalArgumentException e) {
            throw new IllegalArgumentException("failed to configure " + getTestClass().getName() + "." + frameworkMethod.getMethod().getName() + ": " + e.getMessage(), e);
        }
    }
    return children;
}
Also used : Config(org.robolectric.annotation.Config) AndroidManifest(org.robolectric.manifest.AndroidManifest) FrameworkMethod(org.junit.runners.model.FrameworkMethod)

Example 13 with AndroidManifest

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

the class RobolectricTestRunner method getAppManifest.

protected AndroidManifest getAppManifest(Config config) {
    ManifestFactory manifestFactory = getManifestFactory(config);
    ManifestIdentifier identifier = manifestFactory.identify(config);
    synchronized (appManifestsCache) {
        AndroidManifest appManifest;
        appManifest = appManifestsCache.get(identifier);
        if (appManifest == null) {
            appManifest = manifestFactory.create(identifier);
            appManifestsCache.put(identifier, appManifest);
        }
        return appManifest;
    }
}
Also used : AndroidManifest(org.robolectric.manifest.AndroidManifest)

Example 14 with AndroidManifest

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

the class ActivityController method getActivityTitle.

private String getActivityTitle() {
    String title = null;
    /* Get the label for the activity from the manifest */
    ShadowApplicationAdapter shadowApplicationAdapter = shadowsAdapter.getApplicationAdapter(component);
    AndroidManifest appManifest = shadowApplicationAdapter.getAppManifest();
    if (appManifest == null)
        return null;
    String labelRef = appManifest.getActivityLabel(component.getClass().getName());
    if (labelRef != null) {
        if (labelRef.startsWith("@")) {
            /* Label refers to a string value, get the resource identifier */
            int labelRes = RuntimeEnvironment.application.getResources().getIdentifier(labelRef.replace("@", ""), "string", appManifest.getPackageName());
            /* Get the resource ID, use the activity to look up the actual string */
            title = RuntimeEnvironment.application.getString(labelRes);
        } else {
            title = labelRef;
        /* Label isn't an identifier, use it directly as the title */
        }
    }
    return title;
}
Also used : ShadowApplicationAdapter(org.robolectric.ShadowsAdapter.ShadowApplicationAdapter) AndroidManifest(org.robolectric.manifest.AndroidManifest)

Example 15 with AndroidManifest

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

the class GradleManifestFactoryTest method getAppManifest_withBuildDirOverride_shouldCreateManifest.

@Test
public void getAppManifest_withBuildDirOverride_shouldCreateManifest() throws Exception {
    final AndroidManifest manifest = createManifest(configBuilder.setConstants(BuildConfig.class).setBuildDir("custom_build").build());
    assertThat(manifest.getPackageName()).isEqualTo("org.robolectric.gradleapp");
    assertThat(manifest.getResDirectory()).isEqualTo(file("custom_build/intermediates/res/flavor1/type1"));
    assertThat(manifest.getAssetsDirectory()).isEqualTo(file("custom_build/intermediates/assets/flavor1/type1"));
    assertThat(manifest.getAndroidManifestFile()).isEqualTo(file("custom_build/intermediates/bundles/flavor1/type1/AndroidManifest.xml"));
}
Also used : AndroidManifest(org.robolectric.manifest.AndroidManifest) BuildConfig(org.robolectric.gradleapp.BuildConfig) Test(org.junit.Test)

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