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