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