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

Commit 8f56b0e3 authored by Eliot Courtney's avatar Eliot Courtney
Browse files

Change all mocks that are Dependencys to be properly injected.

If a class being unit tested is changed to Dependency.get() a dependency
rather than receiving it as an argument, the tests could break in subtle
ways. Make sure all mocked Dependencys are properly injected as test
dependencies.

Bug: 63874929
Bug: 62602530
Test: runtest systemui
Change-Id: I2b23a2ea0ac9067952624a5c302ca419685307ae
parent 2b4c3a08
Loading
Loading
Loading
Loading
+24 −8
Original line number Diff line number Diff line
@@ -73,22 +73,24 @@ public class NotificationEntryManagerTest extends SysuiTestCase {

    @Mock private NotificationPresenter mPresenter;
    @Mock private ExpandableNotificationRow mRow;
    @Mock private NotificationListContainer mListContainer;
    @Mock private NotificationEntryManager.Callback mCallback;
    @Mock private HeadsUpManager mHeadsUpManager;
    @Mock private NotificationListenerService.RankingMap mRankingMap;
    @Mock private RemoteInputController mRemoteInputController;
    @Mock private IStatusBarService mBarService;

    // Dependency mocks:
    @Mock private ForegroundServiceController mForegroundServiceController;
    @Mock private NotificationLockscreenUserManager mLockscreenUserManager;
    @Mock private NotificationGroupManager mGroupManager;
    @Mock private NotificationGutsManager mGutsManager;
    @Mock private NotificationRemoteInputManager mRemoteInputManager;
    @Mock private NotificationMediaManager mMediaManager;
    @Mock private ForegroundServiceController mForegroundServiceController;
    @Mock private NotificationListener mNotificationListener;
    @Mock private MetricsLogger mMetricsLogger;
    @Mock private DeviceProvisionedController mDeviceProvisionedController;
    @Mock private VisualStabilityManager mVisualStabilityManager;
    @Mock private NotificationListContainer mListContainer;
    @Mock private NotificationEntryManager.Callback mCallback;
    @Mock private HeadsUpManager mHeadsUpManager;
    @Mock private NotificationListenerService.RankingMap mRankingMap;
    @Mock private RemoteInputController mRemoteInputController;
    @Mock private IStatusBarService mBarService;
    @Mock private MetricsLogger mMetricsLogger;

    private NotificationData.Entry mEntry;
    private StatusBarNotification mSbn;
@@ -135,6 +137,20 @@ public class NotificationEntryManagerTest extends SysuiTestCase {
    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        mDependency.injectTestDependency(ForegroundServiceController.class,
                mForegroundServiceController);
        mDependency.injectTestDependency(NotificationLockscreenUserManager.class,
                mLockscreenUserManager);
        mDependency.injectTestDependency(NotificationGroupManager.class, mGroupManager);
        mDependency.injectTestDependency(NotificationGutsManager.class, mGutsManager);
        mDependency.injectTestDependency(NotificationRemoteInputManager.class, mRemoteInputManager);
        mDependency.injectTestDependency(NotificationMediaManager.class, mMediaManager);
        mDependency.injectTestDependency(NotificationListener.class, mNotificationListener);
        mDependency.injectTestDependency(DeviceProvisionedController.class,
                mDeviceProvisionedController);
        mDependency.injectTestDependency(VisualStabilityManager.class, mVisualStabilityManager);
        mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger);

        mHandler = new Handler(Looper.getMainLooper());
        mCountDownLatch = new CountDownLatch(1);

+16 −12
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.systemui.statusbar;
import static junit.framework.Assert.assertTrue;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@@ -38,6 +37,8 @@ import com.android.systemui.SysuiTestCase;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.util.HashSet;
import java.util.Set;
@@ -49,24 +50,27 @@ public class NotificationListenerTest extends SysuiTestCase {
    private static final String TEST_PACKAGE_NAME = "test";
    private static final int TEST_UID = 0;

    private NotificationPresenter mPresenter;
    private Handler mHandler;
    @Mock private NotificationPresenter mPresenter;
    @Mock private NotificationListenerService.RankingMap mRanking;
    @Mock private NotificationData mNotificationData;

    // Dependency mocks:
    @Mock private NotificationEntryManager mEntryManager;
    @Mock private NotificationRemoteInputManager mRemoteInputManager;

    private NotificationListener mListener;
    private Handler mHandler;
    private StatusBarNotification mSbn;
    private NotificationListenerService.RankingMap mRanking;
    private Set<String> mKeysKeptForRemoteInput;
    private NotificationData mNotificationData;
    private NotificationRemoteInputManager mRemoteInputManager;
    private NotificationEntryManager mEntryManager;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        mDependency.injectTestDependency(NotificationEntryManager.class, mEntryManager);
        mDependency.injectTestDependency(NotificationRemoteInputManager.class,
                mRemoteInputManager);

        mHandler = new Handler(Looper.getMainLooper());
        mPresenter = mock(NotificationPresenter.class);
        mNotificationData = mock(NotificationData.class);
        mRanking = mock(NotificationListenerService.RankingMap.class);
        mRemoteInputManager = mock(NotificationRemoteInputManager.class);
        mEntryManager = mock(NotificationEntryManager.class);
        mKeysKeptForRemoteInput = new HashSet<>();

        when(mPresenter.getHandler()).thenReturn(mHandler);
+14 −13
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import static android.content.Intent.ACTION_USER_SWITCHED;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -49,26 +48,30 @@ import com.google.android.collect.Lists;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

@SmallTest
@RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper
public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
    private NotificationPresenter mPresenter;
    private NotificationEntryManager mEntryManager;
    private TestNotificationLockscreenUserManager mLockscreenUserManager;
    private DeviceProvisionedController mDeviceProvisionedController;
    @Mock private NotificationPresenter mPresenter;
    @Mock private UserManager mUserManager;

    // Dependency mocks:
    @Mock private NotificationEntryManager mEntryManager;
    @Mock private DeviceProvisionedController mDeviceProvisionedController;

    private int mCurrentUserId;
    private Handler mHandler;
    private UserManager mUserManager;
    private TestNotificationLockscreenUserManager mLockscreenUserManager;

    @Before
    public void setUp() {
        mUserManager = mock(UserManager.class);
        mPresenter = mock(NotificationPresenter.class);
        mEntryManager = mock(NotificationEntryManager.class);
        mDependency.injectMockDependency(DeviceProvisionedController.class);
        mDeviceProvisionedController = mDependency.get(DeviceProvisionedController.class);
        MockitoAnnotations.initMocks(this);
        mDependency.injectTestDependency(NotificationEntryManager.class, mEntryManager);
        mDependency.injectTestDependency(DeviceProvisionedController.class,
                mDeviceProvisionedController);

        mHandler = new Handler(Looper.getMainLooper());
        mContext.addMockSystemService(UserManager.class, mUserManager);
@@ -80,8 +83,6 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
        when(mPresenter.getEntryManager()).thenReturn(mEntryManager);

        mLockscreenUserManager = new TestNotificationLockscreenUserManager(mContext);
        mDependency.injectTestDependency(NotificationLockscreenUserManager.class,
                mLockscreenUserManager);
        mLockscreenUserManager.setUpWithPresenter(mPresenter);
    }

+6 −2
Original line number Diff line number Diff line
@@ -54,13 +54,15 @@ public class NotificationLoggerTest extends SysuiTestCase {
    private static final int TEST_UID = 0;

    @Mock private NotificationPresenter mPresenter;
    @Mock private NotificationEntryManager mEntryManager;
    @Mock private NotificationListener mListener;
    @Mock private NotificationListContainer mListContainer;
    @Mock private IStatusBarService mBarService;
    @Mock private NotificationData mNotificationData;
    @Mock private ExpandableNotificationRow mRow;

    // Dependency mocks:
    @Mock private NotificationEntryManager mEntryManager;
    @Mock private NotificationListener mListener;

    private NotificationData.Entry mEntry;
    private StatusBarNotification mSbn;
    private TestableNotificationLogger mLogger;
@@ -68,6 +70,8 @@ public class NotificationLoggerTest extends SysuiTestCase {
    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        mDependency.injectTestDependency(NotificationEntryManager.class, mEntryManager);
        mDependency.injectTestDependency(NotificationListener.class, mListener);

        when(mPresenter.getEntryManager()).thenReturn(mEntryManager);
        when(mEntryManager.getNotificationData()).thenReturn(mNotificationData);
+12 −7
Original line number Diff line number Diff line
@@ -34,23 +34,28 @@ public class NotificationRemoteInputManagerTest extends SysuiTestCase {
    private static final String TEST_PACKAGE_NAME = "test";
    private static final int TEST_UID = 0;

    private Handler mHandler;
    private TestableNotificationRemoteInputManager mRemoteInputManager;
    private StatusBarNotification mSbn;
    private NotificationData.Entry mEntry;

    @Mock private NotificationPresenter mPresenter;
    @Mock private NotificationEntryManager mEntryManager;
    @Mock private RemoteInputController.Delegate mDelegate;
    @Mock private NotificationLockscreenUserManager mLockscreenUserManager;
    @Mock private NotificationRemoteInputManager.Callback mCallback;
    @Mock private RemoteInputController mController;
    @Mock private NotificationListenerService.RankingMap mRanking;
    @Mock private ExpandableNotificationRow mRow;

    // Dependency mocks:
    @Mock private NotificationEntryManager mEntryManager;
    @Mock private NotificationLockscreenUserManager mLockscreenUserManager;

    private Handler mHandler;
    private TestableNotificationRemoteInputManager mRemoteInputManager;
    private StatusBarNotification mSbn;
    private NotificationData.Entry mEntry;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        mDependency.injectTestDependency(NotificationEntryManager.class, mEntryManager);
        mDependency.injectTestDependency(NotificationLockscreenUserManager.class,
                mLockscreenUserManager);
        mHandler = new Handler(Looper.getMainLooper());

        when(mPresenter.getHandler()).thenReturn(mHandler);
Loading