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.junit 18 19 import android.app.Instrumentation 20 import androidx.test.platform.app.InstrumentationRegistry 21 import org.junit.runners.model.FrameworkMethod 22 import org.junit.runners.model.TestClass 23 24 abstract class AbstractFlickerRunnerDecorator( 25 protected val testClass: TestClass, 26 protected val inner: IFlickerJUnitDecorator?, 27 protected val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation() 28 ) : IFlickerJUnitDecorator { doValidateConstructornull29 override fun doValidateConstructor(): List<Throwable> { 30 val errors = mutableListOf<Throwable>() 31 inner?.doValidateConstructor()?.let { errors.addAll(it) } 32 return errors 33 } 34 doValidateInstanceMethodsnull35 override fun doValidateInstanceMethods(): List<Throwable> { 36 val errors = mutableListOf<Throwable>() 37 inner?.doValidateInstanceMethods()?.let { errors.addAll(it) } 38 return errors 39 } 40 shouldRunBeforeOnnull41 override fun shouldRunBeforeOn(method: FrameworkMethod): Boolean { 42 return inner?.shouldRunBeforeOn(method) ?: true 43 } 44 shouldRunAfterOnnull45 override fun shouldRunAfterOn(method: FrameworkMethod): Boolean { 46 return inner?.shouldRunAfterOn(method) ?: true 47 } 48 } 49