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