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 package com.android.systemui.shade 17 18 import android.testing.AndroidTestingRunner 19 import androidx.constraintlayout.widget.ConstraintSet 20 import androidx.test.filters.SmallTest 21 import com.android.systemui.SysuiTestCase 22 import com.android.systemui.util.mockito.mock 23 import com.google.common.truth.Truth.assertThat 24 import org.junit.Test 25 import org.junit.runner.RunWith 26 import org.mockito.Mockito.inOrder 27 28 @SmallTest 29 @RunWith(AndroidTestingRunner::class) 30 class ConstraintChangesTest : SysuiTestCase() { 31 32 @Test 33 fun testSumWithoutNulls() { 34 val mockQQS1: ConstraintChange = mock() 35 val mockQS1: ConstraintChange = mock() 36 val mockLS1: ConstraintChange = mock() 37 val mockQQS2: ConstraintChange = mock() 38 val mockQS2: ConstraintChange = mock() 39 val mockLS2: ConstraintChange = mock() 40 41 val changes1 = ConstraintsChanges(mockQQS1, mockQS1, mockLS1) 42 val changes2 = ConstraintsChanges(mockQQS2, mockQS2, mockLS2) 43 44 val sum = changes1 + changes2 45 46 val constraintSet = ConstraintSet() 47 sum.qqsConstraintsChanges?.invoke(constraintSet) 48 sum.qsConstraintsChanges?.invoke(constraintSet) 49 sum.largeScreenConstraintsChanges?.invoke(constraintSet) 50 51 val inOrder = inOrder(mockQQS1, mockQS1, mockLS1, mockQQS2, mockQS2, mockLS2) 52 53 inOrder.verify(mockQQS1).invoke(constraintSet) 54 inOrder.verify(mockQQS2).invoke(constraintSet) 55 inOrder.verify(mockQS1).invoke(constraintSet) 56 inOrder.verify(mockQS2).invoke(constraintSet) 57 inOrder.verify(mockLS1).invoke(constraintSet) 58 inOrder.verify(mockLS2).invoke(constraintSet) 59 } 60 61 @Test 62 fun testSumWithSomeNulls() { 63 val mockQQS: ConstraintChange = mock() 64 val mockQS: ConstraintChange = mock() 65 66 val changes1 = ConstraintsChanges(mockQQS, null, null) 67 val changes2 = ConstraintsChanges(null, mockQS, null) 68 69 val sum = changes1 + changes2 70 71 assertThat(sum.qqsConstraintsChanges).isSameInstanceAs(mockQQS) 72 assertThat(sum.qsConstraintsChanges).isSameInstanceAs(mockQS) 73 assertThat(sum.largeScreenConstraintsChanges).isNull() 74 } 75 } 76