• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.applications;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 import static org.mockito.Mockito.mock;
21 import static org.mockito.Mockito.spy;
22 import static org.mockito.Mockito.when;
23 
24 import android.content.Context;
25 import android.os.UserManager;
26 
27 import com.android.settings.notification.EmergencyBroadcastPreferenceController;
28 import com.android.settings.testutils.SettingsRobolectricTestRunner;
29 import com.android.settings.testutils.XmlTestUtils;
30 
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.robolectric.RuntimeEnvironment;
34 import org.robolectric.annotation.Config;
35 import org.robolectric.annotation.Implementation;
36 import org.robolectric.annotation.Implements;
37 
38 import java.util.List;
39 
40 @RunWith(SettingsRobolectricTestRunner.class)
41 public class AppAndNotificationDashboardFragmentTest {
42 
43     @Test
44     @Config(shadows = {ShadowEmergencyBroadcastPreferenceController.class})
testNonIndexableKeys_existInXmlLayout()45     public void testNonIndexableKeys_existInXmlLayout() {
46         final Context context = spy(RuntimeEnvironment.application);
47         UserManager manager = mock(UserManager.class);
48         when(manager.isAdminUser()).thenReturn(true);
49         when(context.getSystemService(Context.USER_SERVICE)).thenReturn(manager);
50         final List<String> niks = AppAndNotificationDashboardFragment.SEARCH_INDEX_DATA_PROVIDER
51                 .getNonIndexableKeys(context);
52         AppAndNotificationDashboardFragment fragment = new AppAndNotificationDashboardFragment();
53         final int xmlId = fragment.getPreferenceScreenResId();
54 
55         final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(context, xmlId);
56 
57         assertThat(keys).containsAllIn(niks);
58     }
59 
60     @Implements(EmergencyBroadcastPreferenceController.class)
61     public static class ShadowEmergencyBroadcastPreferenceController {
62 
63         @Implementation
isAvailable()64         public boolean isAvailable() {
65             return true;
66         }
67     }
68 }
69