1 /*
2  * Copyright (C) 2020 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 android.car.test.mock;
17 
18 import static org.mockito.ArgumentMatchers.any;
19 import static org.mockito.ArgumentMatchers.isA;
20 import static org.mockito.Mockito.doAnswer;
21 
22 import android.annotation.NonNull;
23 import android.os.RemoteException;
24 import android.util.Log;
25 
26 import com.android.car.internal.ICarBase;
27 
28 /**
29  * Provides common Mockito calls for Car-specific classes.
30  */
31 public final class CarMockitoHelper {
32 
33     private static final String TAG = CarMockitoHelper.class.getSimpleName();
34 
35     /**
36      * Mocks a call to {@link Car#handleRemoteExceptionFromCarService(RemoteException, Object)} so
37      * it returns the passed as 2nd argument.
38      */
mockHandleRemoteExceptionFromCarServiceWithDefaultValue( @onNull ICarBase car)39     public static void mockHandleRemoteExceptionFromCarServiceWithDefaultValue(
40             @NonNull ICarBase car) {
41         doAnswer((invocation) -> {
42             Log.v(TAG, "mocking handleRemoteExceptionFromCarService(): args=" + invocation);
43             Object returnValue = invocation.getArguments()[1];
44             Log.v(TAG, "returning " + returnValue);
45             return returnValue;
46         }).when(car).handleRemoteExceptionFromCarService(isA(RemoteException.class), any());
47     }
48 
CarMockitoHelper()49     private CarMockitoHelper() {
50         throw new UnsupportedOperationException("contains only static methods");
51     }
52 }
53