Use mocked Car in CarPropertyManagerUnitTest.
- Real Car can kill the client when Car service restarts.
Bug: 240426835
Test: atest CarServiceUnitTest
Change-Id: I84269d7c3d2d29c2c97e1de881c862622f63b41f
(cherry picked from commit 8025581efcfc6095381d563a817f51c41bef72ab)
Merged-In: I84269d7c3d2d29c2c97e1de881c862622f63b41f
diff --git a/tests/carservice_unit_test/src/com/android/car/CarPropertyManagerUnitTest.java b/tests/carservice_unit_test/src/com/android/car/CarPropertyManagerUnitTest.java
index 007bc5e..88193c6 100644
--- a/tests/carservice_unit_test/src/com/android/car/CarPropertyManagerUnitTest.java
+++ b/tests/carservice_unit_test/src/com/android/car/CarPropertyManagerUnitTest.java
@@ -43,7 +43,8 @@
import android.car.hardware.property.ICarPropertyEventListener;
import android.content.Context;
import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageManager;
+import android.os.Handler;
+import android.os.Looper;
import android.os.RemoteException;
import com.google.common.collect.ImmutableList;
@@ -72,6 +73,10 @@
private static final float LARGER_UPDATE_RATE_HZ = 50.1f;
private static final float SMALLER_UPDATE_RATE_HZ = 49.9f;
+ private final Handler mMainHandler = new Handler(Looper.getMainLooper());
+
+ @Mock
+ private Car mCar;
@Mock
private ApplicationInfo mApplicationInfo;
@Mock
@@ -79,8 +84,6 @@
@Mock
private Context mContext;
@Mock
- private PackageManager mPackageManager;
- @Mock
private CarPropertyManager.CarPropertyEventCallback mCarPropertyEventCallback;
@Mock
private CarPropertyManager.CarPropertyEventCallback mCarPropertyEventCallback2;
@@ -116,8 +119,8 @@
@Before
public void setUp() throws RemoteException {
- when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE)).thenReturn(true);
- when(mContext.getPackageManager()).thenReturn(mPackageManager);
+ when(mCar.getContext()).thenReturn(mContext);
+ when(mCar.getEventHandler()).thenReturn(mMainHandler);
when(mContext.getApplicationInfo()).thenReturn(mApplicationInfo);
when(mContinuousCarPropertyConfig.getChangeMode()).thenReturn(
CarPropertyConfig.VEHICLE_PROPERTY_CHANGE_MODE_CONTINUOUS);
@@ -133,7 +136,7 @@
ImmutableList.of(mOnChangeCarPropertyConfig));
when(mICarProperty.getPropertyConfigList(new int[]{STATIC_PROPERTY})).thenReturn(
ImmutableList.of(mStaticCarPropertyConfig));
- mCarPropertyManager = new CarPropertyManager(Car.createCar(mContext), mICarProperty);
+ mCarPropertyManager = new CarPropertyManager(mCar, mICarProperty);
}
@Test