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 
17 package android.tools.flicker.assertors.assertions
18 
19 import android.tools.flicker.assertors.AssertionTemplate
20 import android.tools.flicker.assertors.ComponentTemplate
21 
22 /** Base class for tests that require a [components] named window name */
23 abstract class AssertionTemplateWithComponent(vararg val components: ComponentTemplate) :
24     AssertionTemplate() {
25 
<lambda>null26     override val name = "${super.name}(${components.joinToString { it.name }})"
27 
28     override fun equals(other: Any?): Boolean {
29         if (other !is AssertionTemplateWithComponent) {
30             return false
31         }
32 
33         // Check both assertions are instances of the same class.
34         if (this::class != other::class) {
35             return false
36         }
37 
38         if (components.size != other.components.size) {
39             return false
40         }
41 
42         // TODO: Make sure equality is properly defined on the component
43         // Order of components matters
44         return components.zip(other.components).all { it.first == it.second }
45     }
46 
hashCodenull47     override fun hashCode(): Int {
48         var result = super.hashCode()
49         result = 31 * result + components.hashCode()
50         return result
51     }
52 }
53