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 com.android.adservices.common.logging.annotations.ExpectErrorLogUtilCall.DEFAULT_TIMES; 20 import static com.android.adservices.common.logging.annotations.ExpectErrorLogUtilCall.UNDEFINED_INT_PARAM; 21 22 import static java.lang.annotation.ElementType.METHOD; 23 import static java.lang.annotation.RetentionPolicy.RUNTIME; 24 25 import java.lang.annotation.Repeatable; 26 import java.lang.annotation.Retention; 27 import java.lang.annotation.Target; 28 29 /** 30 * Used to specify expected {@code ErrorLogUtil.e(Throwable, int, int)} calls over test methods. 31 * This annotation can be used for verifying background calls as well. 32 * 33 * <ol> 34 * <li>To verify ErrorLogUtil.e(Throwable, int, int): @ExpectErrorLogUtilCall(E.class, X, Y) 35 * <li>To verify with any exception: @ExpectErrorLogUtilCall(Any.class, X, Y) 36 * <li>To verify multiple same calls, use the times arg: @ExpectErrorLogUtilCall(E.class, X, Y, 5) 37 * <li>To verify different invocations, use multiple annotations. 38 * <li>See {@link SetErrorLogUtilDefaultParams} to specify default params at the class level. 39 * </ol> 40 * 41 * <p>See {@link ExpectErrorLogUtilCall} for verifying {@code ErrorLogUtil.e(int, int)} calls. 42 */ 43 @Retention(RUNTIME) 44 @Target(METHOD) 45 @Repeatable(ExpectErrorLogUtilWithExceptionCalls.class) 46 public @interface ExpectErrorLogUtilWithExceptionCall { 47 /** Name of annotation */ 48 String ANNOTATION_NAME = ExpectErrorLogUtilWithExceptionCall.class.getSimpleName(); 49 50 /** Used to verify against any exception type for ErrorLogUtil.e(Throwable, int, int) calls. */ 51 class Any extends Throwable { Any()52 private Any() {} 53 } 54 55 /** Internal exception type to represent unspecified exception. */ 56 class Undefined extends Throwable { Undefined()57 private Undefined() {} 58 } 59 60 /** 61 * Throwable 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 */ throwable()66 Class<? extends Throwable> throwable() default Undefined.class; 67 68 /** 69 * Error code to be logged. 70 * 71 * <p>It's required to define this using {@link SetErrorLogUtilDefaultParams} at the class level 72 * if it is not defined within this annotation. 73 */ errorCode()74 int errorCode() default UNDEFINED_INT_PARAM; 75 76 /** 77 * PPAPI name code to be logged. 78 * 79 * <p>It's required to define this using {@link SetErrorLogUtilDefaultParams} at the class level 80 * if it is not defined within this annotation. 81 */ ppapiName()82 int ppapiName() default UNDEFINED_INT_PARAM; 83 84 /** Number of log calls, default set to 1 */ times()85 int times() default DEFAULT_TIMES; 86 } 87