diff options
author | Jeff Chang <chengjeff@google.com> | 2019-12-26 21:38:13 +0800 |
---|---|---|
committer | Jeff Chang <chengjeff@google.com> | 2019-12-26 22:02:46 +0800 |
commit | 6d12c9c94046ea71bf37b41595022d2460bcdf31 (patch) | |
tree | 5e197f59562342cd610f785a844530e3a8454c98 /core/tests/mockingcoretests | |
parent | baa2cea8c362d54e763be5b316e5fbd8bcd3fc28 (diff) |
Attempt to fix the ActivityThreadClientTest test case failed.
ActivityThreadclient test case failed in emulator environment, but they
always work successfully on devices. This CL try to fix the test
case failed by mocking the LoadApk#updateApplicationInfo function
because the purpose of the test focuses on activity client state changes
behavior.
Bug: 144675058
Test: atest FrameworksMockingCoreTests:android.app.activity.ActivityThreadClientTest
Change-Id: I8bec296b65a4e688166fde0f2803bdb06d981a30
Diffstat (limited to 'core/tests/mockingcoretests')
-rw-r--r-- | core/tests/mockingcoretests/src/android/app/activity/ActivityThreadClientTest.java | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/core/tests/mockingcoretests/src/android/app/activity/ActivityThreadClientTest.java b/core/tests/mockingcoretests/src/android/app/activity/ActivityThreadClientTest.java index 364e4ea6e3ec..9863e389cb5e 100644 --- a/core/tests/mockingcoretests/src/android/app/activity/ActivityThreadClientTest.java +++ b/core/tests/mockingcoretests/src/android/app/activity/ActivityThreadClientTest.java @@ -25,10 +25,12 @@ import static android.app.servertransaction.ActivityLifecycleItem.ON_STOP; 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.spyOn; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.when; import android.app.Activity; @@ -36,6 +38,7 @@ import android.app.ActivityTaskManager; import android.app.ActivityThread; import android.app.ActivityThread.ActivityClientRecord; import android.app.IActivityTaskManager; +import android.app.LoadedApk; import android.app.servertransaction.PendingTransactionActions; import android.content.ComponentName; import android.content.Intent; @@ -346,6 +349,14 @@ public class ActivityThreadClientTest { info.applicationInfo.packageName = info.packageName; info.applicationInfo.uid = UserHandle.myUserId(); + // mock the function for preventing NPE in emulator environment. The purpose of the + // test is for activity client state changes, we don't focus on the updating for the + // ApplicationInfo. + LoadedApk packageInfo = mThread.peekPackageInfo(info.packageName, + true /* includeCode */); + spyOn(packageInfo); + doNothing().when(packageInfo).updateApplicationInfo(any(), any()); + return new ActivityClientRecord(new Binder(), Intent.makeMainActivity(component), 0 /* ident */, info, new Configuration(), CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null /* referrer */, |