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.notification;
18 
19 import static com.android.settings.core.BasePreferenceController.AVAILABLE;
20 import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
21 
22 import static com.google.common.truth.Truth.assertThat;
23 
24 import static org.mockito.Mockito.spy;
25 import static org.mockito.Mockito.when;
26 
27 import android.content.Context;
28 import android.media.AudioManager;
29 import android.media.Spatializer;
30 
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.Mock;
35 import org.mockito.MockitoAnnotations;
36 import org.robolectric.RobolectricTestRunner;
37 import org.robolectric.RuntimeEnvironment;
38 
39 @RunWith(RobolectricTestRunner.class)
40 public class SpatialAudioParentPreferenceControllerTest {
41 
42     private static final String KEY = "spatial_audio_summary";
43 
44     @Mock
45     private Context mContext;
46     @Mock
47     private AudioManager mAudioManager;
48     @Mock
49     private Spatializer mSpatializer;
50 
51     private SpatialAudioParentPreferenceController mController;
52 
53     @Before
setUp()54     public void setUp() {
55         MockitoAnnotations.initMocks(this);
56         mContext = spy(RuntimeEnvironment.application);
57         when(mContext.getSystemService(AudioManager.class)).thenReturn(mAudioManager);
58         when(mAudioManager.getSpatializer()).thenReturn(mSpatializer);
59         mController = new SpatialAudioParentPreferenceController(mContext, KEY);
60     }
61 
62     @Test
getAvailabilityStatus_levelNone_shouldReturnUnsupported()63     public void getAvailabilityStatus_levelNone_shouldReturnUnsupported() {
64         when(mSpatializer.getImmersiveAudioLevel()).thenReturn(
65                 Spatializer.SPATIALIZER_IMMERSIVE_LEVEL_NONE);
66 
67         assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
68     }
69 
70     @Test
getAvailabilityStatus_levelMultiChannel_shouldReturnAvailable()71     public void getAvailabilityStatus_levelMultiChannel_shouldReturnAvailable() {
72         when(mSpatializer.getImmersiveAudioLevel()).thenReturn(
73                 Spatializer.SPATIALIZER_IMMERSIVE_LEVEL_MULTICHANNEL);
74 
75         assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
76     }
77 }
78