BacklightSwitch extends AppCompatImageButton { AlertDialog writePermissionRequestDialog() { val resources = getResources(); return new AlertDialog.Builder(getContext()) .setTitle(resources.getString(R.string.write_permissions_request_title)) .setMessage(resources.getString(R.string.write_permissions_request_message)) .setNeutralButton(resources.getString(R.string.ok_button), (d, w) -> settings.requestWritePermission()) .create(); } BacklightSwitch(final Context context, final AttributeSet attrs);   }
@Test public void showsNotificationDialogWhenLauncherDoesNotHaveWritePermissionsToSystemSettings() { val backlightSwitch = givenDefaultBacklightSwitch(); val settings = givenSystemSettingsWithoutPermissions(); val controller = new BacklightSwitch.BacklightController(settings, backlightSwitch); controller.onClick(mock(View.class)); then(backlightSwitch.writePermissionRequestDialog()).should().show(); }