blob: d234e42d763fd4cd4d2b2b49a5086ea6bbb00d9c [file] [log] [blame]
Marcus Hagerott89456ce2016-11-02 09:51:20 -07001/*
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 */
Gary Mai69c182a2016-12-05 13:07:03 -080016package com.android.contacts.model;
Marcus Hagerott819214d2016-09-29 14:58:27 -070017
Gary Mai0a49afa2016-12-05 15:53:58 -080018import static org.hamcrest.Matchers.equalTo;
19import static org.junit.Assert.assertThat;
20
Marcus Hagerott819214d2016-09-29 14:58:27 -070021import android.os.Parcel;
22import android.support.test.filters.SmallTest;
23import android.support.test.runner.AndroidJUnit4;
24
25import org.junit.Test;
26import org.junit.runner.RunWith;
27
Marcus Hagerott819214d2016-09-29 14:58:27 -070028@SmallTest
29@RunWith(AndroidJUnit4.class)
30public class SimContactTests {
31 @Test
32 public void parcelRoundtrip() {
33 assertParcelsCorrectly(new SimContact(1, "name1", "phone1",
34 new String[] { "email1a", "email1b" }));
Marcus Hagerott6c42b4c2016-10-31 14:59:53 -070035 assertParcelsCorrectly(new SimContact(2, "name2", "phone2", null));
Marcus Hagerott819214d2016-09-29 14:58:27 -070036 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
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}