• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.cluster;
18 
19 import static android.view.Display.INVALID_DISPLAY;
20 
21 import static com.google.common.truth.Truth.assertThat;
22 
23 import android.graphics.Insets;
24 import android.graphics.Rect;
25 import android.os.Parcel;
26 
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.mockito.junit.MockitoJUnitRunner;
30 
31 @RunWith(MockitoJUnitRunner.class)
32 public final class ClusterStateTest {
33     private static final ClusterState CLUSTER_STATE = new ClusterState() {
34         {
35             on = true;
36             bounds = new Rect(1, 1, 2, 2);
37             insets = Insets.of(0, 1, 2, 3);
38             uiType = ClusterHomeManager.UI_TYPE_CLUSTER_NONE;
39             displayId = INVALID_DISPLAY;
40         }
41     };
42 
43     @Test
clusterStateWriteAndReadParcel()44     public void clusterStateWriteAndReadParcel() {
45         ClusterState originalClusterState = CLUSTER_STATE;
46         Parcel parcel = Parcel.obtain();
47         originalClusterState.writeToParcel(parcel, 0);
48         parcel.setDataPosition(0);
49 
50         ClusterState convertedClusterState = ClusterState.CREATOR.createFromParcel(parcel);
51 
52         assertThat(convertedClusterState.on).isEqualTo(true);
53         assertThat(convertedClusterState.bounds).isEqualTo(new Rect(1, 1, 2, 2));
54         assertThat(convertedClusterState.insets).isEqualTo(Insets.of(0, 1, 2, 3));
55         assertThat(convertedClusterState.uiType).isEqualTo(ClusterHomeManager.UI_TYPE_CLUSTER_NONE);
56         assertThat(convertedClusterState.displayId).isEqualTo(INVALID_DISPLAY);
57     }
58 
59     @Test
clusterStateNewArray()60     public void clusterStateNewArray() {
61         ClusterState[] clusterStateArray = ClusterState.CREATOR.newArray(10);
62         assertThat(clusterStateArray).hasLength(10);
63     }
64 }
65