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 com.android.adservices.common.logging.annotations;
18 
19 import static java.lang.annotation.ElementType.METHOD;
20 import static java.lang.annotation.RetentionPolicy.RUNTIME;
21 
22 import java.lang.annotation.Repeatable;
23 import java.lang.annotation.Retention;
24 import java.lang.annotation.Target;
25 
26 /**
27  * Used to specify expected {@code ErrorLogUtil.e(int, int)} calls over test methods.
28  *
29  * <ol>
30  *   <li>To verify ErrorLogUtil.e(int, int) calls: @ExpectErrorLogUtilCall(X, Y)
31  *   <li>To verify multiple same calls, use the times arg: @ExpectErrorLogUtilCall(X, Y, 5)
32  *   <li>To verify different invocations, use multiple annotations.
33  *   <li>See {@link SetErrorLogUtilDefaultParams} to specify default params at the class level.
34  * </ol>
35  *
36  * <p>See {@link ExpectErrorLogUtilWithExceptionCall} for verifying {@code ErrorLogUtil.e(Throwable,
37  * int, int)} calls.
38  */
39 @Retention(RUNTIME)
40 @Target(METHOD)
41 @Repeatable(ExpectErrorLogUtilCalls.class)
42 public @interface ExpectErrorLogUtilCall {
43     /** Name of annotation */
44     String ANNOTATION_NAME = ExpectErrorLogUtilCall.class.getSimpleName();
45 
46     /** Internal value to represent unspecified int logging parameter. */
47     int UNDEFINED_INT_PARAM = Integer.MIN_VALUE;
48 
49     /** Default number of times to expect log call. */
50     int DEFAULT_TIMES = 1;
51 
52     /**
53      * Error code to be logged.
54      *
55      * <p>It's required to define this using {@link SetErrorLogUtilDefaultParams} at the class level
56      * if it is not defined within this annotation.
57      */
errorCode()58     int errorCode() default UNDEFINED_INT_PARAM;
59 
60     /**
61      * PPAPI name code to be logged.
62      *
63      * <p>It's required to define this using {@link SetErrorLogUtilDefaultParams} at the class level
64      * if it is not defined within this annotation.
65      */
ppapiName()66     int ppapiName() default UNDEFINED_INT_PARAM;
67 
68     /** Number of log calls, default set to 1 */
times()69     int times() default DEFAULT_TIMES;
70 }
71