1 /* 2 * Copyright (C) 2022 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 package com.android.bedstead.harrier 17 18 import com.android.bedstead.harrier.annotations.FailureMode 19 import com.google.common.truth.Truth 20 import org.junit.Assume 21 import org.junit.AssumptionViolatedException 22 23 /** 24 * Utilities for use by [AnnotationExecutor] subclasses. 25 */ 26 object AnnotationExecutorUtil { 27 /** 28 * [failOrSkip] if [value] is true. 29 */ 30 @JvmStatic checkFailOrSkipnull31 fun checkFailOrSkip(message: String?, value: Boolean, failureMode: FailureMode) { 32 when (failureMode) { 33 FailureMode.FAIL -> Truth.assertWithMessage(message).that(value).isTrue() 34 FailureMode.SKIP -> Assume.assumeTrue(message, value) 35 } 36 } 37 38 /** 39 * Either fail or skip the current test depending on the value of `failureMode`. 40 */ 41 @JvmStatic failOrSkipnull42 fun failOrSkip(message: String?, failureMode: FailureMode) { 43 when (failureMode) { 44 FailureMode.FAIL -> throw AssertionError(message) 45 FailureMode.SKIP -> throw AssumptionViolatedException(message) 46 } 47 } 48 } 49