1 /* 2 * Copyright (C) 2023 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.keyguard 17 18 import android.animation.Animator 19 import android.testing.AndroidTestingRunner 20 import android.transition.TransitionValues 21 import android.view.View 22 import android.view.ViewGroup 23 import androidx.test.filters.SmallTest 24 import com.android.keyguard.KeyguardStatusViewController.SplitShadeTransitionAdapter 25 import com.android.systemui.SysuiTestCase 26 import com.android.systemui.util.mockito.mock 27 import com.google.common.truth.Truth.assertThat 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.MockitoAnnotations 33 34 @SmallTest 35 @RunWith(AndroidTestingRunner::class) 36 class SplitShadeTransitionAdapterTest : SysuiTestCase() { 37 38 @Mock private lateinit var KeyguardClockSwitchController: KeyguardClockSwitchController 39 40 private lateinit var adapter: SplitShadeTransitionAdapter 41 42 @Before 43 fun setUp() { 44 MockitoAnnotations.initMocks(this) 45 adapter = SplitShadeTransitionAdapter(KeyguardClockSwitchController) 46 } 47 48 @Test 49 fun createAnimator_nullStartValues_returnsNull() { 50 val endValues = createEndValues() 51 52 val animator = adapter.createAnimator(startValues = null, endValues = endValues) 53 54 assertThat(animator).isNull() 55 } 56 57 @Test 58 fun createAnimator_nullEndValues_returnsNull() { 59 val animator = adapter.createAnimator(startValues = createStartValues(), endValues = null) 60 61 assertThat(animator).isNull() 62 } 63 64 @Test 65 fun createAnimator_nonNullStartAndEndValues_returnsAnimator() { 66 val animator = 67 adapter.createAnimator(startValues = createStartValues(), endValues = createEndValues()) 68 69 assertThat(animator).isNotNull() 70 } 71 72 private fun createStartValues() = 73 TransitionValues().also { values -> 74 values.view = View(context) 75 adapter.captureStartValues(values) 76 } 77 78 private fun createEndValues() = 79 TransitionValues().also { values -> 80 values.view = View(context) 81 adapter.captureEndValues(values) 82 } 83 } 84 85 private fun SplitShadeTransitionAdapter.createAnimator( 86 startValues: TransitionValues?, 87 endValues: TransitionValues? 88 ): Animator? { 89 return createAnimator(/* sceneRoot= */ mock(), startValues, endValues) 90 } 91