Home | History | Annotate | Download | only in notification
      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.notification;
     18 
     19 import android.content.Context;
     20 
     21 import android.media.AudioManager;
     22 import android.os.UserManager;
     23 import com.android.settings.R;
     24 import com.android.settings.SettingsRobolectricTestRunner;
     25 import com.android.settings.TestConfig;
     26 import com.android.settings.testutils.XmlTestUtils;
     27 import com.android.settings.testutils.shadow.ShadowAudioHelper;
     28 import com.android.settings.testutils.shadow.ShadowUserManager;
     29 import org.junit.Test;
     30 import org.junit.runner.RunWith;
     31 import org.robolectric.RuntimeEnvironment;
     32 import org.robolectric.annotation.Config;
     33 
     34 import java.util.List;
     35 
     36 import static com.google.common.truth.Truth.assertThat;
     37 import static org.mockito.Mockito.doReturn;
     38 import static org.mockito.Mockito.mock;
     39 import static org.mockito.Mockito.spy;
     40 import static org.mockito.Mockito.when;
     41 
     42 @RunWith(SettingsRobolectricTestRunner.class)
     43 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
     44 public class SoundSettingsTest {
     45 
     46     @Test
     47     @Config( shadows = {
     48             ShadowUserManager.class,
     49             ShadowAudioHelper.class,
     50     })
     51     public void testNonIndexableKeys_existInXmlLayout() {
     52         final Context context = spy(RuntimeEnvironment.application);
     53         AudioManager audioManager = mock(AudioManager.class);
     54         doReturn(audioManager).when(context).getSystemService(Context.AUDIO_SERVICE);
     55 
     56         UserManager userManager = mock(UserManager.class);
     57         when(userManager.isAdminUser()).thenReturn(false);
     58         doReturn(userManager).when(context).getSystemService(Context.USER_SERVICE);
     59 
     60         final List<String> niks = SoundSettings.SEARCH_INDEX_DATA_PROVIDER
     61                 .getNonIndexableKeys(context);
     62         final int xmlId = (new SoundSettings()).getPreferenceScreenResId();
     63         final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(context, xmlId);
     64         keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(context,
     65                 R.xml.zen_mode_settings));
     66         // Add keys with hidden resources
     67         keys.add("alarm_volume");
     68         keys.add("ring_volume");
     69         keys.add("notification_volume");
     70 
     71         assertThat(keys).containsAllIn(niks);
     72     }
     73 }