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; 18 19 import com.android.adservices.common.logging.annotations.ExpectErrorLogUtilCall; 20 import com.android.adservices.shared.testing.LogVerifier; 21 22 import com.google.common.collect.ImmutableList; 23 24 import java.util.List; 25 import java.util.Objects; 26 27 /** Factory class to centralize creation of {@link LogVerifier} objects. */ 28 public final class AdServicesLogVerifierFactory { 29 /** Supported log types. */ 30 enum LogType { 31 /** 32 * Verify ErrorLogUtil.e(Throwable, int, int) and ErrorLogUtil.e(int, int) calls. Use {@link 33 * ExpectErrorLogUtilCall} annotation to denote expected logging calls. 34 */ 35 ERROR_LOG_UTIL; 36 } 37 38 /** 39 * Creates appropriate {@link LogVerifier} objects for a given {@link LogType}. 40 * 41 * @param logType {@link LogType} 42 * @return list of {@link LogVerifier} objects associated with the log types. 43 */ create(LogType logType)44 public static List<LogVerifier> create(LogType logType) { 45 Objects.requireNonNull(logType); 46 47 switch (logType) { 48 case ERROR_LOG_UTIL: 49 return ImmutableList.of( 50 new AdServicesErrorLogUtilVerifier(), 51 new AdServicesErrorLogUtilWithExceptionVerifier()); 52 default: 53 throw new IllegalArgumentException("Unsupported logType: " + logType); 54 } 55 } 56 } 57