Fix test case fail

Bug: 160956047
Test: make -j50 RunSettingsRoboTests
Change-Id: Ib975e906aefc44c59a8465a586832d92664f5147
This commit is contained in:
timhypeng
2020-07-10 21:38:19 +08:00
parent 3d1e9c2ea1
commit b5527e329b
4 changed files with 16 additions and 10 deletions

View File

@@ -22,7 +22,6 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -94,9 +93,9 @@ public class MediaOutputIndicatorWorkerTest {
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBluetoothManager;
when(mLocalBluetoothManager.getEventManager()).thenReturn(mBluetoothEventManager);
mMediaOutputIndicatorWorker = new MediaOutputIndicatorWorker(mContext, URI);
when(mContext.getSystemService(MediaSessionManager.class)).thenReturn(mMediaSessionManager);
doReturn(mMediaSessionManager).when(mContext).getSystemService(MediaSessionManager.class);
mMediaControllers.add(mMediaController);
when(mMediaSessionManager.getActiveSessions(any())).thenReturn(mMediaControllers);
doReturn(mMediaControllers).when(mMediaSessionManager).getActiveSessions(any());
mResolver = mock(ContentResolver.class);
doReturn(mResolver).when(mContext).getContentResolver();
@@ -144,6 +143,7 @@ public class MediaOutputIndicatorWorkerTest {
@Test
public void onSlicePinned_noActiveController_noPackageName() {
mMediaOutputIndicatorWorker.mLocalMediaManager = mLocalMediaManager;
mMediaControllers.clear();
mMediaOutputIndicatorWorker.onSlicePinned();
@@ -186,18 +186,16 @@ public class MediaOutputIndicatorWorkerTest {
@Test
public void onReceive_shouldNotifyChange() {
mMediaOutputIndicatorWorker.mLocalMediaManager = mLocalMediaManager;
mMediaOutputIndicatorWorker.onSlicePinned();
waitForLocalMediaManagerInit();
// onSlicePinned will registerCallback() and get first callback. Callback triggers this at
// the first time.
verify(mResolver, times(1)).notifyChange(URI, null);
final Intent intent = new Intent(AudioManager.STREAM_DEVICES_CHANGED_ACTION);
for (BroadcastReceiver receiver : mShadowApplication.getReceiversForIntent(intent)) {
receiver.onReceive(mContext, intent);
}
// Intent receiver triggers notifyChange() again
verify(mResolver, times(2)).notifyChange(URI, null /* observer */);
verify(mResolver).notifyChange(URI, null /* observer */);
}
@Test