1 /*
2  * Copyright (C) 2021 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 package com.android.phone;
18 
19 import static org.junit.Assert.assertNull;
20 import static org.junit.Assert.assertTrue;
21 
22 import android.content.Intent;
23 import android.telephony.SubscriptionInfo;
24 import android.telephony.SubscriptionManager;
25 
26 import org.junit.Test;
27 
28 public class SubscriptionInfoHelperTest {
29     private static final String EXTRA_SUBSCRIPTION_LABEL =
30             "com.android.phone.settings.SubscriptionInfoHelper.SubscriptionLabel";
31 
32     /**
33      * Ensures {@link SubscriptionInfoHelper#addExtrasToIntent(Intent, SubscriptionInfo)} can
34      * properly handle a null display name without crashing.
35      */
36     @Test
testAddExtrasToIntentWithNullDisplayName()37     public void testAddExtrasToIntentWithNullDisplayName() {
38         Intent intent = new Intent();
39         SubscriptionInfo info = new SubscriptionInfo(1, // id
40                 "90210", // iccId
41                 1, // simSlotIndex
42                 null, // displayName
43                 null, // carrierName
44                 SubscriptionManager.NAME_SOURCE_CARRIER_ID, // nameSource
45                 0, //iconTint
46                 "555-1212", // number
47                 0, // roaming
48                 null, // icon
49                 "401", // mcc
50                 "384", // mnc
51                 "us", // countryIso
52                 false, // isEmbedded
53                 null, // nativeAccessRules
54                 ""); // cardString
55         SubscriptionInfoHelper.addExtrasToIntent(intent, info);
56         assertNull(intent.getStringExtra(EXTRA_SUBSCRIPTION_LABEL));
57         assertTrue(intent.hasExtra(EXTRA_SUBSCRIPTION_LABEL));
58     }
59 }
60