Use the prebuilt manual DND mode from TestModeBuilder in tests
Instead of unnecessarily creating them by hand. This also allows restricting the visibility of the ZenMode constructors (which should only be instantiated by ZenModesBackend in production code). Bug: 360817586 Test: atest com.android.settings.notification.modes Flag: android.app.modes_ui Change-Id: Id5a232a5a0ffc7bc09652fc4b6e6dd2a6383a2ae
This commit is contained in:
@@ -18,11 +18,9 @@ package com.android.settings.notification.modes;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.app.AutomaticZenRule;
|
|
||||||
import android.app.Flags;
|
import android.app.Flags;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
|
||||||
import android.platform.test.annotations.EnableFlags;
|
import android.platform.test.annotations.EnableFlags;
|
||||||
import android.platform.test.flag.junit.SetFlagsRule;
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
@@ -31,7 +29,6 @@ import androidx.fragment.app.Fragment;
|
|||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.settingslib.notification.modes.TestModeBuilder;
|
import com.android.settingslib.notification.modes.TestModeBuilder;
|
||||||
import com.android.settingslib.notification.modes.ZenMode;
|
|
||||||
import com.android.settingslib.notification.modes.ZenModesBackend;
|
import com.android.settingslib.notification.modes.ZenModesBackend;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -73,10 +70,8 @@ public class ManualDurationPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testIsAvailable_onlyForManualDnd() {
|
public void testIsAvailable_onlyForManualDnd() {
|
||||||
assertThat(mPrefController.isAvailable(TestModeBuilder.EXAMPLE)).isFalse();
|
assertThat(mPrefController.isAvailable(TestModeBuilder.EXAMPLE)).isFalse();
|
||||||
|
assertThat(mPrefController.isAvailable(TestModeBuilder.MANUAL_DND_ACTIVE)).isTrue();
|
||||||
ZenMode manualDnd = ZenMode.manualDndMode(
|
assertThat(mPrefController.isAvailable(TestModeBuilder.MANUAL_DND_INACTIVE)).isTrue();
|
||||||
new AutomaticZenRule.Builder("id", Uri.EMPTY).build(), false);
|
|
||||||
assertThat(mPrefController.isAvailable(manualDnd)).isTrue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -23,11 +23,9 @@ import static org.mockito.Mockito.mock;
|
|||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.app.AutomaticZenRule;
|
|
||||||
import android.app.Flags;
|
import android.app.Flags;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
|
||||||
import android.platform.test.annotations.EnableFlags;
|
import android.platform.test.annotations.EnableFlags;
|
||||||
import android.platform.test.flag.junit.SetFlagsRule;
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
@@ -192,8 +190,7 @@ public final class ZenModeButtonPreferenceControllerTest {
|
|||||||
Button button = new Button(mContext);
|
Button button = new Button(mContext);
|
||||||
LayoutPreference pref = mock(LayoutPreference.class);
|
LayoutPreference pref = mock(LayoutPreference.class);
|
||||||
when(pref.findViewById(anyInt())).thenReturn(button);
|
when(pref.findViewById(anyInt())).thenReturn(button);
|
||||||
ZenMode zenMode = ZenMode.manualDndMode(
|
ZenMode zenMode = TestModeBuilder.MANUAL_DND_INACTIVE;
|
||||||
new AutomaticZenRule.Builder("manual", Uri.EMPTY).build(), false);
|
|
||||||
|
|
||||||
mController.updateZenMode(pref, zenMode);
|
mController.updateZenMode(pref, zenMode);
|
||||||
button.callOnClick();
|
button.callOnClick();
|
||||||
@@ -207,8 +204,7 @@ public final class ZenModeButtonPreferenceControllerTest {
|
|||||||
Button button = new Button(mContext);
|
Button button = new Button(mContext);
|
||||||
LayoutPreference pref = mock(LayoutPreference.class);
|
LayoutPreference pref = mock(LayoutPreference.class);
|
||||||
when(pref.findViewById(anyInt())).thenReturn(button);
|
when(pref.findViewById(anyInt())).thenReturn(button);
|
||||||
ZenMode zenMode = ZenMode.manualDndMode(
|
ZenMode zenMode = TestModeBuilder.MANUAL_DND_INACTIVE;
|
||||||
new AutomaticZenRule.Builder("manual", Uri.EMPTY).build(), false);
|
|
||||||
|
|
||||||
mController.updateZenMode(pref, zenMode);
|
mController.updateZenMode(pref, zenMode);
|
||||||
button.callOnClick();
|
button.callOnClick();
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ package com.android.settings.notification.modes;
|
|||||||
import static android.app.AutomaticZenRule.TYPE_OTHER;
|
import static android.app.AutomaticZenRule.TYPE_OTHER;
|
||||||
import static android.app.AutomaticZenRule.TYPE_SCHEDULE_CALENDAR;
|
import static android.app.AutomaticZenRule.TYPE_SCHEDULE_CALENDAR;
|
||||||
import static android.app.AutomaticZenRule.TYPE_SCHEDULE_TIME;
|
import static android.app.AutomaticZenRule.TYPE_SCHEDULE_TIME;
|
||||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
|
||||||
import static android.platform.test.flag.junit.SetFlagsRule.DefaultInitValueType.DEVICE_DEFAULT;
|
import static android.platform.test.flag.junit.SetFlagsRule.DefaultInitValueType.DEVICE_DEFAULT;
|
||||||
|
|
||||||
import static com.android.settings.notification.modes.CharSequenceTruth.assertThat;
|
import static com.android.settings.notification.modes.CharSequenceTruth.assertThat;
|
||||||
@@ -28,7 +27,6 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
|
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
import android.app.AutomaticZenRule;
|
|
||||||
import android.app.Flags;
|
import android.app.Flags;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
@@ -125,12 +123,7 @@ public class ZenModeTriggerAddPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAvailable_manualDND_false() {
|
public void isAvailable_manualDND_false() {
|
||||||
ZenMode manualMode = ZenMode.manualDndMode(new AutomaticZenRule.Builder("Do Not Disturb",
|
mController.setZenMode(TestModeBuilder.MANUAL_DND_INACTIVE);
|
||||||
Uri.parse("manual"))
|
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.build(), /* isActive= */ false);
|
|
||||||
|
|
||||||
mController.setZenMode(manualMode);
|
|
||||||
assertThat(mController.isAvailable()).isFalse();
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,15 +18,12 @@ package com.android.settings.notification.modes;
|
|||||||
|
|
||||||
import static android.app.AutomaticZenRule.TYPE_OTHER;
|
import static android.app.AutomaticZenRule.TYPE_OTHER;
|
||||||
import static android.app.AutomaticZenRule.TYPE_SCHEDULE_CALENDAR;
|
import static android.app.AutomaticZenRule.TYPE_SCHEDULE_CALENDAR;
|
||||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
|
||||||
import static android.platform.test.flag.junit.SetFlagsRule.DefaultInitValueType.DEVICE_DEFAULT;
|
import static android.platform.test.flag.junit.SetFlagsRule.DefaultInitValueType.DEVICE_DEFAULT;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.app.AutomaticZenRule;
|
|
||||||
import android.app.Flags;
|
import android.app.Flags;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
|
||||||
import android.platform.test.annotations.EnableFlags;
|
import android.platform.test.annotations.EnableFlags;
|
||||||
import android.platform.test.flag.junit.SetFlagsRule;
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
import android.service.notification.SystemZenRules;
|
import android.service.notification.SystemZenRules;
|
||||||
@@ -116,12 +113,7 @@ public class ZenModeTriggerCategoryPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAvailable_manualDND_false() {
|
public void isAvailable_manualDND_false() {
|
||||||
ZenMode manualMode = ZenMode.manualDndMode(new AutomaticZenRule.Builder("Do Not Disturb",
|
mController.setZenMode(TestModeBuilder.MANUAL_DND_INACTIVE);
|
||||||
Uri.parse("manual"))
|
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.build(), /* isActive= */ false);
|
|
||||||
|
|
||||||
mController.setZenMode(manualMode);
|
|
||||||
assertThat(mController.isAvailable()).isFalse();
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ package com.android.settings.notification.modes;
|
|||||||
import static android.app.AutomaticZenRule.TYPE_OTHER;
|
import static android.app.AutomaticZenRule.TYPE_OTHER;
|
||||||
import static android.app.AutomaticZenRule.TYPE_SCHEDULE_CALENDAR;
|
import static android.app.AutomaticZenRule.TYPE_SCHEDULE_CALENDAR;
|
||||||
import static android.app.AutomaticZenRule.TYPE_SCHEDULE_TIME;
|
import static android.app.AutomaticZenRule.TYPE_SCHEDULE_TIME;
|
||||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
|
||||||
import static android.platform.test.flag.junit.SetFlagsRule.DefaultInitValueType.DEVICE_DEFAULT;
|
import static android.platform.test.flag.junit.SetFlagsRule.DefaultInitValueType.DEVICE_DEFAULT;
|
||||||
|
|
||||||
import static com.android.settings.notification.modes.CharSequenceTruth.assertThat;
|
import static com.android.settings.notification.modes.CharSequenceTruth.assertThat;
|
||||||
@@ -35,13 +34,11 @@ import static org.mockito.Mockito.when;
|
|||||||
import static org.robolectric.Shadows.shadowOf;
|
import static org.robolectric.Shadows.shadowOf;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.AutomaticZenRule;
|
|
||||||
import android.app.Flags;
|
import android.app.Flags;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.platform.test.annotations.EnableFlags;
|
import android.platform.test.annotations.EnableFlags;
|
||||||
import android.platform.test.flag.junit.SetFlagsRule;
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
@@ -149,12 +146,7 @@ public class ZenModeTriggerUpdatePreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAvailable_manualDND_false() {
|
public void isAvailable_manualDND_false() {
|
||||||
ZenMode manualMode = ZenMode.manualDndMode(new AutomaticZenRule.Builder("Do Not Disturb",
|
mController.setZenMode(TestModeBuilder.MANUAL_DND_INACTIVE);
|
||||||
Uri.parse("manual"))
|
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.build(), /* isActive= */ false);
|
|
||||||
|
|
||||||
mController.setZenMode(manualMode);
|
|
||||||
assertThat(mController.isAvailable()).isFalse();
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ package com.android.settings.notification.modes;
|
|||||||
|
|
||||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
||||||
|
|
||||||
|
import static com.android.settingslib.notification.modes.TestModeBuilder.MANUAL_DND_INACTIVE;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@@ -71,13 +73,6 @@ public class ZenModesListPreferenceControllerTest {
|
|||||||
.build())
|
.build())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
private static final ZenMode TEST_MANUAL_MODE = ZenMode.manualDndMode(
|
|
||||||
new AutomaticZenRule.Builder("Do Not Disturb", Uri.EMPTY)
|
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowAllSounds().build())
|
|
||||||
.build(),
|
|
||||||
false);
|
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(
|
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(
|
||||||
SetFlagsRule.DefaultInitValueType.DEVICE_DEFAULT);
|
SetFlagsRule.DefaultInitValueType.DEVICE_DEFAULT);
|
||||||
@@ -152,7 +147,7 @@ public class ZenModesListPreferenceControllerTest {
|
|||||||
@DisableFlags(Flags.FLAG_MODES_UI)
|
@DisableFlags(Flags.FLAG_MODES_UI)
|
||||||
public void testModesUiOff_notAvailableAndNoSearchData() {
|
public void testModesUiOff_notAvailableAndNoSearchData() {
|
||||||
// There exist modes
|
// There exist modes
|
||||||
when(mBackend.getModes()).thenReturn(List.of(TEST_MANUAL_MODE, TEST_MODE));
|
when(mBackend.getModes()).thenReturn(List.of(MANUAL_DND_INACTIVE, TEST_MODE));
|
||||||
|
|
||||||
assertThat(mPrefController.isAvailable()).isFalse();
|
assertThat(mPrefController.isAvailable()).isFalse();
|
||||||
List<SearchIndexableRaw> data = new ArrayList<>();
|
List<SearchIndexableRaw> data = new ArrayList<>();
|
||||||
@@ -187,20 +182,20 @@ public class ZenModesListPreferenceControllerTest {
|
|||||||
|
|
||||||
// Changing mode data so there's a different one mode doesn't keep any previous data
|
// Changing mode data so there's a different one mode doesn't keep any previous data
|
||||||
// (and setting that state up in the caller)
|
// (and setting that state up in the caller)
|
||||||
when(mBackend.getModes()).thenReturn(List.of(TEST_MANUAL_MODE));
|
when(mBackend.getModes()).thenReturn(List.of(MANUAL_DND_INACTIVE));
|
||||||
List<SearchIndexableRaw> newData = new ArrayList<>();
|
List<SearchIndexableRaw> newData = new ArrayList<>();
|
||||||
mPrefController.updateDynamicRawDataToIndex(newData);
|
mPrefController.updateDynamicRawDataToIndex(newData);
|
||||||
assertThat(newData).hasSize(1);
|
assertThat(newData).hasSize(1);
|
||||||
|
|
||||||
SearchIndexableRaw newItem = newData.get(0);
|
SearchIndexableRaw newItem = newData.get(0);
|
||||||
assertThat(newItem.key).isEqualTo(TEST_MANUAL_MODE.getId());
|
assertThat(newItem.key).isEqualTo(MANUAL_DND_INACTIVE.getId());
|
||||||
assertThat(newItem.title).isEqualTo("Do Not Disturb"); // set above
|
assertThat(newItem.title).isEqualTo("Do Not Disturb"); // set above
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@EnableFlags(Flags.FLAG_MODES_UI)
|
@EnableFlags(Flags.FLAG_MODES_UI)
|
||||||
public void testUpdateDynamicRawDataToIndex_multipleModes() {
|
public void testUpdateDynamicRawDataToIndex_multipleModes() {
|
||||||
when(mBackend.getModes()).thenReturn(List.of(TEST_MANUAL_MODE, TEST_MODE));
|
when(mBackend.getModes()).thenReturn(List.of(MANUAL_DND_INACTIVE, TEST_MODE));
|
||||||
|
|
||||||
List<SearchIndexableRaw> data = new ArrayList<>();
|
List<SearchIndexableRaw> data = new ArrayList<>();
|
||||||
mPrefController.updateDynamicRawDataToIndex(data);
|
mPrefController.updateDynamicRawDataToIndex(data);
|
||||||
@@ -208,7 +203,7 @@ public class ZenModesListPreferenceControllerTest {
|
|||||||
|
|
||||||
// Should keep the order presented by getModes()
|
// Should keep the order presented by getModes()
|
||||||
SearchIndexableRaw item0 = data.get(0);
|
SearchIndexableRaw item0 = data.get(0);
|
||||||
assertThat(item0.key).isEqualTo(TEST_MANUAL_MODE.getId());
|
assertThat(item0.key).isEqualTo(MANUAL_DND_INACTIVE.getId());
|
||||||
assertThat(item0.title).isEqualTo("Do Not Disturb"); // set above
|
assertThat(item0.title).isEqualTo("Do Not Disturb"); // set above
|
||||||
|
|
||||||
SearchIndexableRaw item1 = data.get(1);
|
SearchIndexableRaw item1 = data.get(1);
|
||||||
|
|||||||
Reference in New Issue
Block a user