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.keyguard
18 
19 import android.content.Context
20 import android.testing.AndroidTestingRunner
21 import android.testing.TestableLooper.RunWithLooper
22 import android.util.AttributeSet
23 import androidx.test.filters.SmallTest
24 import com.android.systemui.SysuiTestCase
25 import com.google.common.truth.Truth.assertThat
26 import org.junit.Before
27 import org.junit.Test
28 import org.junit.runner.RunWith
29 import org.mockito.Mockito.spy
30 import org.mockito.Mockito.times
31 import org.mockito.Mockito.verify
32 
33 @SmallTest
34 @RunWith(AndroidTestingRunner::class)
35 @RunWithLooper
36 class BouncerKeyguardMessageAreaTest : SysuiTestCase() {
37     class FakeBouncerKeyguardMessageArea(context: Context, attrs: AttributeSet?) :
38         BouncerKeyguardMessageArea(context, attrs) {
39         override val SHOW_DURATION_MILLIS = 0L
40         override val HIDE_DURATION_MILLIS = 0L
41     }
42     lateinit var underTest: BouncerKeyguardMessageArea
43 
44     @Before
setupnull45     fun setup() {
46         underTest = FakeBouncerKeyguardMessageArea(context, null)
47     }
48 
49     @Test
testSetSameMessagenull50     fun testSetSameMessage() {
51         val underTestSpy = spy(underTest)
52         underTestSpy.setMessage("abc", animate = true)
53         underTestSpy.setMessage("abc", animate = true)
54         verify(underTestSpy, times(1)).text = "abc"
55     }
56 
57     @Test
testSetDifferentMessagenull58     fun testSetDifferentMessage() {
59         underTest.setMessage("abc", animate = true)
60         underTest.setMessage("def", animate = true)
61         assertThat(underTest.text).isEqualTo("def")
62     }
63 
64     @Test
testSetNullMessagenull65     fun testSetNullMessage() {
66         underTest.setMessage(null, animate = true)
67         assertThat(underTest.text).isEqualTo("")
68     }
69 
70     @Test
testSetNullClearsPreviousMessagenull71     fun testSetNullClearsPreviousMessage() {
72         underTest.setMessage("something not null", animate = true)
73         assertThat(underTest.text).isEqualTo("something not null")
74 
75         underTest.setMessage(null, animate = true)
76         assertThat(underTest.text).isEqualTo("")
77     }
78 }
79