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