1 /* 2 * Copyright (C) 2019 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 android.car; 18 19 import static android.car.VehiclePropertyIds.HVAC_FAN_SPEED; 20 import static android.car.VehiclePropertyIds.HVAC_TEMPERATURE_CURRENT; 21 22 import static com.google.common.truth.Truth.assertThat; 23 24 import android.car.hardware.property.CarPropertyManager; 25 import android.car.testapi.CarPropertyController; 26 import android.car.testapi.FakeCar; 27 28 import androidx.test.core.app.ApplicationProvider; 29 30 import org.junit.Before; 31 import org.junit.Rule; 32 import org.junit.Test; 33 import org.junit.runner.RunWith; 34 import org.mockito.junit.MockitoJUnit; 35 import org.mockito.junit.MockitoRule; 36 import org.robolectric.RobolectricTestRunner; 37 import org.robolectric.annotation.internal.DoNotInstrument; 38 39 @RunWith(RobolectricTestRunner.class) 40 @DoNotInstrument 41 public class CarPropertyManagerTest { 42 private static final int FAN_SPEED_VALUE = 42; 43 private static final float TEMPERATURE_VALUE = 42.24f; 44 45 @Rule 46 public MockitoRule rule = MockitoJUnit.rule(); 47 48 private CarPropertyController mController; 49 private CarPropertyManager mManager; 50 51 @Before setUp()52 public void setUp() { 53 FakeCar fakeCar = FakeCar.createFakeCar(ApplicationProvider.getApplicationContext()); 54 mController = fakeCar.getCarPropertyController(); 55 Car car = fakeCar.getCar(); 56 mManager = (CarPropertyManager) car.getCarManager(Car.PROPERTY_SERVICE); 57 assertThat(mManager).isNotNull(); 58 } 59 60 @Test carPropertyManager_int()61 public void carPropertyManager_int() { 62 mController.addProperty(HVAC_FAN_SPEED, FAN_SPEED_VALUE); 63 assertThat(mManager.getIntProperty(HVAC_FAN_SPEED, 0)).isEqualTo(FAN_SPEED_VALUE); 64 } 65 66 @Test carPropertyManager_intThrows()67 public void carPropertyManager_intThrows() { 68 mController.addProperty(HVAC_FAN_SPEED, FAN_SPEED_VALUE); 69 try { 70 mManager.getFloatProperty(HVAC_FAN_SPEED, 0); 71 } catch (IllegalArgumentException expected) { 72 // Expected, the property is an integer value. 73 } 74 } 75 76 @Test carPropertyManager_float()77 public void carPropertyManager_float() { 78 mController.addProperty(HVAC_TEMPERATURE_CURRENT, TEMPERATURE_VALUE); 79 assertThat(mManager.getFloatProperty(HVAC_TEMPERATURE_CURRENT, 0)) 80 .isEqualTo(TEMPERATURE_VALUE); 81 } 82 83 @Test carPropertyManager_floatThrows()84 public void carPropertyManager_floatThrows() { 85 mController.addProperty(HVAC_TEMPERATURE_CURRENT, TEMPERATURE_VALUE); 86 try { 87 mManager.getIntProperty(HVAC_TEMPERATURE_CURRENT, 0); 88 } catch (IllegalArgumentException expected) { 89 // Expected, the property is an integer value. 90 } 91 } 92 } 93