Make TelecomSystemTest compatible with code coverage
Creates a few implementations of interfaces to spy on to avoid mysterious exceptions resulting from interactions between Mockito and Emma. Change-Id: Ie32b1bb101811471722f6e48aa4c5a75f364575c
This commit is contained in:
parent
fd3a71fb61
commit
ae694b10e9
|
@ -224,6 +224,7 @@ public class CallsManager extends Call.ListenerBase implements VideoProviderProx
|
|||
new ConnectionServiceRepository(mPhoneAccountRegistrar, mContext, mLock, this);
|
||||
mInCallWakeLockController = inCallWakeLockControllerFactory.create(context, this);
|
||||
|
||||
mListeners.add(mInCallWakeLockController);
|
||||
mListeners.add(statusBarNotifier);
|
||||
mListeners.add(mCallLogManager);
|
||||
mListeners.add(mPhoneStateBroadcaster);
|
||||
|
|
|
@ -41,8 +41,6 @@ public class InCallWakeLockController extends CallsManagerListenerBase {
|
|||
PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
|
||||
mFullWakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, TAG);
|
||||
mFullWakeLock.setReferenceCounted(false);
|
||||
|
||||
callsManager.addListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -128,7 +128,6 @@ public final class TelecomSystem {
|
|||
BluetoothManager bluetoothManager = new BluetoothManager(mContext);
|
||||
WiredHeadsetManager wiredHeadsetManager = new WiredHeadsetManager(mContext);
|
||||
|
||||
|
||||
mCallsManager = new CallsManager(
|
||||
mContext,
|
||||
mLock,
|
||||
|
|
|
@ -39,6 +39,9 @@ LOCAL_AAPT_FLAGS := \
|
|||
--auto-add-overlay \
|
||||
--extra-packages com.android.server.telecom
|
||||
|
||||
LOCAL_JACK_ENABLED := disabled
|
||||
LOCAL_PROGUARD_ENABLED := disabled
|
||||
|
||||
LOCAL_PACKAGE_NAME := TelecomUnitTests
|
||||
LOCAL_CERTIFICATE := platform
|
||||
|
||||
|
|
|
@ -18,9 +18,7 @@ package com.android.server.telecom.tests;
|
|||
|
||||
import com.android.server.telecom.Log;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.os.Looper;
|
||||
|
||||
/**
|
||||
* Helper for Mockito-based test cases.
|
||||
|
@ -28,10 +26,6 @@ import android.os.Looper;
|
|||
public final class MockitoHelper {
|
||||
private static final String DEXCACHE = "dexmaker.dexcache";
|
||||
|
||||
private Thread mRequestThread;
|
||||
private ClassLoader mRequestThreadOriginalClassLoader;
|
||||
private ClassLoader mMainThreadOriginalClassLoader;
|
||||
|
||||
/**
|
||||
* Creates a new helper, which in turn will set the context classloader so
|
||||
* it can load Mockito resources.
|
||||
|
@ -39,24 +33,6 @@ public final class MockitoHelper {
|
|||
* @param packageClass test case class
|
||||
*/
|
||||
public void setUp(Context context, Class<?> packageClass) throws Exception {
|
||||
// makes a copy of the context classloader
|
||||
mRequestThread = Thread.currentThread();
|
||||
mRequestThreadOriginalClassLoader = mRequestThread.getContextClassLoader();
|
||||
mMainThreadOriginalClassLoader = Looper.getMainLooper().getThread().getContextClassLoader();
|
||||
|
||||
ClassLoader newClassLoader = packageClass.getClassLoader();
|
||||
|
||||
Log.v(this, "Changing context classloader for thread %s from %s to %s",
|
||||
mRequestThread.getName(),
|
||||
mRequestThreadOriginalClassLoader,
|
||||
newClassLoader);
|
||||
mRequestThread.setContextClassLoader(newClassLoader);
|
||||
|
||||
Log.v(this, "Changing context classloader for MAIN thread from %s to %s",
|
||||
mMainThreadOriginalClassLoader,
|
||||
newClassLoader);
|
||||
Looper.getMainLooper().getThread().setContextClassLoader(newClassLoader);
|
||||
|
||||
String dexCache = context.getCacheDir().toString();
|
||||
Log.v(this, "Setting property %s to %s", DEXCACHE, dexCache);
|
||||
System.setProperty(DEXCACHE, dexCache);
|
||||
|
@ -67,7 +43,6 @@ public final class MockitoHelper {
|
|||
*/
|
||||
public void tearDown() throws Exception {
|
||||
Log.v(this, "Restoring context classloaders");
|
||||
mRequestThread.setContextClassLoader(mRequestThreadOriginalClassLoader);
|
||||
Log.v(this, "Clearing property %s", DEXCACHE);
|
||||
System.clearProperty(DEXCACHE);
|
||||
}
|
||||
|
|
|
@ -26,9 +26,9 @@ import static org.mockito.Mockito.doAnswer;
|
|||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.timeout;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
|
@ -56,7 +56,10 @@ import com.android.internal.telecom.IInCallAdapter;
|
|||
import com.android.server.telecom.BluetoothPhoneServiceImpl;
|
||||
import com.android.server.telecom.CallAudioManager;
|
||||
import com.android.server.telecom.CallIntentProcessor;
|
||||
import com.android.server.telecom.CallerInfoAsyncQueryFactory;
|
||||
import com.android.server.telecom.CallsManager;
|
||||
import com.android.server.telecom.CallsManagerListenerBase;
|
||||
import com.android.server.telecom.ContactsAsyncHelper;
|
||||
import com.android.server.telecom.HeadsetMediaButton;
|
||||
import com.android.server.telecom.HeadsetMediaButtonFactory;
|
||||
import com.android.server.telecom.InCallWakeLockController;
|
||||
|
@ -85,7 +88,49 @@ public class TelecomSystemTest extends TelecomTestCase {
|
|||
static final int TEST_POLL_INTERVAL = 10; // milliseconds
|
||||
static final int TEST_TIMEOUT = 1000; // milliseconds
|
||||
|
||||
@Mock MissedCallNotifier mMissedCallNotifier;
|
||||
public class HeadsetMediaButtonFactoryF implements HeadsetMediaButtonFactory {
|
||||
@Override
|
||||
public HeadsetMediaButton create(Context context, CallsManager callsManager,
|
||||
TelecomSystem.SyncRoot lock) {
|
||||
return mHeadsetMediaButton;
|
||||
}
|
||||
}
|
||||
|
||||
public class ProximitySensorManagerFactoryF implements ProximitySensorManagerFactory {
|
||||
@Override
|
||||
public ProximitySensorManager create(Context context, CallsManager callsManager) {
|
||||
return mProximitySensorManager;
|
||||
}
|
||||
}
|
||||
|
||||
public class InCallWakeLockControllerFactoryF implements InCallWakeLockControllerFactory {
|
||||
@Override
|
||||
public InCallWakeLockController create(Context context, CallsManager callsManager) {
|
||||
return mInCallWakeLockController;
|
||||
}
|
||||
}
|
||||
|
||||
public static class MissedCallNotifierFakeImpl extends CallsManagerListenerBase
|
||||
implements MissedCallNotifier {
|
||||
@Override
|
||||
public void clearMissedCalls() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showMissedCallNotification(com.android.server.telecom.Call call) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateOnStartup(TelecomSystem.SyncRoot lock, CallsManager callsManager,
|
||||
ContactsAsyncHelper contactsAsyncHelper,
|
||||
CallerInfoAsyncQueryFactory callerInfoAsyncQueryFactory) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
MissedCallNotifier mMissedCallNotifier = new MissedCallNotifierFakeImpl();
|
||||
@Mock HeadsetMediaButton mHeadsetMediaButton;
|
||||
@Mock ProximitySensorManager mProximitySensorManager;
|
||||
@Mock InCallWakeLockController mInCallWakeLockController;
|
||||
|
@ -188,30 +233,17 @@ public class TelecomSystemTest extends TelecomTestCase {
|
|||
}
|
||||
|
||||
private void setupTelecomSystem() throws Exception {
|
||||
// Use actual implementations instead of mocking the interface out.
|
||||
HeadsetMediaButtonFactory headsetMediaButtonFactory =
|
||||
mock(HeadsetMediaButtonFactory.class);
|
||||
spy(new HeadsetMediaButtonFactoryF());
|
||||
ProximitySensorManagerFactory proximitySensorManagerFactory =
|
||||
mock(ProximitySensorManagerFactory.class);
|
||||
spy(new ProximitySensorManagerFactoryF());
|
||||
InCallWakeLockControllerFactory inCallWakeLockControllerFactory =
|
||||
mock(InCallWakeLockControllerFactory.class);
|
||||
spy(new InCallWakeLockControllerFactoryF());
|
||||
mAudioService = setupAudioService();
|
||||
|
||||
mCallerInfoAsyncQueryFactoryFixture = new CallerInfoAsyncQueryFactoryFixture();
|
||||
|
||||
when(headsetMediaButtonFactory.create(
|
||||
any(Context.class),
|
||||
any(CallsManager.class),
|
||||
any(TelecomSystem.SyncRoot.class)))
|
||||
.thenReturn(mHeadsetMediaButton);
|
||||
when(proximitySensorManagerFactory.create(
|
||||
any(Context.class),
|
||||
any(CallsManager.class)))
|
||||
.thenReturn(mProximitySensorManager);
|
||||
when(inCallWakeLockControllerFactory.create(
|
||||
any(Context.class),
|
||||
any(CallsManager.class)))
|
||||
.thenReturn(mInCallWakeLockController);
|
||||
|
||||
mTelecomSystem = new TelecomSystem(
|
||||
mComponentContextFixture.getTestDouble(),
|
||||
mMissedCallNotifier,
|
||||
|
@ -296,6 +328,7 @@ public class TelecomSystemTest extends TelecomTestCase {
|
|||
*/
|
||||
private IAudioService setupAudioService() {
|
||||
IAudioService audioService = mock(IAudioService.class);
|
||||
|
||||
final AudioManager fakeAudioManager =
|
||||
(AudioManager) mComponentContextFixture.getTestDouble()
|
||||
.getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
|
||||
|
|
Loading…
Reference in New Issue