From 49f40ee77b4d29b6f4cdb0cb99ebcb5fe0901585 Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Thu, 12 Mar 2020 17:27:35 -0400 Subject: [PATCH] Fix tests Fixing one of them by removing an unneeded setting Test: RunSettingsRoboTests2 Fixes: 151279674 Change-Id: If2b513ba7b4bf8ec5183e2a9457caab3d3e06dc4 --- res/xml/conversation_list_settings.xml | 5 - res/xml/zen_mode_settings.xml | 1 - ...onversationBubblePreferenceController.java | 71 --------- ...rsationBubblePreferenceControllerTest.java | 140 ------------------ 4 files changed, 217 deletions(-) delete mode 100644 src/com/android/settings/notification/app/ImportantConversationBubblePreferenceController.java delete mode 100644 tests/robotests/src/com/android/settings/notification/app/ImportantConversationBubblePreferenceControllerTest.java diff --git a/res/xml/conversation_list_settings.xml b/res/xml/conversation_list_settings.xml index 1d6b13cb079..5b9f0c4a09f 100644 --- a/res/xml/conversation_list_settings.xml +++ b/res/xml/conversation_list_settings.xml @@ -27,11 +27,6 @@ - diff --git a/src/com/android/settings/notification/app/ImportantConversationBubblePreferenceController.java b/src/com/android/settings/notification/app/ImportantConversationBubblePreferenceController.java deleted file mode 100644 index f6f14aa1ed8..00000000000 --- a/src/com/android/settings/notification/app/ImportantConversationBubblePreferenceController.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.settings.notification.app; - -import static android.provider.Settings.Global.NOTIFICATION_BUBBLES; -import static android.provider.Settings.Secure.BUBBLE_IMPORTANT_CONVERSATIONS; - -import android.content.Context; -import android.provider.Settings; - -import androidx.annotation.VisibleForTesting; -import androidx.preference.Preference; - -import com.android.settings.core.PreferenceControllerMixin; -import com.android.settings.core.TogglePreferenceController; - -public class ImportantConversationBubblePreferenceController extends TogglePreferenceController - implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener { - - private static final String TAG = "ImpConvBubPrefContr"; - @VisibleForTesting - static final int ON = 1; - @VisibleForTesting - static final int OFF = 0; - - - public ImportantConversationBubblePreferenceController(Context context, String preferenceKey) { - super(context, preferenceKey); - } - - private boolean isGloballyEnabled() { - return Settings.Global.getInt(mContext.getContentResolver(), - NOTIFICATION_BUBBLES, OFF) == ON; - } - - @Override - public int getAvailabilityStatus() { - return isGloballyEnabled() ? AVAILABLE : DISABLED_DEPENDENT_SETTING; - } - - @Override - public boolean isSliceable() { - return false; - } - - @Override - public boolean isChecked() { - return Settings.Secure.getInt(mContext.getContentResolver(), - BUBBLE_IMPORTANT_CONVERSATIONS, ON) == ON; - } - - @Override - public boolean setChecked(boolean isChecked) { - return Settings.Secure.putInt(mContext.getContentResolver(), - BUBBLE_IMPORTANT_CONVERSATIONS, isChecked ? ON : OFF); - } -} diff --git a/tests/robotests/src/com/android/settings/notification/app/ImportantConversationBubblePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/ImportantConversationBubblePreferenceControllerTest.java deleted file mode 100644 index c99e0953726..00000000000 --- a/tests/robotests/src/com/android/settings/notification/app/ImportantConversationBubblePreferenceControllerTest.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (C) 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.settings.notification.app; - -import static android.provider.Settings.Global.NOTIFICATION_BUBBLES; -import static android.provider.Settings.Secure.BUBBLE_IMPORTANT_CONVERSATIONS; - -import static com.android.settings.core.BasePreferenceController.AVAILABLE; -import static com.android.settings.core.BasePreferenceController.DISABLED_DEPENDENT_SETTING; -import static com.android.settings.notification.app.ImportantConversationBubblePreferenceController.OFF; -import static com.android.settings.notification.app.ImportantConversationBubblePreferenceController.ON; - -import static com.google.common.truth.Truth.assertThat; - -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import android.content.Context; -import android.provider.Settings; - -import androidx.preference.PreferenceScreen; -import androidx.preference.TwoStatePreference; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Answers; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.robolectric.RobolectricTestRunner; - -@RunWith(RobolectricTestRunner.class) -public class ImportantConversationBubblePreferenceControllerTest { - - @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private Context mContext; - @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private PreferenceScreen mScreen; - - private ImportantConversationBubblePreferenceController mController; - @Mock - private TwoStatePreference mPreference; - - private static final String KEY = "important_bubble"; - - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - mController = new ImportantConversationBubblePreferenceController(mContext, KEY); - when(mPreference.getKey()).thenReturn(mController.getPreferenceKey()); - when(mScreen.findPreference(mPreference.getKey())).thenReturn(mPreference); - } - - @Test - public void testGetAvailabilityStatus_globallyOn() { - Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, ON); - - assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE); - } - - @Test - public void testGetAvailabilityStatus_globallyOff() { - Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, OFF); - - assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING); - } - - @Test - public void updateState_preferenceSetCheckedWhenSettingIsOn() { - Settings.Secure.putInt(mContext.getContentResolver(), BUBBLE_IMPORTANT_CONVERSATIONS, ON); - - mController.updateState(mPreference); - - verify(mPreference).setChecked(true); - } - - @Test - public void updateState_preferenceSetUncheckedWhenSettingIsOff() { - Settings.Secure.putInt(mContext.getContentResolver(), BUBBLE_IMPORTANT_CONVERSATIONS, OFF); - - mController.updateState(mPreference); - - verify(mPreference).setChecked(false); - } - - @Test - public void isChecked_settingIsOff_shouldReturnFalse() { - Settings.Secure.putInt(mContext.getContentResolver(), BUBBLE_IMPORTANT_CONVERSATIONS, OFF); - - assertThat(mController.isChecked()).isFalse(); - } - - @Test - public void isChecked_settingIsOn_shouldReturnTrue() { - Settings.Secure.putInt(mContext.getContentResolver(), BUBBLE_IMPORTANT_CONVERSATIONS, ON); - - assertThat(mController.isChecked()).isTrue(); - } - - @Test - public void setChecked_setFalse_disablesSetting() { - Settings.Secure.putInt(mContext.getContentResolver(), BUBBLE_IMPORTANT_CONVERSATIONS, ON); - - mController.setChecked(false); - int updatedValue = Settings.Secure.getInt(mContext.getContentResolver(), - BUBBLE_IMPORTANT_CONVERSATIONS, -1); - - assertThat(updatedValue).isEqualTo(OFF); - } - - @Test - public void setChecked_setTrue_enablesSetting() { - Settings.Secure.putInt(mContext.getContentResolver(), BUBBLE_IMPORTANT_CONVERSATIONS, OFF); - - mController.setChecked(true); - int updatedValue = Settings.Secure.getInt(mContext.getContentResolver(), - BUBBLE_IMPORTANT_CONVERSATIONS, -1); - - assertThat(updatedValue).isEqualTo(ON); - } - - @Test - public void isSliceable_returnsFalse() { - assertThat(mController.isSliceable()).isFalse(); - } -}