ActionBarDelegate { @Nullable public static ActionBarDelegate create(@NonNull final Activity activity) { if (activity instanceof AppCompatActivity) { final androidx.appcompat.app.ActionBar actionBar = ((AppCompatActivity) activity).getSupportActionBar(); return actionBar == null ? null : create(activity, actionBar); } final ActionBar actionBar = activity.getActionBar(); return actionBar == null ? null : create(activity, actionBar); } protected  ActionBarDelegate(@NonNull final Context context); @Nullable static ActionBarDelegate create(@NonNull final Activity activity); @NonNull static ActionBarDelegate create(@NonNull final Context context, @Nullable final ActionBar actionBar); @NonNull static ActionBarDelegate create(@NonNull final Context context, @Nullable final androidx.appcompat.app.ActionBar actionBar); abstract void setDisplayHomeAsUpEnabled(boolean enabled); abstract void setHomeAsUpIndicator(@DrawableRes int resId); abstract void setHomeAsUpVectorIndicator(@DrawableRes int resId); abstract void setHomeAsUpIndicator(@Nullable Drawable indicator); abstract void setIcon(@DrawableRes int resId); abstract void setIcon(@Nullable Drawable icon); abstract void setTitle(@StringRes int resId); abstract void setTitle(@Nullable CharSequence title);  }
@Test public void testCreateForFrameworkActivityWithoutActionBar() { final Activity mockActivity = mock(TestActivity.class); when(mockActivity.getActionBar()).thenReturn(null); assertThat(ActionBarDelegate.create(mockActivity), is(nullValue())); }
@SuppressWarnings("ConstantConditions") @Test public void testCreateForCompatActivityWithoutActionBar() { final AppCompatActivity mockActivity = mock(TestCompatActivity.class); when(mockActivity.getSupportActionBar()).thenReturn(null); assertThat(ActionBarDelegate.create(mockActivity), is(nullValue())); }
@Test public void testCreateForNullActionBar() { assertThat(ActionBarDelegate.create(context, (ActionBar) null), is(notNullValue())); assertThat(ActionBarDelegate.create(context, (androidx.appcompat.app.ActionBar) null), is(notNullValue())); }