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 package com.android.adservices.shared.meta_testing;
17 
18 import com.android.adservices.shared.testing.AndroidSdk;
19 import com.android.adservices.shared.testing.AndroidSdk.Level;
20 import com.android.adservices.shared.testing.AndroidSdk.Range;
21 import com.android.adservices.shared.testing.ScreenSize;
22 import com.android.adservices.shared.testing.annotations.RequiresGoDevice;
23 import com.android.adservices.shared.testing.annotations.RequiresLowRamDevice;
24 import com.android.adservices.shared.testing.annotations.RequiresScreenSizeDevice;
25 import com.android.adservices.shared.testing.annotations.RequiresSdkLevelAtLeastR;
26 import com.android.adservices.shared.testing.annotations.RequiresSdkLevelAtLeastS;
27 import com.android.adservices.shared.testing.annotations.RequiresSdkLevelAtLeastS2;
28 import com.android.adservices.shared.testing.annotations.RequiresSdkLevelAtLeastT;
29 import com.android.adservices.shared.testing.annotations.RequiresSdkLevelAtLeastU;
30 import com.android.adservices.shared.testing.annotations.RequiresSdkRange;
31 
32 import com.google.auto.value.AutoAnnotation;
33 
34 import java.lang.annotation.Annotation;
35 
36 /** Provides {@code auto-value-annotation}s for annotations used on test cases. */
37 public final class TestAnnotations {
38 
TestAnnotations()39     private TestAnnotations() {
40         throw new UnsupportedOperationException("provides only static methods");
41     }
42 
43     /** Gets a new annotation for the given level and reason. */
newAnnotationForAtLeast(Level level, String reason)44     public static Annotation newAnnotationForAtLeast(Level level, String reason) {
45         switch (level) {
46             case R:
47                 return sdkLevelAtLeastR(reason);
48             case S:
49                 return sdkLevelAtLeastS(reason);
50             case S2:
51                 return sdkLevelAtLeastS2(reason);
52             case T:
53                 return sdkLevelAtLeastT(reason);
54             case U:
55                 return sdkLevelAtLeastU(reason);
56             default:
57                 throw new UnsupportedOperationException(level.toString());
58         }
59     }
60 
61     /** Redundant javadoc to make checkstyle happy */
62     @AutoAnnotation
sdkLevelAtLeastR(String reason)63     public static RequiresSdkLevelAtLeastR sdkLevelAtLeastR(String reason) {
64         return new AutoAnnotation_TestAnnotations_sdkLevelAtLeastR(reason);
65     }
66 
67     /** Redundant javadoc to make checkstyle happy */
68     @AutoAnnotation
sdkLevelAtLeastS(String reason)69     public static RequiresSdkLevelAtLeastS sdkLevelAtLeastS(String reason) {
70         return new AutoAnnotation_TestAnnotations_sdkLevelAtLeastS(reason);
71     }
72 
73     /** Redundant javadoc to make checkstyle happy */
74     @AutoAnnotation
sdkLevelAtLeastS2(String reason)75     public static RequiresSdkLevelAtLeastS2 sdkLevelAtLeastS2(String reason) {
76         return new AutoAnnotation_TestAnnotations_sdkLevelAtLeastS2(reason);
77     }
78 
79     /** Redundant javadoc to make checkstyle happy */
80     @AutoAnnotation
sdkLevelAtLeastT(String reason)81     public static RequiresSdkLevelAtLeastT sdkLevelAtLeastT(String reason) {
82         return new AutoAnnotation_TestAnnotations_sdkLevelAtLeastT(reason);
83     }
84 
85     /** Redundant javadoc to make checkstyle happy */
86     @AutoAnnotation
sdkLevelAtLeastU(String reason)87     public static RequiresSdkLevelAtLeastU sdkLevelAtLeastU(String reason) {
88         return new AutoAnnotation_TestAnnotations_sdkLevelAtLeastU(reason);
89     }
90 
91     /** Redundant javadoc to make checkstyle happy */
92     @AutoAnnotation
newAnnotationForLessThanT(String reason)93     public static RequiresSdkRange newAnnotationForLessThanT(String reason) {
94         return sdkRange(Range.NO_MIN, AndroidSdk.PRE_T, reason);
95     }
96 
97     /** Redundant javadoc to make checkstyle happy */
98     @AutoAnnotation
sdkRange(int atLeast, int atMost, String reason)99     public static RequiresSdkRange sdkRange(int atLeast, int atMost, String reason) {
100         return new AutoAnnotation_TestAnnotations_sdkRange(atLeast, atMost, reason);
101     }
102 
103     /** Redundant javadoc to make checkstyle happy */
104     @AutoAnnotation
requiresLowRamDevice()105     public static RequiresLowRamDevice requiresLowRamDevice() {
106         return new AutoAnnotation_TestAnnotations_requiresLowRamDevice();
107     }
108 
109     /** Redundant javadoc to make checkstyle happy */
110     @AutoAnnotation
requiresScreenSizeDevice(ScreenSize value)111     public static RequiresScreenSizeDevice requiresScreenSizeDevice(ScreenSize value) {
112         return new AutoAnnotation_TestAnnotations_requiresScreenSizeDevice(value);
113     }
114 
115     /** Redundant javadoc to make checkstyle happy */
116     @AutoAnnotation
requiresGoDevice()117     public static RequiresGoDevice requiresGoDevice() {
118         return new AutoAnnotation_TestAnnotations_requiresGoDevice();
119     }
120 }
121