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

Commit dbf2fdc3 authored by Jordan Liu's avatar Jordan Liu
Browse files

Move AppInfo mock to FakeContext

Mockito occasionally complains due to some odd behavior related
to mocking calls in FakeContext (which is a spy(Context)). We
address this by implementing the function in FakeContext instead of
trying to mock it out later.

Fixes: 80431912
Test: atest CarrierServiceStateTrackerTest.java
Change-Id: I18385d84b85960efc51ea974c275ff6cfbf5cca5
Merged-In: I18385d84b85960efc51ea974c275ff6cfbf5cca5
parent 91d5bf9f
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.HandlerThread;
@@ -104,8 +103,6 @@ public class CarrierServiceStateTrackerTest extends TelephonyTest {

        when(mPhone.getContext().getContentResolver()).thenReturn(mFakeContentResolver);

        doReturn(new ApplicationInfo()).when(mContext).getApplicationInfo();

        mNotificationManager = (NotificationManager) mContext.getSystemService(
                Context.NOTIFICATION_SERVICE);

+7 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
@@ -277,6 +278,11 @@ public class ContextFixture implements TestFixture<Context> {
            return mResources;
        }

        @Override
        public ApplicationInfo getApplicationInfo() {
            return mApplicationInfo;
        }

        @Override
        public String getOpPackageName() {
            return "com.android.internal.telephony";
@@ -526,6 +532,7 @@ public class ContextFixture implements TestFixture<Context> {
    // when(...) logic to be used to add specific little responses where needed.

    private final Resources mResources = mock(Resources.class);
    private final ApplicationInfo mApplicationInfo = mock(ApplicationInfo.class);
    private final PackageManager mPackageManager = mock(PackageManager.class);
    private final TelephonyManager mTelephonyManager = mock(TelephonyManager.class);
    private final DownloadManager mDownloadManager = mock(DownloadManager.class);