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.shadow 18 19 import android.content.Context 20 import android.content.res.Resources 21 import android.content.res.TypedArray 22 import android.testing.AndroidTestingRunner 23 import android.util.AttributeSet 24 import androidx.test.filters.SmallTest 25 import com.android.systemui.R 26 import com.android.systemui.SysuiTestCase 27 import com.android.systemui.shared.shadow.DoubleShadowTextClock 28 import com.android.systemui.util.mockito.whenever 29 import junit.framework.Assert.assertTrue 30 import org.junit.Before 31 import org.junit.Rule 32 import org.junit.Test 33 import org.junit.runner.RunWith 34 import org.mockito.Mock 35 import org.mockito.MockitoAnnotations 36 import org.mockito.junit.MockitoJUnit 37 import org.mockito.junit.MockitoRule 38 39 @SmallTest 40 @RunWith(AndroidTestingRunner::class) 41 class DoubleShadowTextClockTest : SysuiTestCase() { 42 @get:Rule val mockito: MockitoRule = MockitoJUnit.rule() 43 44 @Mock lateinit var resources: Resources 45 46 @Mock lateinit var attributes: TypedArray 47 48 private lateinit var context: Context 49 private var attrs: AttributeSet? = null 50 51 @Before 52 fun setup() { 53 MockitoAnnotations.initMocks(this) 54 context = getContext() 55 whenever(attributes.getBoolean(R.styleable.DoubleShadowTextClock_removeTextDescent, false)) 56 .thenReturn(true) 57 } 58 59 @Test 60 fun testAddingPaddingToBottomOfClockWhenConfigIsTrue() { 61 whenever(resources.getBoolean(R.bool.dream_overlay_complication_clock_bottom_padding)) 62 .thenReturn(true) 63 64 val doubleShadowTextClock = 65 DoubleShadowTextClock( 66 resources = resources, 67 context = context, 68 attrs = attrs, 69 attributesInput = attributes 70 ) 71 assertTrue(doubleShadowTextClock.paddingBottom > 0) 72 } 73 74 @Test 75 fun testRemovingPaddingToBottomOfClockWhenConfigIsFalse() { 76 whenever(resources.getBoolean(R.bool.dream_overlay_complication_clock_bottom_padding)) 77 .thenReturn(false) 78 79 val doubleShadowTextClock = 80 DoubleShadowTextClock( 81 resources = resources, 82 context = context, 83 attrs = attrs, 84 attributesInput = attributes 85 ) 86 assertTrue(doubleShadowTextClock.paddingBottom < 0) 87 } 88 } 89