From 2c91bb46b78e72953e67087a573065ef06eb70d0 Mon Sep 17 00:00:00 2001 From: Adrian Roos Date: Thu, 6 Jul 2023 15:14:26 +0000 Subject: [PATCH] InputMethodSystemServerTests: Make more robust Spying directly on the Context causes real invocations from the framework to interfere with the stubbing. Instead, we create our own spied-on copy of the Context. Change-Id: I108d60389bc4d8a9c5a007cfb63e8a56093cae45 Test: atest InputMethodSystemServerTests --- .../server/inputmethod/InputMethodManagerServiceTestBase.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodManagerServiceTestBase.java b/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodManagerServiceTestBase.java index 1a8e00cab39d4..0ed863e3743ee 100644 --- a/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodManagerServiceTestBase.java +++ b/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodManagerServiceTestBase.java @@ -19,6 +19,7 @@ package com.android.server.inputmethod; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; import static com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSession; +import static com.android.dx.mockito.inline.extended.ExtendedMockito.spy; import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; import static org.mockito.ArgumentMatchers.any; @@ -145,8 +146,7 @@ public class InputMethodManagerServiceTestBase { .mockStatic(SystemServerInitThreadPool.class) .startMocking(); - mContext = InstrumentationRegistry.getInstrumentation().getContext(); - spyOn(mContext); + mContext = spy(InstrumentationRegistry.getInstrumentation().getContext()); mTargetSdkVersion = mContext.getApplicationInfo().targetSdkVersion; mIsLargeScreen = mContext.getResources().getConfiguration()