@Test
public void testProviderRegistry() {
Context appContext = InstrumentationRegistry.getTargetContext();
PackageManager pm = appContext.getPackageManager();
// We define the component name based on the package name from the context and the
// Provider class.
ComponentName componentName = new ComponentName(appContext.getPackageName(),
FavoritesProvider.class.getName());
try {
// Fetch the provider info using the component name from the PackageManager
// This throws an exception if the provider isn't registered.
ProviderInfo providerInfo = pm.getProviderInfo(componentName, 0);
// Make sure that the registered authority matches the authority from the Contract.
assertEquals("Error: FavoritesProvider registered with authority: " + providerInfo.authority
+ " instead of authority: " + FavoritesContract.AUTHORITY,
providerInfo.authority, FavoritesContract.AUTHORITY);
} catch (PackageManager.NameNotFoundException e) {
// I guess the provider isn't registered correctly.
assertTrue("Error: FavoritesProvider not registered at " + appContext.getPackageName(),
false);
}
}
TestProvider.java 文件源码
java
阅读 44
收藏 0
点赞 0
评论 0
项目:MovieGuide
作者:
评论列表
文章目录