• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settings.notification;
18 
19 import android.app.NotificationManager;
20 import android.content.Context;
21 
22 import com.android.settings.R;
23 import com.android.settings.testutils.SettingsRobolectricTestRunner;
24 import com.android.settings.TestConfig;
25 
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.robolectric.RuntimeEnvironment;
30 import org.robolectric.annotation.Config;
31 
32 import static com.google.common.truth.Truth.assertThat;
33 
34 import static junit.framework.Assert.assertTrue;
35 
36 @RunWith(SettingsRobolectricTestRunner.class)
37 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
38 public class ZenModeSettingsTest {
39 
40     private ZenModeSettings.SummaryBuilder mBuilder;
41     private Context mContext;
42 
43     @Before
setUp()44     public void setUp() {
45         mContext = RuntimeEnvironment.application.getApplicationContext();
46         mBuilder = new ZenModeSettings.SummaryBuilder(mContext);
47     }
48 
49     @Test
testAppend_conditionFalse_shouldNotAppend()50     public void testAppend_conditionFalse_shouldNotAppend() {
51         String original = "test";
52 
53         final String result = mBuilder.append(original, false, R.string.zen_mode_alarms);
54 
55         assertThat(result).isEqualTo(original);
56     }
57 
58     @Test
testAppend_conditionTrue_shouldAppend()59     public void testAppend_conditionTrue_shouldAppend() {
60         String original = "test";
61         String alarm = mContext.getString(R.string.zen_mode_alarms);
62 
63         final String result = mBuilder.append(original, true, R.string.zen_mode_alarms);
64 
65         assertThat(result).contains(alarm);
66         assertThat(result).contains(original);
67         assertTrue(result.indexOf(original) < result.indexOf(alarm));
68     }
69 
70     @Test
71     public void testPrepend() {
72         String original = mContext.getString(R.string.zen_mode_alarms);
73         String reminders = mContext.getString(R.string.zen_mode_reminders);
74 
75         final String result = mBuilder.prepend(original, true, R.string.zen_mode_reminders);
76         assertThat(result).contains(original);
77         assertThat(result).contains(reminders);
78         assertTrue(result.indexOf(reminders) < result.indexOf(original));
79     }
80 
81     @Test
82     public void testGetPrioritySettingSummary_sameOrderAsTargetPage() {
83         NotificationManager.Policy policy = new NotificationManager.Policy(
84                 NotificationManager.Policy.PRIORITY_CATEGORY_EVENTS
85                         | NotificationManager.Policy.PRIORITY_CATEGORY_REMINDERS,
86                 0, 0);
87         final String result = mBuilder.getPrioritySettingSummary(policy);
88 
89         String alarms = mContext.getString(R.string.zen_mode_alarms);
90         String reminders = mContext.getString(R.string.zen_mode_reminders);
91         String events = mContext.getString(R.string.zen_mode_events);
92 
93         assertThat(result).contains(alarms);
94         assertThat(result).contains(reminders);
95         assertThat(result).contains(events);
96         assertTrue(result.indexOf(reminders) < result.indexOf(events) &&
97                 result.indexOf(events) < result.indexOf(alarms));
98     }
99 
100 }
101