1 /* 2 * Copyright (C) 2022 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.statusbar.notification.row 18 19 import android.testing.AndroidTestingRunner 20 import android.testing.TestableLooper.RunWithLooper 21 import android.testing.ViewUtils 22 import android.view.LayoutInflater 23 import android.view.View 24 import androidx.test.filters.SmallTest 25 import com.android.systemui.R 26 import com.android.systemui.SysuiTestCase 27 import org.junit.After 28 import org.junit.Before 29 import org.junit.Test 30 import org.junit.runner.RunWith 31 import org.mockito.Mock 32 import org.mockito.Mockito.verify 33 import org.mockito.Mockito.`when` as whenever 34 import org.mockito.MockitoAnnotations 35 36 @SmallTest 37 @RunWith(AndroidTestingRunner::class) 38 @RunWithLooper 39 class NotificationGutsTest : SysuiTestCase() { 40 41 private lateinit var guts: NotificationGuts 42 private lateinit var gutsContentView: View 43 44 @Mock 45 private lateinit var gutsContent: NotificationGuts.GutsContent 46 47 @Mock 48 private lateinit var gutsClosedListener: NotificationGuts.OnGutsClosedListener 49 50 @Before 51 fun setUp() { 52 MockitoAnnotations.initMocks(this) 53 54 val layoutInflater = LayoutInflater.from(mContext) 55 guts = layoutInflater.inflate(R.layout.notification_guts, null) as NotificationGuts 56 gutsContentView = View(mContext) 57 58 whenever(gutsContent.contentView).thenReturn(gutsContentView) 59 60 ViewUtils.attachView(guts) 61 } 62 63 @After 64 fun tearDown() { 65 ViewUtils.detachView(guts) 66 } 67 68 @Test 69 fun setGutsContent() { 70 guts.gutsContent = gutsContent 71 72 verify(gutsContent).setGutsParent(guts) 73 } 74 75 @Test 76 fun openControls() { 77 guts.gutsContent = gutsContent 78 79 guts.openControls(0, 0, false, null) 80 } 81 82 @Test 83 fun closeControlsWithSave() { 84 guts.gutsContent = gutsContent 85 guts.setClosedListener(gutsClosedListener) 86 87 guts.closeControls(gutsContentView, true) 88 89 verify(gutsContent).handleCloseControls(true, false) 90 verify(gutsClosedListener).onGutsClosed(guts) 91 } 92 93 @Test 94 fun closeControlsWithoutSave() { 95 guts.gutsContent = gutsContent 96 guts.setClosedListener(gutsClosedListener) 97 98 guts.closeControls(gutsContentView, false) 99 100 verify(gutsContent).handleCloseControls(false, false) 101 verify(gutsClosedListener).onGutsClosed(guts) 102 } 103 } 104