1 /*
2  * Copyright (C) 2020 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.qs
18 
19 import android.content.Context
20 import android.testing.AndroidTestingRunner
21 import androidx.test.filters.SmallTest
22 import com.android.systemui.SysuiTestCase
23 import org.junit.After
24 import org.junit.Before
25 import org.junit.Test
26 import org.junit.runner.RunWith
27 import org.mockito.Answers
28 import org.mockito.Mock
29 import org.mockito.Mockito.`when`
30 import org.mockito.Mockito.verify
31 import org.mockito.MockitoAnnotations
32 
33 @SmallTest
34 @RunWith(AndroidTestingRunner::class)
35 class QuickStatusBarHeaderControllerTest : SysuiTestCase() {
36 
37     @Mock
38     private lateinit var view: QuickStatusBarHeader
39     @Mock
40     private lateinit var quickQSPanelController: QuickQSPanelController
41 
42     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
43     private lateinit var context: Context
44 
45     private lateinit var controller: QuickStatusBarHeaderController
46 
47     @Before
48     fun setUp() {
49         MockitoAnnotations.initMocks(this)
50         `when`(view.resources).thenReturn(mContext.resources)
51         `when`(view.isAttachedToWindow).thenReturn(true)
52         `when`(view.context).thenReturn(context)
53 
54         controller = QuickStatusBarHeaderController(view, quickQSPanelController)
55     }
56 
57     @After
58     fun tearDown() {
59         controller.onViewDetached()
60     }
61 
62     @Test
63     fun testListeningStatus() {
64         controller.setListening(true)
65         verify(quickQSPanelController).setListening(true)
66 
67         controller.setListening(false)
68         verify(quickQSPanelController).setListening(false)
69     }
70 }
71