ActionBarFragment extends BaseFragment { @Override protected boolean onBackPress() { return finishActionMode() || super.onBackPress(); }  @Override void onCreate(@Nullable final Bundle savedInstanceState); @Override void onCreateOptionsMenu(@NonNull final Menu menu, @NonNull final MenuInflater inflater); @Override void onActivityCreated(@Nullable final Bundle savedInstanceState); void invalidateActionBar();  }
@Test public void testOnBackPress() { final ActionMode mockActionMode = mock(ActionMode.class); final ActionBarFragment fragment = new TestFragment(); fragment.onActionModeStarted(mockActionMode); assertThat(fragment.onBackPress(), is(true)); verify(mockActionMode).finish(); verifyNoMoreInteractions(mockActionMode); }
@Test public void testOnBackPressWithoutStartedActionMode() { final TestFragment fragment = new TestFragment(); assertThat(fragment.onBackPress(), is(false)); }