1 /*
2  * Copyright (C) 2023 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.notetask
18 
19 import android.content.Intent
20 import android.graphics.drawable.Icon
21 import android.os.UserHandle
22 import androidx.test.filters.SmallTest
23 import androidx.test.runner.AndroidJUnit4
24 import com.android.systemui.R
25 import com.android.systemui.SysuiTestCase
26 import com.android.systemui.notetask.NoteTaskBubblesController.NoteTaskBubblesService
27 import com.android.wm.shell.bubbles.Bubbles
28 import com.google.common.truth.Truth.assertThat
29 import java.util.Optional
30 import org.junit.Before
31 import org.junit.Test
32 import org.junit.runner.RunWith
33 import org.mockito.Mock
34 import org.mockito.Mockito.verify
35 import org.mockito.MockitoAnnotations
36 
37 /** atest SystemUITests:NoteTaskBubblesServiceTest */
38 @SmallTest
39 @RunWith(AndroidJUnit4::class)
40 internal class NoteTaskBubblesServiceTest : SysuiTestCase() {
41 
42     @Mock private lateinit var bubbles: Bubbles
43 
44     private fun createServiceBinder(bubbles: Bubbles? = this.bubbles) =
45         NoteTaskBubblesService(Optional.ofNullable(bubbles)).onBind(Intent())
46             as INoteTaskBubblesService
47 
48     @Before
49     fun setUp() {
50         MockitoAnnotations.initMocks(this)
51     }
52 
53     @Test
54     fun areBubblesAvailable_bubblesNotNull_shouldReturnTrue() {
55         assertThat(createServiceBinder().areBubblesAvailable()).isTrue()
56     }
57 
58     @Test
59     fun areBubblesAvailable_bubblesNull_shouldReturnFalse() {
60         assertThat(createServiceBinder(bubbles = null).areBubblesAvailable()).isFalse()
61     }
62 
63     @Test
64     fun showOrHideAppBubble() {
65         val intent = Intent()
66         val user = UserHandle.SYSTEM
67         val icon = Icon.createWithResource(context, R.drawable.ic_note_task_shortcut_widget)
68 
69         createServiceBinder().showOrHideAppBubble(intent, user, icon)
70 
71         verify(bubbles).showOrHideAppBubble(intent, user, icon)
72     }
73 }
74