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