• 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 
18 package android.nearby.cts;
19 
20 import static com.google.common.truth.Truth.assertThat;
21 
22 import android.nearby.CredentialElement;
23 import android.os.Build;
24 import android.os.Parcel;
25 
26 import androidx.annotation.RequiresApi;
27 import androidx.test.ext.junit.runners.AndroidJUnit4;
28 import androidx.test.filters.SdkSuppress;
29 
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 
33 import java.util.Arrays;
34 
35 @RunWith(AndroidJUnit4.class)
36 @RequiresApi(Build.VERSION_CODES.TIRAMISU)
37 public class CredentialElementTest {
38     private static final String KEY = "SECRETE_ID";
39     private static final byte[] VALUE = new byte[]{1, 2, 3, 4};
40 
41     @Test
42     @SdkSuppress(minSdkVersion = 32, codeName = "T")
testBuilder()43     public void testBuilder() {
44         CredentialElement element = new CredentialElement(KEY, VALUE);
45         assertThat(element.getKey()).isEqualTo(KEY);
46         assertThat(Arrays.equals(element.getValue(), VALUE)).isTrue();
47     }
48 
49     @Test
50     @SdkSuppress(minSdkVersion = 32, codeName = "T")
testWriteParcel()51     public void testWriteParcel() {
52         CredentialElement element = new CredentialElement(KEY, VALUE);
53 
54         Parcel parcel = Parcel.obtain();
55         element.writeToParcel(parcel, 0);
56         parcel.setDataPosition(0);
57         CredentialElement elementFromParcel = element.CREATOR.createFromParcel(
58                 parcel);
59         parcel.recycle();
60         assertThat(elementFromParcel.getKey()).isEqualTo(KEY);
61         assertThat(Arrays.equals(elementFromParcel.getValue(), VALUE)).isTrue();
62     }
63 
64     @Test
65     @SdkSuppress(minSdkVersion = 32, codeName = "T")
describeContents()66     public void describeContents() {
67         CredentialElement element = new CredentialElement(KEY, VALUE);
68         assertThat(element.describeContents()).isEqualTo(0);
69     }
70 
71     @Test
72     @SdkSuppress(minSdkVersion = 32, codeName = "T")
testEqual()73     public void testEqual() {
74         CredentialElement element1 = new CredentialElement(KEY, VALUE);
75         CredentialElement element2 = new CredentialElement(KEY, VALUE);
76         assertThat(element1.equals(element2)).isTrue();
77         assertThat(element1.hashCode()).isEqualTo(element2.hashCode());
78     }
79 
80     @Test
81     @SdkSuppress(minSdkVersion = 32, codeName = "T")
testCreatorNewArray()82     public void testCreatorNewArray() {
83         CredentialElement [] elements =
84                 CredentialElement.CREATOR.newArray(2);
85         assertThat(elements.length).isEqualTo(2);
86     }
87 }
88