1 /*
2  * Copyright (C) 2020 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 static android.provider.Settings.Secure.NOTIFICATION_BUBBLES;
20 
21 import static com.android.settings.core.BasePreferenceController.AVAILABLE;
22 import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
23 import static com.android.settings.notification.BadgingNotificationPreferenceController.OFF;
24 import static com.android.settings.notification.BadgingNotificationPreferenceController.ON;
25 
26 import static com.google.common.truth.Truth.assertThat;
27 
28 import android.app.ActivityManager;
29 import android.content.Context;
30 import android.provider.Settings;
31 
32 import androidx.preference.Preference;
33 import androidx.test.core.app.ApplicationProvider;
34 
35 import com.android.settings.R;
36 
37 import org.junit.Before;
38 import org.junit.Test;
39 import org.junit.runner.RunWith;
40 import org.robolectric.RobolectricTestRunner;
41 import org.robolectric.annotation.Config;
42 import org.robolectric.shadow.api.Shadow;
43 import org.robolectric.shadows.ShadowActivityManager;
44 
45 @RunWith(RobolectricTestRunner.class)
46 @Config(shadows = {
47         ShadowActivityManager.class,
48 })
49 public class BubbleSummaryNotificationPreferenceControllerTest {
50 
51     private static final String KEY_NOTIFICATION_BUBBLES = "notification_bubbles";
52     private Context mContext;
53 
54     private BubbleSummaryNotificationPreferenceController mController;
55     private Preference mPreference;
56 
57     private ShadowActivityManager mActivityManager;
58 
59 
60     @Before
setUp()61     public void setUp() {
62         mContext = ApplicationProvider.getApplicationContext();
63         mController = new BubbleSummaryNotificationPreferenceController(mContext,
64                 KEY_NOTIFICATION_BUBBLES);
65         mPreference = new Preference(mContext);
66         mActivityManager =
67                 Shadow.extract(mContext.getSystemService(ActivityManager.class));
68     }
69 
70     @Test
getSummary_NOTIFICATION_BUBBLESIsOff_returnOffString()71     public void getSummary_NOTIFICATION_BUBBLESIsOff_returnOffString() {
72         Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, OFF);
73 
74         assertThat(mController.getSummary()).isEqualTo("Off");
75     }
76 
77     @Test
getSummary_NOTIFICATION_BUBBLESIsOff_returnOnString()78     public void getSummary_NOTIFICATION_BUBBLESIsOff_returnOnString() {
79         Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, ON);
80 
81         String onString = mContext.getString(R.string.notifications_bubble_setting_on_summary);
82         assertThat(mController.getSummary()).isEqualTo(onString);
83     }
84 
85     @Test
isAvailable_lowRam_returnsUnsupported()86     public void isAvailable_lowRam_returnsUnsupported() {
87         mActivityManager.setIsLowRamDevice(true);
88         assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
89     }
90 
91     @Test
isAvailable_notLowRam_returnsAvailable()92     public void isAvailable_notLowRam_returnsAvailable() {
93         mActivityManager.setIsLowRamDevice(false);
94         assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
95     }
96 }
97