fix the incorrect test from aog/643407

this is tested on pi-dev first: ag/3778561

Bug: 74609188
Test: tested manually by doing this from packages/apps/Blueooth dir: runtest --path tests/unit/src/com/android/bluetooth/mapclient/MapClientStateMachineTest.java
Change-Id: I4c828533bb35b216e8d09c961f395bf42a9705ab
diff --git a/tests/unit/src/com/android/bluetooth/mapclient/MapClientStateMachineTest.java b/tests/unit/src/com/android/bluetooth/mapclient/MapClientStateMachineTest.java
index 700f91f..6b0bf69 100644
--- a/tests/unit/src/com/android/bluetooth/mapclient/MapClientStateMachineTest.java
+++ b/tests/unit/src/com/android/bluetooth/mapclient/MapClientStateMachineTest.java
@@ -119,7 +119,21 @@
         setupSdpRecordReceipt();
         Message msg = Message.obtain(mHandler, MceStateMachine.MSG_MAS_DISCONNECTED);
         mMceStateMachine.getCurrentState().processMessage(msg);
-        Assert.assertEquals(BluetoothProfile.STATE_CONNECTING, mMceStateMachine.getState());
+
+        // Wait until the message is processed and a broadcast request is sent to
+        // to MapClientService to change
+        // state from STATE_CONNECTING to STATE_DISCONNECTED
+        boolean result = false;
+        try {
+            result = mDisconnectedLatch.await(TIMEOUT, TimeUnit.MILLISECONDS);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+        // Test that the latch reached zero; i.e., that a broadcast of state-change was received.
+        Assert.assertTrue(result);
+        // When the state reaches STATE_DISCONNECTED, MceStateMachine object is in the process of
+        // being dismantled; i.e., can't rely on getting its current state. That means can't
+        // test its current state = STATE_DISCONNECTED.
     }
 
     /**
@@ -136,12 +150,14 @@
         // Wait until the message is processed and a broadcast request is sent to
         // to MapClientService to change
         // state from STATE_CONNECTING to STATE_CONNECTED
+        boolean result = false;
         try {
-            mDisconnectedLatch.await(TIMEOUT, TimeUnit.MILLISECONDS);
+            result = mConnectedLatch.await(TIMEOUT, TimeUnit.MILLISECONDS);
         } catch (InterruptedException e) {
             e.printStackTrace();
         }
-        Assert.assertNotNull(mMceStateMachine.getCurrentState());
+        // Test that the latch reached zero; i.e., that a broadcast of state-change was received.
+        Assert.assertTrue(result);
         Assert.assertEquals(BluetoothProfile.STATE_CONNECTED, mMceStateMachine.getState());
     }
 
@@ -159,6 +175,8 @@
         public void sendBroadcast(Intent intent, String receiverPermission) {
             int prevState = intent.getIntExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, -1);
             int state = intent.getIntExtra(BluetoothProfile.EXTRA_STATE, -1);
+            Log.i(TAG, "received broadcast: prevState = " + prevState
+                    + ", state = " + state);
             if (prevState == BluetoothProfile.STATE_CONNECTING
                     && state == BluetoothProfile.STATE_CONNECTED) {
                 mConnectedLatch.countDown();