Search in sources :

Example 51 with AndroidManifest

use of org.robolectric.manifest.AndroidManifest in project edx-app-android by edx.

the class DataBindingRobolectricGradleTestRunner method getAppManifest.

@Override
protected AndroidManifest getAppManifest(Config config) {
    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, "data-binding-layout-out").exists()) {
        // Android gradle plugin 1.5.0+ puts the merged layouts in data-binding-layout-out.
        // https://github.com/robolectric/robolectric/issues/2143
        res = FileFsFile.from(BUILD_OUTPUT, "data-binding-layout-out", flavor, type);
    } else if (FileFsFile.from(BUILD_OUTPUT, "res", "merged").exists()) {
        // res/merged added in Android Gradle plugin 1.3-beta1
        res = FileFsFile.from(BUILD_OUTPUT, "res", "merged", flavor, type);
    } else 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()) {
        manifest = FileFsFile.from(BUILD_OUTPUT, "manifests", "full", 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)

Example 52 with AndroidManifest

use of org.robolectric.manifest.AndroidManifest in project Just-Another-Android-App by athkalia.

the class PermissionsTest method permissions_sanity_check.

@Test
public void permissions_sanity_check() {
    // Arrange
    AndroidManifest androidManifest = new AndroidManifest(Fs.fileFromPath("build/intermediates/manifests/full/debug/AndroidManifest.xml"), null, null);
    Set<String> permissions = new HashSet<>(androidManifest.getUsedPermissions());
    // Assert
    String[] expectedPermissions = { "android.permission.INTERNET" };
    assertThat(permissions).containsOnly(expectedPermissions);
}
Also used : AndroidManifest(org.robolectric.manifest.AndroidManifest) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 53 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)

Example 54 with AndroidManifest

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

the class RobolectricTestRunner method beforeTest.

@Override
protected void beforeTest(Sandbox sandbox, FrameworkMethod method, Method bootstrappedMethod) throws Throwable {
    AndroidSandbox androidSandbox = (AndroidSandbox) sandbox;
    RobolectricFrameworkMethod roboMethod = (RobolectricFrameworkMethod) method;
    PerfStatsCollector perfStatsCollector = PerfStatsCollector.getInstance();
    Sdk sdk = roboMethod.getSdk();
    perfStatsCollector.putMetadata(AndroidMetadata.class, new AndroidMetadata(ImmutableMap.of("ro.build.version.sdk", "" + sdk.getApiLevel()), roboMethod.resourcesMode.name()));
    Logger.lifecycle(roboMethod.getDeclaringClass().getName() + "." + roboMethod.getMethod().getName() + ": sdk=" + sdk.getApiLevel() + "; resources=" + roboMethod.resourcesMode);
    if (roboMethod.resourcesMode == ResourcesMode.LEGACY) {
        Logger.warn("Legacy resources mode is deprecated; see" + " http://robolectric.org/migrating/#migrating-to-40");
    }
    roboMethod.setStuff(androidSandbox, androidSandbox.getTestEnvironment());
    Class<TestLifecycle> cl = androidSandbox.bootstrappedClass(getTestLifecycleClass());
    roboMethod.testLifecycle = ReflectionHelpers.newInstance(cl);
    AndroidManifest appManifest = roboMethod.getAppManifest();
    roboMethod.getTestEnvironment().setUpApplicationState(bootstrappedMethod, roboMethod.getConfiguration(), appManifest);
    roboMethod.testLifecycle.beforeTest(bootstrappedMethod);
}
Also used : AndroidSandbox(org.robolectric.internal.AndroidSandbox) AndroidManifest(org.robolectric.manifest.AndroidManifest) Sdk(org.robolectric.pluginapi.Sdk) PerfStatsCollector(org.robolectric.util.PerfStatsCollector)

Example 55 with AndroidManifest

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

the class AndroidTestEnvironmentCreateApplicationTest method newConfigWith.

private AndroidManifest newConfigWith(String packageName, String contents) throws IOException {
    String fileContents = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" + "          package=\"" + packageName + "\">\n" + "    " + contents + "\n" + "</manifest>\n";
    File f = temporaryFolder.newFile("whatever.xml");
    Files.asCharSink(f, UTF_8).write(fileContents);
    return new AndroidManifest(f.toPath(), null, null);
}
Also used : AndroidManifest(org.robolectric.manifest.AndroidManifest) File(java.io.File)

Aggregations

AndroidManifest (org.robolectric.manifest.AndroidManifest)62 Test (org.junit.Test)28 ArrayList (java.util.ArrayList)10 ResourcePath (org.robolectric.res.ResourcePath)9 Properties (java.util.Properties)8 ActivityData (org.robolectric.manifest.ActivityData)8 Context (android.content.Context)6 BuildConfig (org.robolectric.gradleapp.BuildConfig)6 IntentFilterData (org.robolectric.manifest.IntentFilterData)6 FileFsFile (org.robolectric.res.FileFsFile)5 FsFile (org.robolectric.res.FsFile)5 Config (org.robolectric.annotation.Config)4 ActivityInfo (android.content.pm.ActivityInfo)3 File (java.io.File)3 DefaultManifestFactory (org.robolectric.internal.DefaultManifestFactory)3 ManifestFactory (org.robolectric.internal.ManifestFactory)3 Application (android.app.Application)2 ManifestIdentifier (org.robolectric.internal.ManifestIdentifier)2 ContentProviderData (org.robolectric.manifest.ContentProviderData)2 Sdk (org.robolectric.pluginapi.Sdk)2