ActivityWithContextMenu extends Activity { @Override public void onAttachFragment(android.app.Fragment fragment) { super.onAttachFragment(fragment); fragments.add(new WeakReference(fragment)); }  @Override void registerForContextMenu(final View view); @Override void onAttachFragment(android.app.Fragment fragment); @Override void unregisterForContextMenu(View view);  }
@Test public void shouldRememberAttachedFragments() { Fragment fragment = new Fragment(); activityWithContextMenu.onAttachFragment(fragment); assertThat(activityWithContextMenu.fragments).hasSize(1); Object rememberedFragment = activityWithContextMenu.fragments.get(0).get(); assertThat(rememberedFragment).isEqualTo(fragment); }