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.system;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import static org.mockito.Mockito.spy;
22 import static org.mockito.Mockito.when;
23 
24 import android.content.Context;
25 
26 import com.android.settings.testutils.XmlTestUtils;
27 import com.android.settings.testutils.shadow.SettingsShadowResources;
28 import com.android.settings.testutils.shadow.ShadowUserManager;
29 
30 import org.junit.After;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.robolectric.RobolectricTestRunner;
35 import org.robolectric.RuntimeEnvironment;
36 import org.robolectric.annotation.Config;
37 
38 import java.util.List;
39 
40 @RunWith(RobolectricTestRunner.class)
41 @Config(shadows = {SettingsShadowResources.class, ShadowUserManager.class})
42 public class SystemDashboardFragmentTest {
43 
44     private Context mContext;
45     private SystemDashboardFragment mFragment;
46 
47     @Before
setup()48     public void setup() {
49         SettingsShadowResources.overrideResource(
50                 com.android.internal.R.bool.config_supportSystemNavigationKeys, true);
51         ShadowUserManager.getShadow().setIsAdminUser(true);
52         mContext = RuntimeEnvironment.application;
53         mFragment = spy(new SystemDashboardFragment());
54         when(mFragment.getContext()).thenReturn(mContext);
55     }
56 
57     @After
tearDown()58     public void tearDown() {
59         SettingsShadowResources.reset();
60     }
61 
62     @Test
testNonIndexableKeys_existInXmlLayout()63     public void testNonIndexableKeys_existInXmlLayout() {
64         final List<String> niks = SystemDashboardFragment.SEARCH_INDEX_DATA_PROVIDER
65                 .getNonIndexableKeys(mContext);
66         final int xmlId = (new SystemDashboardFragment()).getPreferenceScreenResId();
67 
68         final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(mContext, xmlId);
69 
70         assertThat(keys).containsAtLeastElementsIn(niks);
71     }
72 }
73