Marcus Hagerott | 89456ce | 2016-11-02 09:51:20 -0700 | [diff] [blame^] | 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 | */ |
Marcus Hagerott | 819214d | 2016-09-29 14:58:27 -0700 | [diff] [blame] | 16 | package com.android.contacts.common.model; |
| 17 | |
| 18 | import android.os.Parcel; |
| 19 | import android.support.test.filters.SmallTest; |
| 20 | import android.support.test.runner.AndroidJUnit4; |
| 21 | |
| 22 | import org.junit.Test; |
| 23 | import org.junit.runner.RunWith; |
| 24 | |
| 25 | import static org.hamcrest.Matchers.equalTo; |
| 26 | import static org.junit.Assert.assertThat; |
| 27 | |
Marcus Hagerott | 819214d | 2016-09-29 14:58:27 -0700 | [diff] [blame] | 28 | @SmallTest |
| 29 | @RunWith(AndroidJUnit4.class) |
| 30 | public class SimContactTests { |
| 31 | @Test |
| 32 | public void parcelRoundtrip() { |
| 33 | assertParcelsCorrectly(new SimContact(1, "name1", "phone1", |
| 34 | new String[] { "email1a", "email1b" })); |
Marcus Hagerott | 6c42b4c | 2016-10-31 14:59:53 -0700 | [diff] [blame] | 35 | assertParcelsCorrectly(new SimContact(2, "name2", "phone2", null)); |
Marcus Hagerott | 819214d | 2016-09-29 14:58:27 -0700 | [diff] [blame] | 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 | |
| 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 | } |