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.shared.testing;
18 
19 import com.google.common.annotations.VisibleForTesting;
20 import com.google.common.collect.ImmutableList;
21 
22 import org.junit.AssumptionViolatedException;
23 
24 import java.util.List;
25 
26 // TODO(b/324919960): make it package-protected again or make sure it's unit tested.
27 /** Utility Exception class to surface device conditions being violated. */
28 public final class DeviceConditionsViolatedException extends AssumptionViolatedException {
29 
30     private final ImmutableList<String> mReasons;
31 
32     // TODO(b/324919960): make it package-protected again or make sure it's unit tested.
DeviceConditionsViolatedException(List<String> reasons)33     public DeviceConditionsViolatedException(List<String> reasons) {
34         super(
35                 String.format(
36                         "Assumptions violated: %d\nReasons: %s",
37                         reasons.size(), String.join("\n", reasons)));
38         this.mReasons = ImmutableList.copyOf(reasons);
39     }
40 
41     @VisibleForTesting
getConditionsViolatedReasons()42     public ImmutableList<String> getConditionsViolatedReasons() {
43         return mReasons;
44     }
45 }
46