• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 com.android.contacts.model;
17 
18 import static org.hamcrest.Matchers.equalTo;
19 import static org.junit.Assert.assertThat;
20 
21 import android.os.Parcel;
22 
23 import androidx.test.filters.SmallTest;
24 import androidx.test.runner.AndroidJUnit4;
25 
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 
29 @SmallTest
30 @RunWith(AndroidJUnit4.class)
31 public class SimContactTests {
32     @Test
parcelRoundtrip()33     public void parcelRoundtrip() {
34         assertParcelsCorrectly(new SimContact(1, "name1", "phone1",
35                 new String[] { "email1a", "email1b" }));
36         assertParcelsCorrectly(new SimContact(2, "name2", "phone2", null));
37         assertParcelsCorrectly(new SimContact(3, "name3", null,
38                 new String[] { "email3" }));
39         assertParcelsCorrectly(new SimContact(4, null, "phone4",
40                 new String[] { "email4" }));
41         assertParcelsCorrectly(new SimContact(5, null, null, null));
42         assertParcelsCorrectly(new SimContact(6, "name6", "phone6",
43                 new String[0]));
44     }
45 
assertParcelsCorrectly(SimContact contact)46     private void assertParcelsCorrectly(SimContact contact) {
47         final Parcel parcel = Parcel.obtain();
48         parcel.writeParcelable(contact, 0);
49         parcel.setDataPosition(0);
50         final SimContact unparceled = parcel.readParcelable(
51                 SimContact.class.getClassLoader());
52         assertThat(unparceled, equalTo(contact));
53         parcel.recycle();
54     }
55 }
56