use of org.robolectric.manifest.AndroidManifest in project robolectric by robolectric.
the class ShadowContentResolverTest method getProvider_shouldCreateProviderFromManifest.
@Test
public void getProvider_shouldCreateProviderFromManifest() {
AndroidManifest manifest = ShadowApplication.getInstance().getAppManifest();
ContentProviderData testProviderData = new ContentProviderData("org.robolectric.shadows.ShadowContentResolverTest$TestContentProvider", null, AUTHORITY, null, null, null);
try {
manifest.getContentProviders().add(testProviderData);
assertThat(ShadowContentResolver.getProvider(Uri.parse("content://" + AUTHORITY + "/shadows"))).isNotNull();
} finally {
manifest.getContentProviders().remove(testProviderData);
}
}
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 {
SdkEnvironment sdkEnvironment = (SdkEnvironment) sandbox;
RobolectricFrameworkMethod roboMethod = (RobolectricFrameworkMethod) method;
roboMethod.parallelUniverseInterface = getHooksInterface(sdkEnvironment);
Class<TestLifecycle> cl = sdkEnvironment.bootstrappedClass(getTestLifecycleClass());
roboMethod.testLifecycle = ReflectionHelpers.newInstance(cl);
final Config config = roboMethod.config;
final AndroidManifest appManifest = roboMethod.getAppManifest();
roboMethod.parallelUniverseInterface.setSdkConfig((sdkEnvironment).getSdkConfig());
roboMethod.parallelUniverseInterface.resetStaticState(config);
SdkConfig sdkConfig = roboMethod.sdkConfig;
Class<?> androidBuildVersionClass = (sdkEnvironment).bootstrappedClass(Build.VERSION.class);
ReflectionHelpers.setStaticField(androidBuildVersionClass, "SDK_INT", sdkConfig.getApiLevel());
ReflectionHelpers.setStaticField(androidBuildVersionClass, "RELEASE", sdkConfig.getAndroidVersion());
PackageResourceTable systemResourceTable = sdkEnvironment.getSystemResourceTable(getJarResolver());
PackageResourceTable appResourceTable = getAppResourceTable(appManifest);
roboMethod.parallelUniverseInterface.setUpApplicationState(bootstrappedMethod, roboMethod.testLifecycle, appManifest, config, new RoutingResourceTable(getCompiletimeSdkResourceTable(), appResourceTable), new RoutingResourceTable(systemResourceTable, appResourceTable), new RoutingResourceTable(systemResourceTable));
roboMethod.testLifecycle.beforeTest(bootstrappedMethod);
}
use of org.robolectric.manifest.AndroidManifest in project robolectric by robolectric.
the class ResourceMergerTest method libraryConfigShouldOverrideProjectProperties.
@Test
@Config(manifest = "src/test/resources/TestAndroidManifest.xml", libraries = "lib1")
public void libraryConfigShouldOverrideProjectProperties() throws Exception {
AndroidManifest manifest = Shadows.shadowOf(RuntimeEnvironment.application).getAppManifest();
List<AndroidManifest> libraryManifests = manifest.getLibraryManifests();
assertEquals(1, libraryManifests.size());
assertEquals("org.robolectric.lib1", libraryManifests.get(0).getPackageName());
}
use of org.robolectric.manifest.AndroidManifest in project robolectric by robolectric.
the class DefaultPackageManager method getProviderInfo.
@Override
public ProviderInfo getProviderInfo(ComponentName className, int flags) throws NameNotFoundException {
String packageName = className.getPackageName();
AndroidManifest androidManifest = androidManifests.get(packageName);
String classString = resolvePackageName(packageName, className);
for (ContentProviderData contentProviderData : androidManifest.getContentProviders()) {
if (contentProviderData.getClassName().equals(classString)) {
ProviderInfo providerInfo = new ProviderInfo();
providerInfo.packageName = packageName;
providerInfo.name = contentProviderData.getClassName();
// todo: support multiple authorities
providerInfo.authority = contentProviderData.getAuthorities();
providerInfo.readPermission = contentProviderData.getReadPermission();
providerInfo.writePermission = contentProviderData.getWritePermission();
providerInfo.pathPermissions = createPathPermissions(contentProviderData.getPathPermissionDatas());
if ((flags & GET_META_DATA) != 0) {
providerInfo.metaData = metaDataToBundle(contentProviderData.getMetaData().getValueMap());
}
return providerInfo;
}
}
return null;
}
use of org.robolectric.manifest.AndroidManifest in project robolectric by robolectric.
the class DefaultPackageManager method getServiceInfo.
@Override
public ServiceInfo getServiceInfo(ComponentName className, int flags) throws NameNotFoundException {
String packageName = className.getPackageName();
AndroidManifest androidManifest = androidManifests.get(packageName);
String serviceName = className.getClassName();
ServiceData serviceData = androidManifest.getServiceData(serviceName);
if (serviceData == null) {
throw new NameNotFoundException(serviceName);
}
ServiceInfo serviceInfo = new ServiceInfo();
serviceInfo.packageName = packageName;
serviceInfo.name = serviceName;
serviceInfo.applicationInfo = getApplicationInfo(packageName, flags);
serviceInfo.permission = serviceData.getPermission();
if ((flags & GET_META_DATA) != 0) {
serviceInfo.metaData = metaDataToBundle(serviceData.getMetaData().getValueMap());
}
return serviceInfo;
}
Aggregations