ActionBarFragment extends BaseFragment { public void invalidateActionBar() { if (actionBarDelegate != null && annotationHandler != null) { final ActionBarFragmentAnnotationHandler annotationHandler = (ActionBarFragmentAnnotationHandler) this.annotationHandler; annotationHandler.configureActionBar(actionBarDelegate); if (annotationHandler.hasOptionsMenu()) { setHasOptionsMenu(true); } } }  @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 testInvalidateActionBar() { final ActionBarFragment fragment = new TestFragment(); final ActionBarDelegate mockActionBarDelegate = mock(ActionBarDelegate.class); fragment.actionBarDelegate = mockActionBarDelegate; fragment.invalidateActionBar(); verify(mockActionBarDelegate).setIcon(TestFragment.ICON_RESOURCE); verify(mockActionBarDelegate).setTitle(TestFragment.TITLE_RESOURCE); verifyNoMoreInteractions(mockActionBarDelegate); }
@Test public void testInvalidateActionBarForFragmentWithoutMenu() { final ActionBarFragment fragment = new TestFragmentWithoutAnnotation(); final ActionBarDelegate mockActionBarDelegate = mock(ActionBarDelegate.class); fragment.actionBarDelegate = mockActionBarDelegate; fragment.invalidateActionBar(); verifyZeroInteractions(mockActionBarDelegate); }
@Test public void testInvalidateActionBarWhenNotAttached() { final TestFragment fragment = new TestFragment(); fragment.invalidateActionBar(); }
@Test public void testInvalidateActionBarWhenAnnotationsAreDisabled() { FragmentAnnotations.setEnabled(false); final ActionBarFragment fragment = new TestFragment(); fragment.activityDelegate = mock(ActivityDelegate.class); fragment.invalidateActionBar(); }