Fabian Kozynski | a48d2d0 | 2019-02-27 11:36:02 -0500 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2019 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.systemui.qs; |
| 18 | |
| 19 | import static org.mockito.ArgumentMatchers.anyInt; |
| 20 | import static org.mockito.Mockito.mock; |
| 21 | import static org.mockito.Mockito.when; |
| 22 | |
| 23 | import android.telephony.SubscriptionManager; |
| 24 | import android.testing.AndroidTestingRunner; |
| 25 | import android.testing.TestableLooper; |
| 26 | import android.view.LayoutInflater; |
| 27 | |
| 28 | import androidx.test.filters.SmallTest; |
| 29 | |
| 30 | import com.android.keyguard.CarrierTextController; |
| 31 | import com.android.systemui.R; |
| 32 | import com.android.systemui.statusbar.policy.NetworkController; |
| 33 | import com.android.systemui.utils.leaks.LeakCheckedTest; |
| 34 | |
| 35 | import org.junit.Before; |
| 36 | import org.junit.Test; |
| 37 | import org.junit.runner.RunWith; |
| 38 | import org.mockito.Mockito; |
| 39 | import org.mockito.invocation.InvocationOnMock; |
| 40 | import org.mockito.stubbing.Answer; |
| 41 | |
| 42 | @RunWith(AndroidTestingRunner.class) |
| 43 | @TestableLooper.RunWithLooper |
| 44 | @SmallTest |
| 45 | public class QSCarrierGroupTest extends LeakCheckedTest { |
| 46 | |
| 47 | private QSCarrierGroup mCarrierGroup; |
| 48 | |
| 49 | @Before |
| 50 | public void setup() throws Exception { |
| 51 | injectLeakCheckedDependencies(ALL_SUPPORTED_CLASSES); |
| 52 | TestableLooper.get(this).runWithLooper( |
| 53 | () -> mCarrierGroup = (QSCarrierGroup) LayoutInflater.from(mContext).inflate( |
| 54 | R.layout.qs_carrier_group, null)); |
| 55 | } |
| 56 | |
| 57 | @Test // throws no Exception |
| 58 | public void testUpdateCarrierText_sameLengths() { |
| 59 | QSCarrierGroup spiedCarrierGroup = Mockito.spy(mCarrierGroup); |
| 60 | when(spiedCarrierGroup.getSlotIndex(anyInt())).thenAnswer( |
| 61 | new Answer<Integer>() { |
| 62 | @Override |
| 63 | public Integer answer(InvocationOnMock invocationOnMock) throws Throwable { |
| 64 | return invocationOnMock.getArgument(0); |
| 65 | } |
| 66 | }); |
| 67 | |
| 68 | // listOfCarriers length 1, subscriptionIds length 1, anySims false |
| 69 | CarrierTextController.CarrierTextCallbackInfo |
| 70 | c1 = new CarrierTextController.CarrierTextCallbackInfo( |
| 71 | "", |
| 72 | new CharSequence[]{""}, |
| 73 | false, |
| 74 | new int[]{0}); |
| 75 | spiedCarrierGroup.updateCarrierInfo(c1); |
| 76 | |
| 77 | // listOfCarriers length 1, subscriptionIds length 1, anySims true |
| 78 | CarrierTextController.CarrierTextCallbackInfo |
| 79 | c2 = new CarrierTextController.CarrierTextCallbackInfo( |
| 80 | "", |
| 81 | new CharSequence[]{""}, |
| 82 | true, |
| 83 | new int[]{0}); |
| 84 | spiedCarrierGroup.updateCarrierInfo(c2); |
| 85 | |
| 86 | // listOfCarriers length 2, subscriptionIds length 2, anySims false |
| 87 | CarrierTextController.CarrierTextCallbackInfo |
| 88 | c3 = new CarrierTextController.CarrierTextCallbackInfo( |
| 89 | "", |
| 90 | new CharSequence[]{"", ""}, |
| 91 | false, |
| 92 | new int[]{0, 1}); |
| 93 | spiedCarrierGroup.updateCarrierInfo(c3); |
| 94 | |
| 95 | // listOfCarriers length 2, subscriptionIds length 2, anySims true |
| 96 | CarrierTextController.CarrierTextCallbackInfo |
| 97 | c4 = new CarrierTextController.CarrierTextCallbackInfo( |
| 98 | "", |
| 99 | new CharSequence[]{"", ""}, |
| 100 | true, |
| 101 | new int[]{0, 1}); |
| 102 | spiedCarrierGroup.updateCarrierInfo(c4); |
| 103 | } |
| 104 | |
| 105 | @Test // throws no Exception |
| 106 | public void testUpdateCarrierText_differentLength() { |
| 107 | QSCarrierGroup spiedCarrierGroup = Mockito.spy(mCarrierGroup); |
| 108 | when(spiedCarrierGroup.getSlotIndex(anyInt())).thenAnswer( |
| 109 | new Answer<Integer>() { |
| 110 | @Override |
| 111 | public Integer answer(InvocationOnMock invocationOnMock) throws Throwable { |
| 112 | return invocationOnMock.getArgument(0); |
| 113 | } |
| 114 | }); |
| 115 | |
| 116 | // listOfCarriers length 2, subscriptionIds length 1, anySims false |
| 117 | CarrierTextController.CarrierTextCallbackInfo |
| 118 | c1 = new CarrierTextController.CarrierTextCallbackInfo( |
| 119 | "", |
| 120 | new CharSequence[]{"", ""}, |
| 121 | false, |
| 122 | new int[]{0}); |
| 123 | spiedCarrierGroup.updateCarrierInfo(c1); |
| 124 | |
| 125 | // listOfCarriers length 2, subscriptionIds length 1, anySims true |
| 126 | CarrierTextController.CarrierTextCallbackInfo |
| 127 | c2 = new CarrierTextController.CarrierTextCallbackInfo( |
| 128 | "", |
| 129 | new CharSequence[]{"", ""}, |
| 130 | true, |
| 131 | new int[]{0}); |
| 132 | spiedCarrierGroup.updateCarrierInfo(c2); |
| 133 | |
| 134 | // listOfCarriers length 1, subscriptionIds length 2, anySims false |
| 135 | CarrierTextController.CarrierTextCallbackInfo |
| 136 | c3 = new CarrierTextController.CarrierTextCallbackInfo( |
| 137 | "", |
| 138 | new CharSequence[]{""}, |
| 139 | false, |
| 140 | new int[]{0, 1}); |
| 141 | spiedCarrierGroup.updateCarrierInfo(c3); |
| 142 | |
| 143 | // listOfCarriers length 1, subscriptionIds length 2, anySims true |
| 144 | CarrierTextController.CarrierTextCallbackInfo |
| 145 | c4 = new CarrierTextController.CarrierTextCallbackInfo( |
| 146 | "", |
| 147 | new CharSequence[]{""}, |
| 148 | true, |
| 149 | new int[]{0, 1}); |
| 150 | spiedCarrierGroup.updateCarrierInfo(c4); |
| 151 | } |
| 152 | |
| 153 | @Test // throws no Exception |
| 154 | public void testUpdateCarrierText_invalidSim() { |
| 155 | QSCarrierGroup spiedCarrierGroup = Mockito.spy(mCarrierGroup); |
| 156 | when(spiedCarrierGroup.getSlotIndex(anyInt())).thenReturn( |
| 157 | SubscriptionManager.INVALID_SIM_SLOT_INDEX); |
| 158 | CarrierTextController.CarrierTextCallbackInfo |
| 159 | c4 = new CarrierTextController.CarrierTextCallbackInfo( |
| 160 | "", |
| 161 | new CharSequence[]{"", ""}, |
| 162 | true, |
| 163 | new int[]{0, 1}); |
| 164 | spiedCarrierGroup.updateCarrierInfo(c4); |
| 165 | } |
| 166 | |
| 167 | @Test // throws no Exception |
| 168 | public void testSetMobileDataIndicators_invalidSim() { |
| 169 | QSCarrierGroup spiedCarrierGroup = Mockito.spy(mCarrierGroup); |
| 170 | when(spiedCarrierGroup.getSlotIndex(anyInt())).thenReturn( |
| 171 | SubscriptionManager.INVALID_SIM_SLOT_INDEX); |
| 172 | spiedCarrierGroup.setMobileDataIndicators( |
| 173 | mock(NetworkController.IconState.class), |
| 174 | mock(NetworkController.IconState.class), |
| 175 | 0, 0, true, true, "", "", true, 0, true); |
| 176 | } |
| 177 | } |