1 /*
2  * Copyright (C) 2024 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.datastore
18 
19 import android.tools.Scenario
20 import android.tools.flicker.assertions.BaseAssertionRunner
21 import android.tools.io.Reader
22 import android.tools.io.RunStatus
23 import android.tools.traces.TRACE_CONFIG_REQUIRE_CHANGES
24 import android.tools.withTracing
25 
26 /**
27  * Helper class to run an assertion on a flicker artifact from a [DataStore]
28  *
29  * @param scenario flicker scenario existing in the [DataStore]
30  * @param resultReader helper class to read the flicker artifact
31  */
32 class CachedAssertionRunner(
33     private val scenario: Scenario,
34     resultReader: Reader =
35         android.tools.flicker.datastore.CachedResultReader(scenario, TRACE_CONFIG_REQUIRE_CHANGES),
36 ) : BaseAssertionRunner(resultReader) {
doUpdateStatusnull37     override fun doUpdateStatus(newStatus: RunStatus) {
38         return withTracing("${this::class.simpleName}#doUpdateStatus") {
39             val result = DataStore.getResult(scenario)
40             result.updateStatus(newStatus)
41             DataStore.replaceResult(scenario, result)
42         }
43     }
44 }
45