Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit db0b156c authored by Chen Xu's avatar Chen Xu Committed by Android (Google) Code Review
Browse files

Merge "First Unit test for DefaultPhoneNotifier" into nyc-dev

parents 7a537e99 ec6e2f9f
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -47,8 +47,7 @@ public class DefaultPhoneNotifier implements PhoneNotifier {

    protected ITelephonyRegistry mRegistry;

    /*package*/
    protected DefaultPhoneNotifier() {
    public DefaultPhoneNotifier() {
        mRegistry = ITelephonyRegistry.Stub.asInterface(ServiceManager.getService(
                    "telephony.registry"));
    }
+123 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.internal.telephony;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;

import java.util.List;
import java.util.ArrayList;

import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.verify;
import org.mockito.ArgumentCaptor;
import android.telephony.CellInfo;
import android.telephony.SignalStrength;
import android.telephony.TelephonyManager;
import android.test.suitebuilder.annotation.SmallTest;
import com.android.internal.telephony.mocks.TelephonyRegistryMock;

public class DefaultPhoneNotifierTest extends TelephonyTest {

    private DefaultPhoneNotifier mDefaultPhoneNotifierUT;
    @Mock
    TelephonyRegistryMock mTelephonyRegisteryMock;
    @Mock
    SignalStrength mSignalStrength;
    @Mock
    CellInfo mCellInfo;

    @Before
    public void setUp() throws Exception {
        super.setUp(getClass().getSimpleName());
        mServiceManagerMockedServices.put("telephony.registry", mTelephonyRegisteryMock);
        doReturn(mTelephonyRegisteryMock).when(mTelephonyRegisteryMock)
                .queryLocalInterface(anyString());

        mDefaultPhoneNotifierUT = new DefaultPhoneNotifier();
    }

    @After
    public void tearDown() throws Exception {
        super.tearDown();
    }

    @Test @SmallTest
    public void testNotifyCallForwarding() throws Exception {
        mDefaultPhoneNotifierUT.notifyCallForwardingChanged(mPhone);
        verify(mTelephonyRegisteryMock).notifyCallForwardingChangedForSubscriber(eq(0), eq(false));

        doReturn(true).when(mPhone).getCallForwardingIndicator();
        doReturn(1).when(mPhone).getSubId();
        mDefaultPhoneNotifierUT.notifyCallForwardingChanged(mPhone);
        verify(mTelephonyRegisteryMock).notifyCallForwardingChangedForSubscriber(eq(1), eq(true));
    }

    @Test @SmallTest
    public void testNotifyDataActivity() throws Exception {
        //mock data activity state
        doReturn(Phone.DataActivityState.NONE).when(mPhone).getDataActivityState();
        mDefaultPhoneNotifierUT.notifyDataActivity(mPhone);
        verify(mTelephonyRegisteryMock).notifyDataActivityForSubscriber(eq(0),
                eq(TelephonyManager.DATA_ACTIVITY_NONE));

        doReturn(1).when(mPhone).getSubId();
        doReturn(Phone.DataActivityState.DATAIN).when(mPhone).getDataActivityState();
        mDefaultPhoneNotifierUT.notifyDataActivity(mPhone);
        verify(mTelephonyRegisteryMock).notifyDataActivityForSubscriber(eq(1),
                eq(TelephonyManager.DATA_ACTIVITY_IN));
    }

    @Test @SmallTest
    public void testNotifySignalStrength() throws Exception {
        //mock signal strength value
        doReturn(99).when(mSignalStrength).getGsmSignalStrength();
        doReturn(mSignalStrength).when(mPhone).getSignalStrength();
        ArgumentCaptor<SignalStrength> signalStrengthArgumentCaptor =
                ArgumentCaptor.forClass(SignalStrength.class);

        mDefaultPhoneNotifierUT.notifySignalStrength(mPhone);
        verify(mTelephonyRegisteryMock).notifySignalStrengthForSubscriber(eq(0),
                signalStrengthArgumentCaptor.capture());
        assertEquals(99, signalStrengthArgumentCaptor.getValue().getGsmSignalStrength());

        doReturn(1).when(mPhone).getSubId();
        mDefaultPhoneNotifierUT.notifySignalStrength(mPhone);
        verify(mTelephonyRegisteryMock).notifySignalStrengthForSubscriber(eq(1),
                signalStrengthArgumentCaptor.capture());
        assertEquals(99, signalStrengthArgumentCaptor.getValue().getGsmSignalStrength());
    }

    @Test @SmallTest
    public void testNotifyCellInfo() throws Exception {
        //mock cellinfo
        List<CellInfo> mCellInfoList = new ArrayList<>();
        mCellInfoList.add(mCellInfo);
        ArgumentCaptor<List> cellInfoArgumentCaptor = ArgumentCaptor.forClass(List.class);

        mDefaultPhoneNotifierUT.notifyCellInfo(mPhone, mCellInfoList);

        verify(mTelephonyRegisteryMock).notifyCellInfoForSubscriber(eq(0),
                cellInfoArgumentCaptor.capture());
        assertEquals(mCellInfo, cellInfoArgumentCaptor.getValue().get(0));
    }

}
+0 −6
Original line number Diff line number Diff line
@@ -34,17 +34,12 @@ import static org.mockito.Mockito.eq;
import org.junit.Test;
import org.mockito.Mock;

import android.os.IBinder;
import android.os.ServiceManager;
import android.telephony.TelephonyManager;

import android.test.suitebuilder.annotation.SmallTest;

import java.util.HashMap;

public class PhoneSubInfoControllerTest extends TelephonyTest {
    private PhoneSubInfoController mPhoneSubInfoControllerUT;
    private HashMap<String, IBinder> mServiceManagerMockedServices = new HashMap<>();
    private AppOpsManager mAppOsMgr;

    @Mock
@@ -61,7 +56,6 @@ public class PhoneSubInfoControllerTest extends TelephonyTest {
                Context.TELEPHONY_SERVICE);
        doReturn(2).when(mTelephonyManager).getPhoneCount();

        replaceInstance(ServiceManager.class, "sCache", null, mServiceManagerMockedServices);
        mServiceManagerMockedServices.put("isub", mSubscriptionController);
        doReturn(mSubscriptionController).when(mSubscriptionController)
                .queryLocalInterface(anyString());
+0 −13
Original line number Diff line number Diff line
@@ -21,9 +21,7 @@ import android.content.Intent;
import android.os.AsyncResult;
import android.os.Bundle;
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.Parcel;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.telephony.CellInfo;
import android.telephony.CellInfoGsm;
@@ -37,9 +35,6 @@ import android.test.suitebuilder.annotation.MediumTest;
import com.android.internal.telephony.dataconnection.DcTracker;
import com.android.internal.telephony.test.SimulatedCommands;
import com.android.internal.telephony.uicc.IccCardApplicationStatus;
import com.android.internal.telephony.uicc.SIMRecords;
import com.android.internal.telephony.uicc.UiccCardApplication;
import com.android.internal.telephony.uicc.UiccController;

import static com.android.internal.telephony.TelephonyTestUtils.waitForMs;
import static org.junit.Assert.*;
@@ -58,7 +53,6 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Mock;

import java.util.ArrayList;
import java.util.HashMap;

public class ServiceStateTrackerTest extends TelephonyTest {

@@ -66,10 +60,6 @@ public class ServiceStateTrackerTest extends TelephonyTest {
    private DcTracker mDct;
    @Mock
    private ProxyController mProxyController;
    @Mock
    HashMap<String, IBinder> mServiceCache;
    @Mock
    IBinder mBinder;

    private ServiceStateTracker sst;
    private TelephonyManager mTelephonyManager;
@@ -98,9 +88,6 @@ public class ServiceStateTrackerTest extends TelephonyTest {
        mTelephonyManager = (TelephonyManager) mContextFixture.getTestDouble().
                getSystemService(Context.TELEPHONY_SERVICE);

        doReturn(mBinder).when(mServiceCache).get(anyString());

        replaceInstance(ServiceManager.class, "sCache", null, mServiceCache);
        replaceInstance(ProxyController.class, "sProxyController", null, mProxyController);

        mContextFixture.putStringArrayResource(
+0 −9
Original line number Diff line number Diff line
@@ -17,8 +17,6 @@
package com.android.internal.telephony;

import android.os.IBinder;
import android.os.ServiceManager;
import android.telephony.SmsManager;
import android.telephony.TelephonyManager;
import android.test.suitebuilder.annotation.SmallTest;

@@ -28,18 +26,13 @@ import org.junit.Test;
import org.mockito.Mock;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doReturn;

public class Sms7BitEncodingTranslatorTest extends TelephonyTest {

    @Mock
    HashMap<String, IBinder> mServiceCache;
    @Mock
    IBinder mBinder;

@@ -48,8 +41,6 @@ public class Sms7BitEncodingTranslatorTest extends TelephonyTest {
        logd("+Setup!");
        super.setUp(getClass().getSimpleName());

        doReturn(mBinder).when(mServiceCache).get(anyString());
        replaceInstance(ServiceManager.class, "sCache", null, mServiceCache);
        logd("-Setup!");
    }

Loading