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