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 android.content.Context; 20 import android.os.UserManager; 21 22 import com.android.settings.SettingsRobolectricTestRunner; 23 import com.android.settings.TestConfig; 24 import com.android.settings.testutils.XmlTestUtils; 25 import com.android.settings.testutils.shadow.ShadowUserManager; 26 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 java.util.List; 33 34 import static com.google.common.truth.Truth.assertThat; 35 import static org.mockito.Mockito.doReturn; 36 import static org.mockito.Mockito.mock; 37 import static org.mockito.Mockito.spy; 38 import static org.mockito.Mockito.when; 39 40 @RunWith(SettingsRobolectricTestRunner.class) 41 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, 42 shadows = { 43 ShadowUserManager.class 44 }) 45 public class SystemDashboardFragmentTest { 46 47 @Test testNonIndexableKeys_existInXmlLayout()48 public void testNonIndexableKeys_existInXmlLayout() { 49 final Context context = spy(RuntimeEnvironment.application); 50 UserManager manager = mock(UserManager.class); 51 when(manager.isAdminUser()).thenReturn(false); 52 doReturn(manager).when(context).getSystemService(Context.USER_SERVICE); 53 final List<String> niks = SystemDashboardFragment.SEARCH_INDEX_DATA_PROVIDER 54 .getNonIndexableKeys(context); 55 final int xmlId = (new SystemDashboardFragment()).getPreferenceScreenResId(); 56 57 final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(context, xmlId); 58 59 assertThat(keys).containsAllIn(niks); 60 } 61 } 62