ModifierShortcutTest improvement

 - After each assertion of shortcut role/category, reset invocation
   count rather than the whole mock (which clears all the stubbing).
   This is needed for an upcoming change where we will need to keep stubs
   intact during test cases
 - Correct ordering for expected, actual in assertion

Flag: TEST_ONLY
Bug: 351963350
Test: atest ModifierShortcutTests
Change-Id: Ib99310a4a310ae40a6eea4c6089e172aeb8f1cbb
diff --git a/services/tests/wmtests/src/com/android/server/policy/ModifierShortcutTests.java b/services/tests/wmtests/src/com/android/server/policy/ModifierShortcutTests.java
index 59b08a5..526c351 100644
--- a/services/tests/wmtests/src/com/android/server/policy/ModifierShortcutTests.java
+++ b/services/tests/wmtests/src/com/android/server/policy/ModifierShortcutTests.java
@@ -97,6 +97,7 @@
             mPhoneWindowManager.assertLaunchCategory(category);
         }
 
+        mPhoneWindowManager.overrideRoleManager();
         for (int i = 0; i < ROLE_SHORTCUTS.size(); i++) {
             final int keyCode = ROLE_SHORTCUTS.keyAt(i);
             final String role = ROLE_SHORTCUTS.valueAt(i);
diff --git a/services/tests/wmtests/src/com/android/server/policy/TestPhoneWindowManager.java b/services/tests/wmtests/src/com/android/server/policy/TestPhoneWindowManager.java
index fdb57d1..2b7e7ab 100644
--- a/services/tests/wmtests/src/com/android/server/policy/TestPhoneWindowManager.java
+++ b/services/tests/wmtests/src/com/android/server/policy/TestPhoneWindowManager.java
@@ -568,6 +568,12 @@
         doReturn(isShowing).when(mKeyguardServiceDelegate).isShowing();
     }
 
+    void overrideRoleManager() {
+        doReturn(mContext).when(mContext).createContextAsUser(any(), anyInt());
+        doReturn(mRoleManager).when(mContext).getSystemService(eq(RoleManager.class));
+        doReturn(mPackageManager).when(mContext).getPackageManager();
+    }
+
     void setupAssistForLaunch() {
         doNothing().when(mPhoneWindowManager).sendCloseSystemWindows();
         doReturn(true).when(mPhoneWindowManager).isUserSetupComplete();
@@ -709,7 +715,7 @@
             throw new AssertionError("failed to assert " + category, t);
         }
         // Reset verifier for next call.
-        Mockito.reset(mContext);
+        Mockito.clearInvocations(mContext);
     }
 
     void assertLaunchRole(String role) {
@@ -719,10 +725,10 @@
             verify(mContext).startActivityAsUser(intentCaptor.capture(), any());
             switch (role) {
                 case RoleManager.ROLE_BROWSER:
-                    Assert.assertEquals(intentCaptor.getValue(), mBrowserIntent);
+                    Assert.assertEquals(mBrowserIntent, intentCaptor.getValue());
                     break;
                 case RoleManager.ROLE_SMS:
-                    Assert.assertEquals(intentCaptor.getValue(), mSmsIntent);
+                    Assert.assertEquals(mSmsIntent, intentCaptor.getValue());
                     break;
                 default:
                     throw new AssertionError("Role " + role + " not supported in tests.");
@@ -731,7 +737,7 @@
             throw new AssertionError("failed to assert " + role, t);
         }
         // Reset verifier for next call.
-        Mockito.reset(mContext);
+        Mockito.clearInvocations(mContext);
     }