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

Commit 9424749d authored by Youngjun Kwak's avatar Youngjun Kwak Committed by Automerger Merge Worker
Browse files

Merge "Fix flaky test in ConnectedDeviceVoiceRecognitionNotifierTest." into...

Merge "Fix flaky test in ConnectedDeviceVoiceRecognitionNotifierTest." into rvc-qpr-dev am: 96540963 am: 6edd2af4

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/12300500

Change-Id: Iaa5099ad1eb2cc4e63332beb93e3e30919719c00
parents 116f1190 6edd2af4
Loading
Loading
Loading
Loading
+27 −6
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ package com.android.systemui.car.voicerecognition;
import static com.android.systemui.car.voicerecognition.ConnectedDeviceVoiceRecognitionNotifier.INVALID_VALUE;
import static com.android.systemui.car.voicerecognition.ConnectedDeviceVoiceRecognitionNotifier.VOICE_RECOGNITION_STARTED;

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
@@ -40,11 +42,13 @@ import com.android.systemui.car.CarSystemUiTest;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;

@CarSystemUiTest
@RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper
@SmallTest
// TODO(b/162866441): Refactor to use the Executor pattern instead.
public class ConnectedDeviceVoiceRecognitionNotifierTest extends SysuiTestCase {

    private static final String BLUETOOTH_PERM = android.Manifest.permission.BLUETOOTH;
@@ -52,13 +56,15 @@ public class ConnectedDeviceVoiceRecognitionNotifierTest extends SysuiTestCase {

    private ConnectedDeviceVoiceRecognitionNotifier mVoiceRecognitionNotifier;
    private TestableLooper mTestableLooper;
    private Handler mHandler;
    private Handler mTestHandler;
    private BluetoothDevice mBluetoothDevice;

    @Before
    public void setUp() throws Exception {
        mTestableLooper = TestableLooper.get(this);
        mTestHandler = spy(new Handler(mTestableLooper.getLooper()));
        mHandler = new Handler(mTestableLooper.getLooper());
        mTestHandler = spy(mHandler);
        mBluetoothDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(
                BLUETOOTH_REMOTE_ADDRESS);
        mVoiceRecognitionNotifier = new ConnectedDeviceVoiceRecognitionNotifier(
@@ -74,8 +80,14 @@ public class ConnectedDeviceVoiceRecognitionNotifierTest extends SysuiTestCase {

        mContext.sendBroadcast(intent, BLUETOOTH_PERM);
        mTestableLooper.processAllMessages();

        verify(mTestHandler).post(any());
        waitForIdleSync();

        mHandler.post(() -> {
            ArgumentCaptor<Runnable> argumentCaptor = ArgumentCaptor.forClass(Runnable.class);
            verify(mTestHandler).post(argumentCaptor.capture());
            assertThat(argumentCaptor.getValue()).isNotNull();
            assertThat(argumentCaptor.getValue()).isNotEqualTo(this);
        });
    }

    @Test
@@ -86,8 +98,11 @@ public class ConnectedDeviceVoiceRecognitionNotifierTest extends SysuiTestCase {

        mContext.sendBroadcast(intent, BLUETOOTH_PERM);
        mTestableLooper.processAllMessages();
        waitForIdleSync();

        mHandler.post(() -> {
            verify(mTestHandler, never()).post(any());
        });
    }

    @Test
@@ -97,8 +112,11 @@ public class ConnectedDeviceVoiceRecognitionNotifierTest extends SysuiTestCase {

        mContext.sendBroadcast(intent, BLUETOOTH_PERM);
        mTestableLooper.processAllMessages();
        waitForIdleSync();

        mHandler.post(() -> {
            verify(mTestHandler, never()).post(any());
        });
    }

    @Test
@@ -108,7 +126,10 @@ public class ConnectedDeviceVoiceRecognitionNotifierTest extends SysuiTestCase {

        mContext.sendBroadcast(intent, BLUETOOTH_PERM);
        mTestableLooper.processAllMessages();
        waitForIdleSync();

        mHandler.post(() -> {
            verify(mTestHandler, never()).post(any());
        });
    }
}