Merge "Fix flaky test in ConnectedDeviceVoiceRecognitionNotifierTest." into rvc-qpr-dev am: 96540963a8
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/12300500 Change-Id: I86e9bc6bb1a9a746bbc88fb6a9d770cffb2131db
This commit is contained in:
@@ -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.INVALID_VALUE;
|
||||||
import static com.android.systemui.car.voicerecognition.ConnectedDeviceVoiceRecognitionNotifier.VOICE_RECOGNITION_STARTED;
|
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.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
@@ -40,11 +42,13 @@ import com.android.systemui.car.CarSystemUiTest;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
|
|
||||||
@CarSystemUiTest
|
@CarSystemUiTest
|
||||||
@RunWith(AndroidTestingRunner.class)
|
@RunWith(AndroidTestingRunner.class)
|
||||||
@TestableLooper.RunWithLooper
|
@TestableLooper.RunWithLooper
|
||||||
@SmallTest
|
@SmallTest
|
||||||
|
// TODO(b/162866441): Refactor to use the Executor pattern instead.
|
||||||
public class ConnectedDeviceVoiceRecognitionNotifierTest extends SysuiTestCase {
|
public class ConnectedDeviceVoiceRecognitionNotifierTest extends SysuiTestCase {
|
||||||
|
|
||||||
private static final String BLUETOOTH_PERM = android.Manifest.permission.BLUETOOTH;
|
private static final String BLUETOOTH_PERM = android.Manifest.permission.BLUETOOTH;
|
||||||
@@ -52,13 +56,15 @@ public class ConnectedDeviceVoiceRecognitionNotifierTest extends SysuiTestCase {
|
|||||||
|
|
||||||
private ConnectedDeviceVoiceRecognitionNotifier mVoiceRecognitionNotifier;
|
private ConnectedDeviceVoiceRecognitionNotifier mVoiceRecognitionNotifier;
|
||||||
private TestableLooper mTestableLooper;
|
private TestableLooper mTestableLooper;
|
||||||
|
private Handler mHandler;
|
||||||
private Handler mTestHandler;
|
private Handler mTestHandler;
|
||||||
private BluetoothDevice mBluetoothDevice;
|
private BluetoothDevice mBluetoothDevice;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
mTestableLooper = TestableLooper.get(this);
|
mTestableLooper = TestableLooper.get(this);
|
||||||
mTestHandler = spy(new Handler(mTestableLooper.getLooper()));
|
mHandler = new Handler(mTestableLooper.getLooper());
|
||||||
|
mTestHandler = spy(mHandler);
|
||||||
mBluetoothDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(
|
mBluetoothDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(
|
||||||
BLUETOOTH_REMOTE_ADDRESS);
|
BLUETOOTH_REMOTE_ADDRESS);
|
||||||
mVoiceRecognitionNotifier = new ConnectedDeviceVoiceRecognitionNotifier(
|
mVoiceRecognitionNotifier = new ConnectedDeviceVoiceRecognitionNotifier(
|
||||||
@@ -74,8 +80,14 @@ public class ConnectedDeviceVoiceRecognitionNotifierTest extends SysuiTestCase {
|
|||||||
|
|
||||||
mContext.sendBroadcast(intent, BLUETOOTH_PERM);
|
mContext.sendBroadcast(intent, BLUETOOTH_PERM);
|
||||||
mTestableLooper.processAllMessages();
|
mTestableLooper.processAllMessages();
|
||||||
|
waitForIdleSync();
|
||||||
|
|
||||||
verify(mTestHandler).post(any());
|
mHandler.post(() -> {
|
||||||
|
ArgumentCaptor<Runnable> argumentCaptor = ArgumentCaptor.forClass(Runnable.class);
|
||||||
|
verify(mTestHandler).post(argumentCaptor.capture());
|
||||||
|
assertThat(argumentCaptor.getValue()).isNotNull();
|
||||||
|
assertThat(argumentCaptor.getValue()).isNotEqualTo(this);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -86,8 +98,11 @@ public class ConnectedDeviceVoiceRecognitionNotifierTest extends SysuiTestCase {
|
|||||||
|
|
||||||
mContext.sendBroadcast(intent, BLUETOOTH_PERM);
|
mContext.sendBroadcast(intent, BLUETOOTH_PERM);
|
||||||
mTestableLooper.processAllMessages();
|
mTestableLooper.processAllMessages();
|
||||||
|
waitForIdleSync();
|
||||||
|
|
||||||
verify(mTestHandler, never()).post(any());
|
mHandler.post(() -> {
|
||||||
|
verify(mTestHandler, never()).post(any());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -97,8 +112,11 @@ public class ConnectedDeviceVoiceRecognitionNotifierTest extends SysuiTestCase {
|
|||||||
|
|
||||||
mContext.sendBroadcast(intent, BLUETOOTH_PERM);
|
mContext.sendBroadcast(intent, BLUETOOTH_PERM);
|
||||||
mTestableLooper.processAllMessages();
|
mTestableLooper.processAllMessages();
|
||||||
|
waitForIdleSync();
|
||||||
|
|
||||||
verify(mTestHandler, never()).post(any());
|
mHandler.post(() -> {
|
||||||
|
verify(mTestHandler, never()).post(any());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -108,7 +126,10 @@ public class ConnectedDeviceVoiceRecognitionNotifierTest extends SysuiTestCase {
|
|||||||
|
|
||||||
mContext.sendBroadcast(intent, BLUETOOTH_PERM);
|
mContext.sendBroadcast(intent, BLUETOOTH_PERM);
|
||||||
mTestableLooper.processAllMessages();
|
mTestableLooper.processAllMessages();
|
||||||
|
waitForIdleSync();
|
||||||
|
|
||||||
verify(mTestHandler, never()).post(any());
|
mHandler.post(() -> {
|
||||||
|
verify(mTestHandler, never()).post(any());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user