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

Commit c6d73e6b authored by William Escande's avatar William Escande
Browse files

Migration Assert to Truth: assertNotNull

Bug: 311772251
Test: atest BluetoothInstrumentationTests
Flag: TEST_ONLY
Change-Id: I2cde94f07f175da9de658ab0c03fde6bb28ba00a
parent fa0b3e4b
Loading
Loading
Loading
Loading
+5 −5
Original line number Original line Diff line number Diff line
@@ -99,7 +99,7 @@ public class TestUtils {
                                + " AdapterService")
                                + " AdapterService")
                .that(AdapterService.getAdapterService())
                .that(AdapterService.getAdapterService())
                .isNull();
                .isNull();
        Assert.assertNotNull("Adapter service should not be null", adapterService);
        assertThat(adapterService).isNotNull();
        // We cannot mock AdapterService.getAdapterService() with Mockito.
        // We cannot mock AdapterService.getAdapterService() with Mockito.
        // Hence we need to set AdapterService.sAdapterService field.
        // Hence we need to set AdapterService.sAdapterService field.
        AdapterService.setAdapterService(adapterService);
        AdapterService.setAdapterService(adapterService);
@@ -117,7 +117,7 @@ public class TestUtils {
                        + " supplied adapterService in this method",
                        + " supplied adapterService in this method",
                adapterService,
                adapterService,
                AdapterService.getAdapterService());
                AdapterService.getAdapterService());
        Assert.assertNotNull("Adapter service should not be null", adapterService);
        assertThat(adapterService).isNotNull();
        AdapterService.clearAdapterService(adapterService);
        AdapterService.clearAdapterService(adapterService);
    }
    }


