use of android.content.pm.ProviderInfo in project robolectric by robolectric.
the class ShadowPackageManagerTest method removeProvider.
@Test
public void removeProvider() {
ComponentName componentName = new ComponentName(context, "org.robolectric.shadows.testing.TestContentProvider1");
ProviderInfo removed = shadowOf(packageManager).removeProvider(componentName);
assertThat(removed).isNotNull();
try {
packageManager.getProviderInfo(componentName, 0);
fail();
} catch (NameNotFoundException e) {
// expected
}
}
use of android.content.pm.ProviderInfo in project robolectric by robolectric.
the class ShadowPackageManagerTest method getProviderInfo_shouldPopulatePermissionsInProviderInfos.
@Test
public void getProviderInfo_shouldPopulatePermissionsInProviderInfos() throws Exception {
ProviderInfo providerInfo = packageManager.getProviderInfo(new ComponentName(context, "org.robolectric.shadows.testing.TestContentProvider1"), 0);
assertThat(providerInfo.authority).isEqualTo("org.robolectric.authority1");
assertThat(providerInfo.readPermission).isEqualTo("READ_PERMISSION");
assertThat(providerInfo.writePermission).isEqualTo("WRITE_PERMISSION");
assertThat(providerInfo.pathPermissions).asList().hasSize(1);
assertThat(providerInfo.pathPermissions[0].getType()).isEqualTo(PathPermission.PATTERN_SIMPLE_GLOB);
assertThat(providerInfo.pathPermissions[0].getPath()).isEqualTo("/path/*");
assertThat(providerInfo.pathPermissions[0].getReadPermission()).isEqualTo("PATH_READ_PERMISSION");
assertThat(providerInfo.pathPermissions[0].getWritePermission()).isEqualTo("PATH_WRITE_PERMISSION");
}
use of android.content.pm.ProviderInfo in project robolectric by robolectric.
the class ShadowPackageManagerTest method addProvider.
@Test
public void addProvider() throws Exception {
ProviderInfo providerInfo = new ProviderInfo();
providerInfo.name = "name";
providerInfo.packageName = "package";
shadowOf(packageManager).addOrUpdateProvider(providerInfo);
assertThat(packageManager.getProviderInfo(new ComponentName("package", "name"), 0)).isNotNull();
}
use of android.content.pm.ProviderInfo in project robolectric by robolectric.
the class ContentProviderController method create.
/**
* Create and register {@link ContentProvider} using {@link ProviderInfo} found from manifest.
*/
public ContentProviderController<T> create() {
Context baseContext = RuntimeEnvironment.getApplication().getBaseContext();
ComponentName componentName = createRelative(baseContext.getPackageName(), contentProvider.getClass().getName());
ProviderInfo providerInfo = null;
try {
providerInfo = baseContext.getPackageManager().getProviderInfo(componentName, PackageManager.MATCH_DISABLED_COMPONENTS);
} catch (PackageManager.NameNotFoundException e) {
Logger.strict("Unable to find provider info for " + componentName, e);
}
return create(providerInfo);
}
use of android.content.pm.ProviderInfo in project robolectric by robolectric.
the class ShadowContentResolverTest method registerProvider_shouldAttachProviderInfo.
@Test
public void registerProvider_shouldAttachProviderInfo() {
ContentProvider mock = mock(ContentProvider.class);
ProviderInfo providerInfo0 = new ProviderInfo();
// todo: support multiple authorities
providerInfo0.authority = "the-authority";
providerInfo0.grantUriPermissions = true;
mock.attachInfo(ApplicationProvider.getApplicationContext(), providerInfo0);
mock.onCreate();
ArgumentCaptor<ProviderInfo> captor = ArgumentCaptor.forClass(ProviderInfo.class);
verify(mock).attachInfo(same((Application) ApplicationProvider.getApplicationContext()), captor.capture());
ProviderInfo providerInfo = captor.getValue();
assertThat(providerInfo.authority).isEqualTo("the-authority");
assertThat(providerInfo.grantUriPermissions).isEqualTo(true);
}
Aggregations