ActivityWithContextMenu extends Activity { @Override public void registerForContextMenu(final View view) { view.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { menuResId = ActivityWithContextMenu.this.getContextMenuResId(view); verifyMenuResId(); dialogWithBlurredBackgroundLauncher.showDialog(createDialog()); return true; } }); }  @Override void registerForContextMenu(final View view); @Override void onAttachFragment(android.app.Fragment fragment); @Override void unregisterForContextMenu(View view);  }
@Test public void shouldLaunchDialogWhenLongClickOnViewRegisteredForContextMenu() { TextView view = new TextView(RuntimeEnvironment.application.getBaseContext()); activityWithContextMenu.registerForContextMenu(view); view.performLongClick(); verify(dialogWithBlurredBackgroundLauncher) .showDialog(any(Dialog.class)); }