1 /* 2 * Copyright (C) 2016 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.apitest; 17 18 import android.car.Car; 19 import android.car.CarApiUtil; 20 import android.car.CarNotConnectedException; 21 import android.car.settings.CarSettings; 22 23 import junit.framework.TestCase; 24 25 public class CarApiUtilTest extends TestCase { 26 27 public void testDecodeGarageTimeSetting() { 28 String time = "11:20"; 29 int[] result = CarApiUtil.decodeGarageTimeSetting(time); 30 assertEquals(11, result[0]); 31 assertEquals(20, result[1]); 32 33 time = "23:59"; 34 result = CarApiUtil.decodeGarageTimeSetting(time); 35 assertEquals(23, result[0]); 36 assertEquals(59, result[1]); 37 38 time = null; 39 assertEquals(CarSettings.DEFAULT_GARAGE_MODE_WAKE_UP_TIME, 40 CarApiUtil.decodeGarageTimeSetting(time)); 41 42 time = "25:10"; 43 result = CarApiUtil.decodeGarageTimeSetting(time); 44 assertEquals(CarSettings.DEFAULT_GARAGE_MODE_WAKE_UP_TIME, result); 45 46 time = "12:99"; 47 result = CarApiUtil.decodeGarageTimeSetting(time); 48 assertEquals(CarSettings.DEFAULT_GARAGE_MODE_WAKE_UP_TIME, result); 49 50 time= "hour:min"; 51 result = CarApiUtil.decodeGarageTimeSetting(time); 52 assertEquals(CarSettings.DEFAULT_GARAGE_MODE_WAKE_UP_TIME, result); 53 } 54 55 public void testEncodeGarageModeTime() { 56 assertTrue(CarApiUtil.encodeGarageTimeSetting(0, 0).equals("0:0")); 57 assertTrue(CarApiUtil.encodeGarageTimeSetting(10, 0).equals("10:0")); 58 assertTrue(CarApiUtil.encodeGarageTimeSetting(23, 59).equals("23:59")); 59 } 60 61 public void testCheckCarNotConnectedExceptionFromCarService() { 62 IllegalStateException e = new IllegalStateException(Car.CAR_NOT_CONNECTED_EXCEPTION_MSG); 63 Exception resultException = null; 64 try { 65 CarApiUtil.checkCarNotConnectedExceptionFromCarService(e); 66 } catch (Exception exception) { 67 resultException = exception; 68 } 69 assertTrue(resultException instanceof CarNotConnectedException); 70 71 e = new IllegalStateException("Hello"); 72 resultException = null; 73 try { 74 CarApiUtil.checkCarNotConnectedExceptionFromCarService(e); 75 } catch (Exception exception) { 76 resultException = exception; 77 } 78 assertEquals(e, resultException); 79 } 80 } 81