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 package com.android.systemui.statusbar.notification.collection.coordinator
17 
18 import android.testing.TestableLooper.RunWithLooper
19 import androidx.test.ext.junit.runners.AndroidJUnit4
20 import androidx.test.filters.SmallTest
21 import com.android.systemui.SysuiTestCase
22 import com.android.systemui.statusbar.notification.AssistantFeedbackController
23 import com.android.systemui.statusbar.notification.FeedbackIcon
24 import com.android.systemui.statusbar.notification.collection.NotifPipeline
25 import com.android.systemui.statusbar.notification.collection.NotificationEntry
26 import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder
27 import com.android.systemui.statusbar.notification.collection.listbuilder.NotifSection
28 import com.android.systemui.statusbar.notification.collection.listbuilder.OnAfterRenderEntryListener
29 import com.android.systemui.statusbar.notification.collection.listbuilder.OnBeforeRenderListListener
30 import com.android.systemui.statusbar.notification.collection.provider.SectionStyleProvider
31 import com.android.systemui.statusbar.notification.collection.render.NotifRowController
32 import com.android.systemui.util.mockito.any
33 import com.android.systemui.util.mockito.eq
34 import com.android.systemui.util.mockito.withArgCaptor
35 import org.junit.Before
36 import org.junit.Test
37 import org.junit.runner.RunWith
38 import org.mockito.Mock
39 import org.mockito.Mockito.verify
40 import org.mockito.Mockito.`when` as whenever
41 import org.mockito.MockitoAnnotations.initMocks
42 
43 @SmallTest
44 @RunWith(AndroidJUnit4::class)
45 @RunWithLooper
46 class RowAppearanceCoordinatorTest : SysuiTestCase() {
47     private lateinit var coordinator: RowAppearanceCoordinator
48     private lateinit var beforeRenderListListener: OnBeforeRenderListListener
49     private lateinit var afterRenderEntryListener: OnAfterRenderEntryListener
50 
51     private lateinit var entry1: NotificationEntry
52     private lateinit var entry2: NotificationEntry
53 
54     @Mock private lateinit var pipeline: NotifPipeline
55     @Mock private lateinit var assistantFeedbackController: AssistantFeedbackController
56     @Mock private lateinit var sectionStyleProvider: SectionStyleProvider
57 
58     @Mock private lateinit var section1: NotifSection
59     @Mock private lateinit var section2: NotifSection
60     @Mock private lateinit var controller1: NotifRowController
61     @Mock private lateinit var controller2: NotifRowController
62 
63     @Before
setUpnull64     fun setUp() {
65         initMocks(this)
66         coordinator = RowAppearanceCoordinator(
67             mContext,
68             assistantFeedbackController,
69             sectionStyleProvider
70         )
71         coordinator.attach(pipeline)
72         beforeRenderListListener = withArgCaptor {
73             verify(pipeline).addOnBeforeRenderListListener(capture())
74         }
75         afterRenderEntryListener = withArgCaptor {
76             verify(pipeline).addOnAfterRenderEntryListener(capture())
77         }
78         whenever(assistantFeedbackController.getFeedbackIcon(any())).thenReturn(FeedbackIcon(1, 2))
79         entry1 = NotificationEntryBuilder().setSection(section1).build()
80         entry2 = NotificationEntryBuilder().setSection(section2).build()
81     }
82 
83     @Test
testSetSystemExpandedOnlyOnFirstnull84     fun testSetSystemExpandedOnlyOnFirst() {
85         whenever(sectionStyleProvider.isMinimizedSection(eq(section1))).thenReturn(false)
86         whenever(sectionStyleProvider.isMinimizedSection(eq(section1))).thenReturn(false)
87         beforeRenderListListener.onBeforeRenderList(listOf(entry1, entry2))
88         afterRenderEntryListener.onAfterRenderEntry(entry1, controller1)
89         verify(controller1).setSystemExpanded(eq(true))
90         afterRenderEntryListener.onAfterRenderEntry(entry2, controller2)
91         verify(controller2).setSystemExpanded(eq(false))
92     }
93 
94     @Test
testSetSystemExpandedNeverIfMinimizednull95     fun testSetSystemExpandedNeverIfMinimized() {
96         whenever(sectionStyleProvider.isMinimizedSection(eq(section1))).thenReturn(true)
97         whenever(sectionStyleProvider.isMinimizedSection(eq(section1))).thenReturn(true)
98         beforeRenderListListener.onBeforeRenderList(listOf(entry1, entry2))
99         afterRenderEntryListener.onAfterRenderEntry(entry1, controller1)
100         verify(controller1).setSystemExpanded(eq(false))
101         afterRenderEntryListener.onAfterRenderEntry(entry2, controller2)
102         verify(controller2).setSystemExpanded(eq(false))
103     }
104 
105     @Test
testSetFeedbackIconnull106     fun testSetFeedbackIcon() {
107         afterRenderEntryListener.onAfterRenderEntry(entry1, controller1)
108         verify(controller1).setFeedbackIcon(eq(FeedbackIcon(1, 2)))
109     }
110 }
111