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 package com.android.bedstead.harrier; 17 18 import androidx.annotation.NonNull; 19 20 import com.android.bedstead.nene.utils.FailureDumper; 21 22 import java.lang.annotation.Annotation; 23 24 /** 25 * Interface used to register a new class which can execute Harrier annotations. 26 * <p> 27 * This can be used to add additional harrier-compatible annotations without modifying harrier 28 */ 29 // This is written in Java because Kotlin interfaces can't expose default methods to Java 30 public interface AnnotationExecutor extends FailureDumper, DeviceStateComponent { 31 /** 32 * Called when an annotation should be applied. 33 * 34 * <p>This should take care of recording any state necessary to correctly restore state after 35 * the test. 36 * Annotations that don't need the context of device state components 37 * could be handled by extension functions like: {@link AnnotationLogicExtensionsKt} 38 */ applyAnnotation(@onNull Annotation annotation)39 void applyAnnotation(@NonNull Annotation annotation); 40 41 /** 42 * Called when a test has failed which used this annotation executor. 43 */ onTestFailed(@onNull Throwable exception)44 default void onTestFailed(@NonNull Throwable exception) {} 45 } 46