1 package com.android.settings; 2 3 import android.content.Context; 4 import com.android.settings.core.PreferenceController; 5 import com.android.settings.testutils.XmlTestUtils; 6 import org.junit.Test; 7 import org.junit.runner.RunWith; 8 import org.robolectric.RuntimeEnvironment; 9 import org.robolectric.annotation.Config; 10 11 import java.util.ArrayList; 12 import java.util.List; 13 14 import static com.google.common.truth.Truth.assertThat; 15 16 @RunWith(SettingsRobolectricTestRunner.class) 17 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) 18 public class DisplaySettingsTest { 19 20 @Test 21 public void testPreferenceControllers_getPreferenceKeys_existInPreferenceScreen() { 22 final Context context = RuntimeEnvironment.application; 23 final DisplaySettings fragment = new DisplaySettings(); 24 final List<String> preferenceScreenKeys = XmlTestUtils.getKeysFromPreferenceXml(context, 25 fragment.getPreferenceScreenResId()); 26 final List<String> preferenceKeys = new ArrayList<>(); 27 28 for (PreferenceController controller : fragment.getPreferenceControllers(context)) { 29 preferenceKeys.add(controller.getPreferenceKey()); 30 } 31 // Nightmode is currently hidden 32 preferenceKeys.remove("night_mode"); 33 34 assertThat(preferenceScreenKeys).containsAllIn(preferenceKeys); 35 } 36 } 37