1 /* 2 * Copyright (C) 2021 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 21 import android.content.Context; 22 23 import com.android.settings.testutils.XmlTestUtils; 24 import com.android.settings.testutils.shadow.ShadowUserManager; 25 import com.android.settingslib.core.AbstractPreferenceController; 26 import com.android.settingslib.drawer.CategoryKey; 27 28 import org.junit.Before; 29 import org.junit.Test; 30 import org.junit.runner.RunWith; 31 import org.robolectric.RobolectricTestRunner; 32 import org.robolectric.RuntimeEnvironment; 33 import org.robolectric.annotation.Config; 34 35 import java.util.ArrayList; 36 import java.util.List; 37 38 @RunWith(RobolectricTestRunner.class) 39 public class AppDashboardFragmentTest { 40 41 private Context mContext; 42 private AppDashboardFragment mFragment; 43 44 @Before setUp()45 public void setUp() { 46 mContext = RuntimeEnvironment.application; 47 mFragment = new AppDashboardFragment(); 48 } 49 50 @Test testCategory_isApps()51 public void testCategory_isApps() { 52 assertThat(mFragment.getCategoryKey()).isEqualTo(CategoryKey.CATEGORY_APPS); 53 } 54 55 @Test 56 @Config(shadows = ShadowUserManager.class) testPreferenceControllers_existInPreferenceScreen()57 public void testPreferenceControllers_existInPreferenceScreen() { 58 final List<String> preferenceScreenKeys = XmlTestUtils.getKeysFromPreferenceXml(mContext, 59 mFragment.getPreferenceScreenResId()); 60 final List<String> preferenceKeys = new ArrayList<>(); 61 62 for (AbstractPreferenceController controller : mFragment.createPreferenceControllers( 63 mContext)) { 64 preferenceKeys.add(controller.getPreferenceKey()); 65 } 66 67 assertThat(preferenceScreenKeys).containsAtLeastElementsIn(preferenceKeys); 68 } 69 } 70