use of org.robolectric.res.builder.RobolectricPackageManager in project materialistic by hidroh.
the class ItemActivityTest method testOptionExternal.
@SuppressLint("NewApi")
@Test
public void testOptionExternal() {
RobolectricPackageManager packageManager = (RobolectricPackageManager) RuntimeEnvironment.application.getPackageManager();
packageManager.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("http://example.com")), ShadowResolveInfo.newResolveInfo("label", "com.android.chrome", "DefaultActivity"));
packageManager.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(String.format(HackerNewsClient.WEB_ITEM_PATH, "1"))), ShadowResolveInfo.newResolveInfo("label", "com.android.chrome", "DefaultActivity"));
Intent intent = new Intent();
intent.putExtra(ItemActivity.EXTRA_ITEM, new TestItem() {
@NonNull
@Override
public String getType() {
return STORY_TYPE;
}
@Override
public String getUrl() {
return "http://example.com";
}
@Override
public boolean isStoryType() {
return true;
}
@Override
public String getId() {
return "1";
}
});
controller.withIntent(intent).create().start().resume();
// inflate menu, see https://github.com/robolectric/robolectric/issues/1326
ShadowLooper.pauseMainLooper();
controller.visible();
ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable();
// open article
shadowOf(activity).clickMenuItem(R.id.menu_external);
shadowOf(ShadowPopupMenu.getLatestPopupMenu()).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_article));
ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable();
assertThat(shadowOf(activity).getNextStartedActivity()).hasAction(Intent.ACTION_VIEW);
// open item
shadowOf(activity).clickMenuItem(R.id.menu_external);
shadowOf(ShadowPopupMenu.getLatestPopupMenu()).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_comments));
ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable();
assertThat(shadowOf(activity).getNextStartedActivity()).hasAction(Intent.ACTION_VIEW);
}
use of org.robolectric.res.builder.RobolectricPackageManager in project robolectric by robolectric.
the class RobolectricTest method reset_shouldResetShadows_beforeClearingPackageManager.
@Test
public void reset_shouldResetShadows_beforeClearingPackageManager() {
Iterable<ShadowProvider> oldProviders = ReflectionHelpers.getStaticField(Robolectric.class, "providers");
;
ShadowProvider mockProvider = new MockProvider();
List<ShadowProvider> mockProviders = Collections.singletonList(mockProvider);
ReflectionHelpers.setStaticField(Robolectric.class, "providers", mockProviders);
RobolectricPackageManager mockManager = mock(RobolectricPackageManager.class);
doAnswer(new Answer<Void>() {
public Void answer(InvocationOnMock invocation) {
order.add("packageManager");
return null;
}
}).when(mockManager).reset();
RuntimeEnvironment.setRobolectricPackageManager(mockManager);
try {
Robolectric.reset();
} finally {
// Make sure we clean up after ourselves
ReflectionHelpers.setStaticField(Robolectric.class, "providers", oldProviders);
}
assertThat(order).as("reset order").containsExactly("shadowProvider", "packageManager");
assertThat(RuntimeEnvironment.application).as("app after reset").isNull();
assertThat(RuntimeEnvironment.getRobolectricPackageManager()).as("packageManager after reset").isNull();
assertThat(RuntimeEnvironment.getActivityThread()).as("activityThread after reset").isNull();
}
use of org.robolectric.res.builder.RobolectricPackageManager in project glide by bumptech.
the class GlideTest method setUp.
@Before
public void setUp() throws Exception {
Glide.tearDown();
RobolectricPackageManager pm = RuntimeEnvironment.getRobolectricPackageManager();
ApplicationInfo info = pm.getApplicationInfo(RuntimeEnvironment.application.getPackageName(), 0);
info.metaData = new Bundle();
info.metaData.putString(SetupModule.class.getName(), "GlideModule");
// Ensure that target's size ready callback will be called synchronously.
target = mock(Target.class);
imageView = new ImageView(RuntimeEnvironment.application);
imageView.setLayoutParams(new ViewGroup.LayoutParams(100, 100));
doAnswer(new CallSizeReady()).when(target).getSize(isA(SizeReadyCallback.class));
Handler bgHandler = mock(Handler.class);
when(bgHandler.post(isA(Runnable.class))).thenAnswer(new Answer<Boolean>() {
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
Runnable runnable = (Runnable) invocation.getArguments()[0];
runnable.run();
return true;
}
});
Lifecycle lifecycle = mock(Lifecycle.class);
RequestManagerTreeNode treeNode = mock(RequestManagerTreeNode.class);
requestManager = new RequestManager(Glide.get(getContext()), lifecycle, treeNode);
requestManager.resumeRequests();
}
use of org.robolectric.res.builder.RobolectricPackageManager in project materialistic by hidroh.
the class WebFragmentTest method testDownloadPDF.
@Test
public void testDownloadPDF() {
ResolveInfo resolverInfo = new ResolveInfo();
resolverInfo.activityInfo = new ActivityInfo();
resolverInfo.activityInfo.applicationInfo = new ApplicationInfo();
resolverInfo.activityInfo.applicationInfo.packageName = ListActivity.class.getPackage().getName();
resolverInfo.activityInfo.name = ListActivity.class.getName();
RobolectricPackageManager rpm = (RobolectricPackageManager) RuntimeEnvironment.application.getPackageManager();
rpm.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("http://example.com/file.pdf")), resolverInfo);
WebView webView = (WebView) activity.findViewById(R.id.web_view);
ShadowWebView shadowWebView = (ShadowWebView) ShadowExtractor.extract(webView);
shadowWebView.getDownloadListener().onDownloadStart("http://example.com/file.pdf", "", "", "", 0l);
assertThat(activity.findViewById(R.id.empty)).isVisible();
activity.findViewById(R.id.download_button).performClick();
assertNotNull(shadowOf(activity).getNextStartedActivity());
}
use of org.robolectric.res.builder.RobolectricPackageManager in project materialistic by hidroh.
the class TestApplication method addResolver.
public static void addResolver(Intent intent) {
RobolectricPackageManager packageManager = (RobolectricPackageManager) RuntimeEnvironment.application.getPackageManager();
packageManager.addResolveInfoForIntent(intent, ShadowResolveInfo.newResolveInfo("label", "com.android.chrome", "DefaultActivity"));
}
Aggregations