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