1 /*
2  * Copyright 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 androidx.glance.testing
18 
19 import androidx.annotation.RestrictTo
20 import androidx.annotation.RestrictTo.Scope
21 
22 /**
23  * A wrapper for Glance composable node under test.
24  *
25  * @param T A representation of Glance composable node (e.g. MappedNode) on which assertions can be
26  *   performed
27  * @param value an object of the representation of the Glance composable node
28  */
29 abstract class GlanceNode<T> @RestrictTo(Scope.LIBRARY_GROUP) constructor(val value: T) {
30     /** Returns children of current glance node. */
childrennull31     abstract fun children(): List<GlanceNode<T>>
32 
33     /**
34      * Returns the Glance node as string that can be presented in error messages helping developer
35      * debug the assertion error.
36      */
37     abstract fun toDebugString(): String
38 
39     override fun equals(other: Any?): Boolean {
40         if (this === other) return true
41         if (other !is GlanceNode<*>) return false
42         return value == other.value
43     }
44 
hashCodenull45     override fun hashCode(): Int {
46         val result = value.hashCode()
47         return 31 * result
48     }
49 
toStringnull50     override fun toString(): String {
51         return ("GlanceNode{value='$value}'")
52     }
53 }
54