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 Log.v(TAG, "mocking handleRemoteExceptionFromCarService(): args=" + invocation); 42 Object returnValue = invocation.getArguments()[1]; 43 Log.v(TAG, "returning " + returnValue); 44 return returnValue; 45 }).when(car).handleRemoteExceptionFromCarService(isA(RemoteException.class), any()); 46 } 47 CarMockitoHelper()48 private CarMockitoHelper() { 49 throw new UnsupportedOperationException("contains only static methods"); 50 } 51 } 52