How can I shadow the PackageManager with Robolectric

后端 未结 6 825
有刺的猬
有刺的猬 2020-12-15 22:16

My Android application has a simple method to fire off an intent to display a URL.

protected void launchBrowser(int id)
{
    Uri uri = Uri.parse( getStrin         


        
6条回答
  •  时光取名叫无心
    2020-12-15 23:07

    Just add on to aleph_null's answer, you can use ShadowResolveInfo.newResolveInfo() to quickly create a mock ResolveInfo ready to be used (I'm using Robolectric 2.4).

    RobolectricPackageManager rpm = (RobolectricPackageManager)Robolectric.application.getPackageManager();
    rpm.addResolveInfoForIntent(new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS), ShadowResolveInfo.newResolveInfo(...));
    

提交回复
热议问题