@@ -145,10 +145,10 @@ public class TestUtils {
     */
     */
    public static BluetoothDevice getTestDevice(BluetoothAdapter bluetoothAdapter, int id) {
    public static BluetoothDevice getTestDevice(BluetoothAdapter bluetoothAdapter, int id) {
        Assert.assertTrue(id <= 0xFF);
        Assert.assertTrue(id <= 0xFF);
        Assert.assertNotNull(bluetoothAdapter);
        assertThat(bluetoothAdapter).isNotNull();
        BluetoothDevice testDevice =
        BluetoothDevice testDevice =
                bluetoothAdapter.getRemoteDevice(String.format("00:01:02:03:04:%02X", id));
                bluetoothAdapter.getRemoteDevice(String.format("00:01:02:03:04:%02X", id));
        Assert.assertNotNull(testDevice);
        assertThat(testDevice).isNotNull();
        return testDevice;
        return testDevice;
    }
    }


@@ -175,7 +175,7 @@ public class TestUtils {
    public static Intent waitForIntent(int timeoutMs, BlockingQueue<Intent> queue) {
    public static Intent waitForIntent(int timeoutMs, BlockingQueue<Intent> queue) {
        try {
        try {
            Intent intent = queue.poll(timeoutMs, TimeUnit.MILLISECONDS);
            Intent intent = queue.poll(timeoutMs, TimeUnit.MILLISECONDS);
            Assert.assertNotNull(intent);
            assertThat(intent).isNotNull();
            return intent;
            return intent;
        } catch (InterruptedException e) {
        } catch (InterruptedException e) {
            Assert.fail("Cannot obtain an Intent from the queue: " + e.getMessage());
            Assert.fail("Cannot obtain an Intent from the queue: " + e.getMessage());
+5 −3
Original line number Original line Diff line number Diff line
@@ -16,6 +16,8 @@


package com.android.bluetooth.audio_util;
package com.android.bluetooth.audio_util;


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

import static org.mockito.Mockito.*;
import static org.mockito.Mockito.*;


import android.content.ContentResolver;
import android.content.ContentResolver;
@@ -393,13 +395,13 @@ public class BrowserPlayerWrapperTest {
            Assert.assertEquals(expected.isBrowsable(), item.isFolder);
            Assert.assertEquals(expected.isBrowsable(), item.isFolder);
            if (item.isFolder) {
            if (item.isFolder) {
                Folder folder = item.folder;
                Folder folder = item.folder;
                Assert.assertNotNull(folder);
                assertThat(folder).isNotNull();
                Assert.assertFalse(folder.isPlayable);
                Assert.assertFalse(folder.isPlayable);
                Assert.assertEquals(expected.getDescription().getMediaId(), folder.mediaId);
                Assert.assertEquals(expected.getDescription().getMediaId(), folder.mediaId);
                Assert.assertEquals(expected.getDescription().getTitle().toString(), folder.title);
                Assert.assertEquals(expected.getDescription().getTitle().toString(), folder.title);
            } else {
            } else {
                Metadata song = item.song;
                Metadata song = item.song;
                Assert.assertNotNull(song);
                assertThat(song).isNotNull();
                Assert.assertEquals(expected.getDescription().getMediaId(), song.mediaId);
                Assert.assertEquals(expected.getDescription().getMediaId(), song.mediaId);
                Assert.assertEquals(expected.getDescription().getTitle().toString(), song.title);
                Assert.assertEquals(expected.getDescription().getTitle().toString(), song.title);
                Assert.assertEquals(
                Assert.assertEquals(
@@ -407,7 +409,7 @@ public class BrowserPlayerWrapperTest {
                Assert.assertEquals(
                Assert.assertEquals(
                        expected.getDescription().getDescription().toString(), song.album);
                        expected.getDescription().getDescription().toString(), song.album);
                if (expected.getDescription().getIconBitmap() != null) {
                if (expected.getDescription().getIconBitmap() != null) {
                    Assert.assertNotNull(song.image);
                    assertThat(song.image).isNotNull();
                    Bitmap expectedBitmap = expected.getDescription().getIconBitmap();
                    Bitmap expectedBitmap = expected.getDescription().getIconBitmap();
                    Assert.assertTrue(expectedBitmap.sameAs(song.image.getImage()));
                    Assert.assertTrue(expectedBitmap.sameAs(song.image.getImage()));
                } else if (expected.getDescription().getIconUri() != null) {
                } else if (expected.getDescription().getIconUri() != null) {
+3 −1
Original line number Original line Diff line number Diff line
@@ -16,6 +16,8 @@


package com.android.bluetooth.audio_util;
package com.android.bluetooth.audio_util;


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

import static org.mockito.Mockito.*;
import static org.mockito.Mockito.*;


import android.content.Context;
import android.content.Context;
@@ -71,7 +73,7 @@ public class MediaPlayerListTest {
        if (Looper.myLooper() == null) {
        if (Looper.myLooper() == null) {
            Looper.prepare();
            Looper.prepare();
        }
        }
        Assert.assertNotNull(Looper.myLooper());
        assertThat(Looper.myLooper()).isNotNull();


        AudioManager mockAudioManager = mock(AudioManager.class);
        AudioManager mockAudioManager = mock(AudioManager.class);
        when(mMockContext.getSystemService(Context.AUDIO_SERVICE)).thenReturn(mockAudioManager);
        when(mMockContext.getSystemService(Context.AUDIO_SERVICE)).thenReturn(mockAudioManager);
+23 −23
Original line number Original line Diff line number Diff line
@@ -105,7 +105,7 @@ public class AvrcpControllerStateMachineTest {
        if (Looper.myLooper() == null) {
        if (Looper.myLooper() == null) {
            Looper.prepare();
            Looper.prepare();
        }
        }
        Assert.assertNotNull(Looper.myLooper());
        assertThat(Looper.myLooper()).isNotNull();


        // Set a mock Adapter Service for profile state change notifications
        // Set a mock Adapter Service for profile state change notifications
        TestUtils.setAdapterService(mAdapterService);
        TestUtils.setAdapterService(mAdapterService);
@@ -410,7 +410,7 @@ public class AvrcpControllerStateMachineTest {
        int numBroadcastsSent = setUpConnectedState(true, false);
        int numBroadcastsSent = setUpConnectedState(true, false);
        MediaControllerCompat.TransportControls transportControls =
        MediaControllerCompat.TransportControls transportControls =
                BluetoothMediaBrowserService.getTransportControls();
                BluetoothMediaBrowserService.getTransportControls();
        Assert.assertNotNull(transportControls);
        assertThat(transportControls).isNotNull();
        Assert.assertEquals(
        Assert.assertEquals(
                PlaybackStateCompat.STATE_NONE,
                PlaybackStateCompat.STATE_NONE,
                BluetoothMediaBrowserService.getPlaybackState().getState());
                BluetoothMediaBrowserService.getPlaybackState().getState());
@@ -487,7 +487,7 @@ public class AvrcpControllerStateMachineTest {
    public void testDump() {
    public void testDump() {
        StringBuilder sb = new StringBuilder();
        StringBuilder sb = new StringBuilder();
        mAvrcpStateMachine.dump(sb);
        mAvrcpStateMachine.dump(sb);
        Assert.assertNotNull(sb.toString());
        assertThat(sb.toString()).isNotNull();
    }
    }


    /** Test media browser play command */
    /** Test media browser play command */
@@ -1251,12 +1251,12 @@ public class AvrcpControllerStateMachineTest {


        // See that state from BluetoothMediaBrowserService is updated
        // See that state from BluetoothMediaBrowserService is updated
        MediaSessionCompat session = BluetoothMediaBrowserService.getSession();
        MediaSessionCompat session = BluetoothMediaBrowserService.getSession();
        Assert.assertNotNull(session);
        assertThat(session).isNotNull();
        MediaControllerCompat controller = session.getController();
        MediaControllerCompat controller = session.getController();
        Assert.assertNotNull(controller);
        assertThat(controller).isNotNull();


        MediaMetadataCompat metadata = controller.getMetadata();
        MediaMetadataCompat metadata = controller.getMetadata();
        Assert.assertNotNull(metadata);
        assertThat(metadata).isNotNull();
        Assert.assertEquals("title", metadata.getString(MediaMetadataCompat.METADATA_KEY_TITLE));
        Assert.assertEquals("title", metadata.getString(MediaMetadataCompat.METADATA_KEY_TITLE));
        Assert.assertEquals("artist", metadata.getString(MediaMetadataCompat.METADATA_KEY_ARTIST));
        Assert.assertEquals("artist", metadata.getString(MediaMetadataCompat.METADATA_KEY_ARTIST));
        Assert.assertEquals("album", metadata.getString(MediaMetadataCompat.METADATA_KEY_ALBUM));
        Assert.assertEquals("album", metadata.getString(MediaMetadataCompat.METADATA_KEY_ALBUM));
@@ -1266,12 +1266,12 @@ public class AvrcpControllerStateMachineTest {
        Assert.assertEquals(10, metadata.getLong(MediaMetadataCompat.METADATA_KEY_DURATION));
        Assert.assertEquals(10, metadata.getLong(MediaMetadataCompat.METADATA_KEY_DURATION));


        PlaybackStateCompat playbackState = controller.getPlaybackState();
        PlaybackStateCompat playbackState = controller.getPlaybackState();
        Assert.assertNotNull(playbackState);
        assertThat(playbackState).isNotNull();
        Assert.assertEquals(PlaybackStateCompat.STATE_PAUSED, playbackState.getState());
        Assert.assertEquals(PlaybackStateCompat.STATE_PAUSED, playbackState.getState());
        Assert.assertEquals(7, playbackState.getPosition());
        Assert.assertEquals(7, playbackState.getPosition());


        List<MediaSessionCompat.QueueItem> queue = controller.getQueue();
        List<MediaSessionCompat.QueueItem> queue = controller.getQueue();
        Assert.assertNotNull(queue);
        assertThat(queue).isNotNull();
        Assert.assertEquals(2, queue.size());
        Assert.assertEquals(2, queue.size());
        Assert.assertEquals("title", queue.get(0).getDescription().getTitle().toString());
        Assert.assertEquals("title", queue.get(0).getDescription().getTitle().toString());
        Assert.assertEquals("title 2", queue.get(1).getDescription().getTitle().toString());
        Assert.assertEquals("title 2", queue.get(1).getDescription().getTitle().toString());
@@ -1318,12 +1318,12 @@ public class AvrcpControllerStateMachineTest {


        // Verify track and playback state
        // Verify track and playback state
        MediaSessionCompat session = BluetoothMediaBrowserService.getSession();
        MediaSessionCompat session = BluetoothMediaBrowserService.getSession();
        Assert.assertNotNull(session);
        assertThat(session).isNotNull();
        MediaControllerCompat controller = session.getController();
        MediaControllerCompat controller = session.getController();
        Assert.assertNotNull(controller);
        assertThat(controller).isNotNull();


        MediaMetadataCompat metadata = controller.getMetadata();
        MediaMetadataCompat metadata = controller.getMetadata();
        Assert.assertNotNull(metadata);
        assertThat(metadata).isNotNull();
        Assert.assertEquals("Song 1", metadata.getString(MediaMetadataCompat.METADATA_KEY_TITLE));
        Assert.assertEquals("Song 1", metadata.getString(MediaMetadataCompat.METADATA_KEY_TITLE));
        Assert.assertEquals("artist", metadata.getString(MediaMetadataCompat.METADATA_KEY_ARTIST));
        Assert.assertEquals("artist", metadata.getString(MediaMetadataCompat.METADATA_KEY_ARTIST));
        Assert.assertEquals("album", metadata.getString(MediaMetadataCompat.METADATA_KEY_ALBUM));
        Assert.assertEquals("album", metadata.getString(MediaMetadataCompat.METADATA_KEY_ALBUM));
@@ -1333,7 +1333,7 @@ public class AvrcpControllerStateMachineTest {
        Assert.assertEquals(10, metadata.getLong(MediaMetadataCompat.METADATA_KEY_DURATION));
        Assert.assertEquals(10, metadata.getLong(MediaMetadataCompat.METADATA_KEY_DURATION));


        PlaybackStateCompat playbackState = controller.getPlaybackState();
        PlaybackStateCompat playbackState = controller.getPlaybackState();
        Assert.assertNotNull(playbackState);
        assertThat(playbackState).isNotNull();
        Assert.assertEquals(PlaybackStateCompat.STATE_PLAYING, playbackState.getState());
        Assert.assertEquals(PlaybackStateCompat.STATE_PLAYING, playbackState.getState());
        Assert.assertEquals(0, playbackState.getActiveQueueItemId());
        Assert.assertEquals(0, playbackState.getActiveQueueItemId());


@@ -1344,7 +1344,7 @@ public class AvrcpControllerStateMachineTest {


        // Assert new track metadata and active queue item
        // Assert new track metadata and active queue item
        metadata = controller.getMetadata();
        metadata = controller.getMetadata();
        Assert.assertNotNull(metadata);
        assertThat(metadata).isNotNull();
        Assert.assertEquals("Song 2", metadata.getString(MediaMetadataCompat.METADATA_KEY_TITLE));
        Assert.assertEquals("Song 2", metadata.getString(MediaMetadataCompat.METADATA_KEY_TITLE));
        Assert.assertEquals("artist", metadata.getString(MediaMetadataCompat.METADATA_KEY_ARTIST));
        Assert.assertEquals("artist", metadata.getString(MediaMetadataCompat.METADATA_KEY_ARTIST));
        Assert.assertEquals("album", metadata.getString(MediaMetadataCompat.METADATA_KEY_ALBUM));
        Assert.assertEquals("album", metadata.getString(MediaMetadataCompat.METADATA_KEY_ALBUM));
@@ -1354,7 +1354,7 @@ public class AvrcpControllerStateMachineTest {
        Assert.assertEquals(10, metadata.getLong(MediaMetadataCompat.METADATA_KEY_DURATION));
        Assert.assertEquals(10, metadata.getLong(MediaMetadataCompat.METADATA_KEY_DURATION));


        playbackState = controller.getPlaybackState();
        playbackState = controller.getPlaybackState();
        Assert.assertNotNull(playbackState);
        assertThat(playbackState).isNotNull();
        Assert.assertEquals(PlaybackStateCompat.STATE_PLAYING, playbackState.getState());
        Assert.assertEquals(PlaybackStateCompat.STATE_PLAYING, playbackState.getState());
        Assert.assertEquals(1, playbackState.getActiveQueueItemId());
        Assert.assertEquals(1, playbackState.getActiveQueueItemId());
    }
    }
@@ -1376,9 +1376,9 @@ public class AvrcpControllerStateMachineTest {


        // Since we're not active, verify BluetoothMediaBrowserService does not have these values
        // Since we're not active, verify BluetoothMediaBrowserService does not have these values
        MediaSessionCompat session = BluetoothMediaBrowserService.getSession();
        MediaSessionCompat session = BluetoothMediaBrowserService.getSession();
        Assert.assertNotNull(session);
        assertThat(session).isNotNull();
        MediaControllerCompat controller = session.getController();
        MediaControllerCompat controller = session.getController();
        Assert.assertNotNull(controller);
        assertThat(controller).isNotNull();


        assertThat(controller.getMetadata()).isNull(); // track starts as null and shouldn't change
        assertThat(controller.getMetadata()).isNull(); // track starts as null and shouldn't change
    }
    }
@@ -1428,12 +1428,12 @@ public class AvrcpControllerStateMachineTest {


        // Since we're not active, verify BluetoothMediaBrowserService does not have these values
        // Since we're not active, verify BluetoothMediaBrowserService does not have these values
        MediaSessionCompat session = BluetoothMediaBrowserService.getSession();
        MediaSessionCompat session = BluetoothMediaBrowserService.getSession();
        Assert.assertNotNull(session);
        assertThat(session).isNotNull();
        MediaControllerCompat controller = session.getController();
        MediaControllerCompat controller = session.getController();
        Assert.assertNotNull(controller);
        assertThat(controller).isNotNull();


        PlaybackStateCompat playbackState = controller.getPlaybackState();
        PlaybackStateCompat playbackState = controller.getPlaybackState();
        Assert.assertNotNull(playbackState);
        assertThat(playbackState).isNotNull();
        Assert.assertEquals(0, playbackState.getPosition());
        Assert.assertEquals(0, playbackState.getPosition());
    }
    }


@@ -1460,9 +1460,9 @@ public class AvrcpControllerStateMachineTest {


        // Since we're not active, verify BluetoothMediaBrowserService does not have these values
        // Since we're not active, verify BluetoothMediaBrowserService does not have these values
        MediaSessionCompat session = BluetoothMediaBrowserService.getSession();
        MediaSessionCompat session = BluetoothMediaBrowserService.getSession();
        Assert.assertNotNull(session);
        assertThat(session).isNotNull();
        MediaControllerCompat controller = session.getController();
        MediaControllerCompat controller = session.getController();
        Assert.assertNotNull(controller);
        assertThat(controller).isNotNull();


        assertThat(controller.getQueue()).isNull();
        assertThat(controller.getQueue()).isNull();
    }
    }
@@ -2003,9 +2003,9 @@ public class AvrcpControllerStateMachineTest {


        // See that state from BluetoothMediaBrowserService is updated to null (i.e. empty)
        // See that state from BluetoothMediaBrowserService is updated to null (i.e. empty)
        MediaSessionCompat session = BluetoothMediaBrowserService.getSession();
        MediaSessionCompat session = BluetoothMediaBrowserService.getSession();
        Assert.assertNotNull(session);
        assertThat(session).isNotNull();
        MediaControllerCompat controller = session.getController();
        MediaControllerCompat controller = session.getController();
        Assert.assertNotNull(controller);
        assertThat(controller).isNotNull();
        assertThat(controller.getQueue()).isNull();
        assertThat(controller.getQueue()).isNull();
    }
    }


+1 −2
Original line number Original line Diff line number Diff line
@@ -49,7 +49,6 @@ import static com.android.bluetooth.bass_client.BassConstants.CLIENT_CHARACTERIS


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


import static org.junit.Assert.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyInt;
@@ -307,7 +306,7 @@ public class BassClientStateMachineTest {
                mBassClientStateMachine.getCurrentState(),
                mBassClientStateMachine.getCurrentState(),
                IsInstanceOf.instanceOf(BassClientStateMachine.Connecting.class));
                IsInstanceOf.instanceOf(BassClientStateMachine.Connecting.class));


        assertNotNull(mBassClientStateMachine.mGattCallback);
        assertThat(mBassClientStateMachine.mGattCallback).isNotNull();
        mBassClientStateMachine.notifyConnectionStateChanged(
        mBassClientStateMachine.notifyConnectionStateChanged(
                GATT_SUCCESS, BluetoothProfile.STATE_CONNECTED);
                GATT_SUCCESS, BluetoothProfile.STATE_CONNECTED);


Loading