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.assertions
18 
19 import android.tools.Tag
20 import android.tools.flicker.subject.FlickerSubject
21 import kotlin.reflect.KClass
22 
23 /**
24  * Helper class to create assertions to execute on a state
25  *
26  * @param stateSubject Type of subject used for state assertions
27  */
28 open class AssertionStateDataFactory(private val stateSubject: KClass<out FlickerSubject>) {
29     /**
30      * Creates an [assertion] to be executed on the initial state of a trace
31      *
32      * @param assertion Assertion predicate
33      */
createStartStateAssertionnull34     fun createStartStateAssertion(assertion: FlickerSubject.() -> Unit) =
35         AssertionDataImpl(
36             tag = Tag.START,
37             expectedSubjectClass = stateSubject,
38             assertion = assertion
39         )
40 
41     /**
42      * Creates an [assertion] to be executed on the final state of a trace
43      *
44      * @param assertion Assertion predicate
45      */
46     fun createEndStateAssertion(assertion: FlickerSubject.() -> Unit) =
47         AssertionDataImpl(tag = Tag.END, expectedSubjectClass = stateSubject, assertion = assertion)
48 
49     /**
50      * Creates an [assertion] to be executed on a user defined moment ([tag]) of a trace
51      *
52      * @param assertion Assertion predicate
53      */
54     fun createTagAssertion(tag: String, assertion: FlickerSubject.() -> Unit) =
55         AssertionDataImpl(tag = tag, expectedSubjectClass = stateSubject, assertion = assertion)
56 }
57