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

Commit 9c96807d authored by Jack Yu's avatar Jack Yu
Browse files

Test infrastructure improvement and code clean up.

Added instance replacement infrastructure and auto-restore functionality.
Cleauped up test cases.
Fixed copyright year.

bug: 25691379
Change-Id: I7e9b0b121c38c3a2c7375b262e2a121abb9c9a59
parent 3c3afb81
Loading
Loading
Loading
Loading
+8 −10
Original line number Diff line number Diff line
@@ -15,17 +15,21 @@
 */
package com.android.internal.telephony;

import android.icu.impl.Assert;
import android.os.Handler;
import android.os.HandlerThread;
import android.telephony.PhoneNumberUtils;
import android.telephony.ServiceState;
import android.test.suitebuilder.annotation.SmallTest;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.junit.Test;

import java.lang.reflect.Field;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -38,12 +42,8 @@ import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import android.telephony.ServiceState;
import android.telephony.PhoneNumberUtils;
import java.lang.reflect.Field;

public class CallManagerTest extends TelephonyTest {
    private CallManager mCallManager = CallManager.getInstance();

    @Mock
    GsmCdmaCall mFgCall;
    @Mock
@@ -66,9 +66,7 @@ public class CallManagerTest extends TelephonyTest {
    @Before
    public void setUp() throws Exception {
        super.setUp(this.getClass().getSimpleName());
        Field field = CallManager.class.getDeclaredField("INSTANCE");
        field.setAccessible(true);
        field.set(null, mCallManager);
        restoreInstance(CallManager.class, "INSTANCE", null);
        /* Mock Phone and Call, initially all calls are idle */
        doReturn(ServiceState.STATE_IN_SERVICE).when(mServiceState).getState();
        doReturn(mServiceState).when(mPhone).getServiceState();
+1 −1
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 * 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.
+1 −1
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 * 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.
+9 −28
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 * 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.
@@ -21,43 +21,27 @@ import android.os.Looper;
import android.telephony.PhoneNumberUtils;
import android.test.suitebuilder.annotation.SmallTest;
import android.test.suitebuilder.annotation.MediumTest;
import android.util.Log;
import android.telephony.DisconnectCause;
import com.android.internal.telephony.test.SimulatedCommands;

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.lang.reflect.Field;

public class GsmCdmaConnectionTest {
    private static final String TAG = "GsmCdmaConnectionTest";
    private ContextFixture mContextFixture;
public class GsmCdmaConnectionTest extends TelephonyTest {

    private GsmCdmaConnection connection;
    private SimulatedCommands mCi;

    @Mock
    GsmCdmaPhone mPhone;
    @Mock
    GsmCdmaCallTracker mCT;
    @Mock
    DriverCall mDC;

    @Before
    public void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);
        mContextFixture = new ContextFixture();
        mCi = new SimulatedCommands();

        Field field = Handler.class.getDeclaredField("mLooper");
        field.setAccessible(true);
        field.set(mCT, Looper.getMainLooper());
        mCT.mCi = mCi;
        doReturn(mContextFixture.getTestDouble()).when(mPhone).getContext();
        doReturn(mPhone).when(mCT).getPhone();
        super.setUp(getClass().getSimpleName());
        replaceInstance(Handler.class, "mLooper", mCT, Looper.getMainLooper());

        doReturn(PhoneConstants.PHONE_TYPE_GSM).when(mPhone).getPhoneType();
        mCT.mForegroundCall = new GsmCdmaCall(mCT);
        mCT.mBackgroundCall = new GsmCdmaCall(mCT);
@@ -67,6 +51,7 @@ public class GsmCdmaConnectionTest {
    @After
    public void tearDown() throws Exception {
        connection = null;
        super.tearDown();
    }

    @Test @SmallTest
@@ -198,8 +183,4 @@ public class GsmCdmaConnectionTest {
        assertEquals(connection.getDisconnectCause(), DisconnectCause.LOCAL);
        assertTrue(connection.getDisconnectTime() <= System.currentTimeMillis());
    }

    private static void logd(String s) {
        Log.d(TAG, s);
    }
}
+1 −1
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 * 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.
Loading