Search in sources :

Example 21 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 22 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 23 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 24 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 25 with AndroidManifest

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

the class ShadowActivity method setThemeFromManifest.

public boolean setThemeFromManifest() {
    ShadowApplication shadowApplication = shadowOf(realActivity.getApplication());
    AndroidManifest appManifest = shadowApplication.getAppManifest();
    if (appManifest == null)
        return false;
    String themeRef = appManifest.getThemeRef(realActivity.getClass().getName());
    if (themeRef != null) {
        int themeRes = realActivity.getResources().getIdentifier(themeRef.replace("@", ""), "style", appManifest.getPackageName());
        realActivity.setTheme(themeRes);
        return true;
    }
    return false;
}
Also used : 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