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