• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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.apitest;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import android.car.hardware.property.AreaIdConfig;
22 import android.os.Parcel;
23 
24 import org.junit.Test;
25 
26 import java.util.List;
27 
28 /**
29  * Unit tests for {@link AreaIdConfig}
30  */
31 public class AreaIdConfigTest {
32     private static final int AREA_ID = 99;
33     private static final int MAX_VALUE = 10;
34     private static final int MIN_VALUE = 1;
35     private static final List<Integer> SUPPORTED_ENUM_VALUES = List.of(2, 3, 4);
36     private static final AreaIdConfig<Integer> AREA_ID_CONFIG = new AreaIdConfig.Builder<Integer>(
37             AREA_ID).setMaxValue(MAX_VALUE).setMinValue(MIN_VALUE).setSupportedEnumValues(
38             SUPPORTED_ENUM_VALUES).build();
39 
40     @Test
getAreaId_returnsExpectedValue()41     public void getAreaId_returnsExpectedValue() {
42         assertThat(AREA_ID_CONFIG.getAreaId()).isEqualTo(AREA_ID);
43     }
44 
45     @Test
getMinValue_returnsExpectedValue()46     public void getMinValue_returnsExpectedValue() {
47         assertThat(AREA_ID_CONFIG.getMinValue()).isEqualTo(MIN_VALUE);
48     }
49 
50     @Test
getMinValue_returnsNullIfNotSet()51     public void getMinValue_returnsNullIfNotSet() {
52         assertThat(new AreaIdConfig.Builder<Long>(AREA_ID).build().getMinValue()).isNull();
53     }
54 
55     @Test
getMaxValue_returnsExpectedValue()56     public void getMaxValue_returnsExpectedValue() {
57         assertThat(AREA_ID_CONFIG.getMaxValue()).isEqualTo(MAX_VALUE);
58     }
59 
60     @Test
getMaxValue_returnsNullIfNotSet()61     public void getMaxValue_returnsNullIfNotSet() {
62         assertThat(new AreaIdConfig.Builder<Long>(AREA_ID).build().getMaxValue()).isNull();
63     }
64 
65     @Test
getSupportedEnumValues_returnsExpectedValue()66     public void getSupportedEnumValues_returnsExpectedValue() {
67         assertThat(AREA_ID_CONFIG.getSupportedEnumValues()).containsExactlyElementsIn(
68                 SUPPORTED_ENUM_VALUES);
69     }
70 
71     @Test
getSupportedEnumValues_returnsEmptyListIfNoSet()72     public void getSupportedEnumValues_returnsEmptyListIfNoSet() {
73         assertThat(new AreaIdConfig.Builder<Long>(
74                 AREA_ID).build().getSupportedEnumValues()).isEmpty();
75     }
76 
77     @Test
describeContents_returnsExpectedValue()78     public void describeContents_returnsExpectedValue() {
79         assertThat(AREA_ID_CONFIG.describeContents()).isEqualTo(0);
80     }
81 
82     @Test
writeToParcel_writesCorrectly()83     public void writeToParcel_writesCorrectly() {
84         Parcel parcel = Parcel.obtain();
85         AREA_ID_CONFIG.writeToParcel(parcel, /*flags=*/0);
86 
87         // After you're done with writing, you need to reset the parcel for reading.
88         parcel.setDataPosition(0);
89 
90         AreaIdConfig<Object> areaIdConfig = AreaIdConfig.CREATOR.createFromParcel(parcel);
91         assertThat((Integer) areaIdConfig.getMaxValue()).isEqualTo(MAX_VALUE);
92         assertThat((Integer) areaIdConfig.getMinValue()).isEqualTo(MIN_VALUE);
93         assertThat(
94                 (List<?>) areaIdConfig.getSupportedEnumValues()).containsExactlyElementsIn(
95                 SUPPORTED_ENUM_VALUES);
96     }
97 
98     @Test
toString_doesNotReturnNull()99     public void toString_doesNotReturnNull() {
100         assertThat(AREA_ID_CONFIG.toString()).isNotNull();
101     }
102 
103     @Test
creator_newArrayWorksCorrectly()104     public void creator_newArrayWorksCorrectly() {
105         AreaIdConfig<Object>[] areaIdConfigs = AreaIdConfig.CREATOR.newArray(2);
106         assertThat(areaIdConfigs).hasLength(2);
107         assertThat(areaIdConfigs[0]).isNull();
108         assertThat(areaIdConfigs[1]).isNull();
109     }
110 }
111 
112