1 /*
2  * Copyright (C) 2024 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.systemui.volume.domain.startable
18 
19 import android.media.AudioManager
20 import androidx.test.ext.junit.runners.AndroidJUnit4
21 import androidx.test.filters.SmallTest
22 import com.android.internal.logging.uiEventLogger
23 import com.android.internal.logging.uiEventLoggerFake
24 import com.android.systemui.SysuiTestCase
25 import com.android.systemui.kosmos.applicationCoroutineScope
26 import com.android.systemui.kosmos.testScope
27 import com.android.systemui.testKosmos
28 import com.android.systemui.volume.data.repository.audioRepository
29 import com.android.systemui.volume.domain.interactor.audioModeInteractor
30 import com.android.systemui.volume.panel.ui.VolumePanelUiEvent
31 import com.google.common.truth.Truth.assertThat
32 import kotlinx.coroutines.ExperimentalCoroutinesApi
33 import kotlinx.coroutines.test.runCurrent
34 import kotlinx.coroutines.test.runTest
35 import org.junit.Before
36 import org.junit.Rule
37 import org.junit.Test
38 import org.junit.runner.RunWith
39 import org.mockito.junit.MockitoJUnit
40 import org.mockito.junit.MockitoRule
41 
42 @OptIn(ExperimentalCoroutinesApi::class)
43 @RunWith(AndroidJUnit4::class)
44 @SmallTest
45 class AudioModeLoggerStartableTest : SysuiTestCase() {
46     @get:Rule val mockitoRule: MockitoRule = MockitoJUnit.rule()
47 
48     private val kosmos = testKosmos()
49 
50     private lateinit var underTest: AudioModeLoggerStartable
51 
52     @Before
setUpnull53     fun setUp() {
54         with(kosmos) {
55             underTest =
56                 AudioModeLoggerStartable(
57                     applicationCoroutineScope,
58                     uiEventLogger,
59                     audioModeInteractor,
60                 )
61         }
62     }
63 
64     @Test
audioMode_inCallnull65     fun audioMode_inCall() {
66         with(kosmos) {
67             testScope.runTest {
68                 audioRepository.setMode(AudioManager.MODE_IN_CALL)
69 
70                 underTest.start()
71                 runCurrent()
72 
73                 assertThat(uiEventLoggerFake.eventId(0))
74                     .isEqualTo(VolumePanelUiEvent.VOLUME_PANEL_AUDIO_MODE_CHANGE_TO_CALLING.id)
75             }
76         }
77     }
78 
79     @Test
audioMode_notInCallnull80     fun audioMode_notInCall() {
81         with(kosmos) {
82             testScope.runTest {
83                 audioRepository.setMode(AudioManager.MODE_NORMAL)
84 
85                 underTest.start()
86                 runCurrent()
87 
88                 assertThat(uiEventLoggerFake.eventId(0))
89                     .isEqualTo(VolumePanelUiEvent.VOLUME_PANEL_AUDIO_MODE_CHANGE_TO_NORMAL.id)
90             }
91         }
92     }
93 }
94