• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 com.android.interactive;
18 
19 import static com.android.bedstead.harrier.AnnotationExecutorUtil.checkFailOrSkip;
20 
21 import com.android.bedstead.harrier.AnnotationExecutor;
22 import com.android.bedstead.harrier.annotations.FailureMode;
23 
24 import java.lang.annotation.Annotation;
25 
26 /**
27  * Implementation of {@link AnnotationExecutor} for use with Interactive.
28  */
29 public final class InteractiveAnnotationExecutor implements AnnotationExecutor {
30 
31     @Override
applyAnnotation(Annotation annotation)32     public void applyAnnotation(Annotation annotation) {
33         if (annotation instanceof RequireBooleanStepResult) {
34             RequireBooleanStepResult requireBooleanStepResultAnnotation =
35                     (RequireBooleanStepResult) annotation;
36             requireBooleanStepResult(requireBooleanStepResultAnnotation.step(),
37                     requireBooleanStepResultAnnotation.expectedResult(),
38                     requireBooleanStepResultAnnotation.reason(),
39                     requireBooleanStepResultAnnotation.failureMode());
40         }
41     }
42 
43     @Override
teardownShareableState()44     public void teardownShareableState() {
45 
46     }
47 
48     @Override
teardownNonShareableState()49     public void teardownNonShareableState() {
50 
51     }
52 
requireBooleanStepResult( Class<? extends Step<Boolean>> stepClass, boolean expectedResult, String reason, FailureMode failureMode)53     private void requireBooleanStepResult(
54             Class<? extends Step<Boolean>> stepClass,
55             boolean expectedResult, String reason, FailureMode failureMode) {
56         boolean result = false;
57         try {
58             result = Step.execute(stepClass);
59         } catch (Exception e) {
60             throw new RuntimeException("Error executing step " + stepClass, e);
61         }
62 
63         checkFailOrSkip(reason, result == expectedResult, failureMode);
64     }
65 }
66