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.concurrency; 18 19 import androidx.annotation.Nullable; 20 21 import java.util.List; 22 23 /** 24 * Abstraction for {@code ResultSyncCallback} and {@code FailableResultSyncCallback}. 25 * 26 * <p>This is needed because the latter is a "special" case of the former as it can receive either a 27 * result OR a failure. 28 */ 29 interface IResultSyncCallback<R> extends SyncCallback, IBinderSyncCallback { 30 31 /** Sets the result. */ injectResult(@ullable R result)32 void injectResult(@Nullable R result); 33 34 /** 35 * Asserts that {@link #injectResult(Object)} was called, waiting up to {@link 36 * #getMaxTimeoutMs()} milliseconds before failing (if not called). 37 * 38 * @return the result 39 */ 40 @Nullable assertResultReceived()41 R assertResultReceived() throws InterruptedException; 42 43 /** 44 * Gets the result returned by {@link #injectResult(Object)}. 45 * 46 * <p>NOTE: it returns the result of the first call, which is sufficient for most use cases - if 47 * you're expecting multiple calls, you can get the further ones using {@link #getResults()}. 48 */ 49 @Nullable getResult()50 R getResult(); 51 52 // NOTE: cannot use Guava's ImmutableList because it doesn't support null elements 53 /** 54 * Gets the result of all calls to {@link #injectResult(Object)}, in order. 55 * 56 * @return immutable list with all results 57 */ getResults()58 List<R> getResults(); 59 } 60