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

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

Migration Assert to Truth: assertNull

Bug: 311772251
Test: atest BluetoothInstrumentationTests
Flag: TEST_ONLY
Change-Id: I48bfaa55f64f808e5e16d0381e168ce93831019c
parent 92b4d1e2
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */
package com.android.bluetooth;

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

import static org.mockito.ArgumentMatchers.eq;
@@ -93,10 +94,11 @@ public class TestUtils {
     *     mocked or spied
     */
    public static void setAdapterService(AdapterService adapterService) {
        Assert.assertNull(
        assertWithMessage(
                        "AdapterService.getAdapterService() must be null before setting another"
                        + " AdapterService",
                AdapterService.getAdapterService());
                                + " AdapterService")
                .that(AdapterService.getAdapterService())
                .isNull();
        Assert.assertNotNull("Adapter service should not be null", adapterService);
        // We cannot mock AdapterService.getAdapterService() with Mockito.
        // Hence we need to set AdapterService.sAdapterService field.
@@ -190,7 +192,7 @@ public class TestUtils {
    public static void waitForNoIntent(int timeoutMs, BlockingQueue<Intent> queue) {
        try {
            Intent intent = queue.poll(timeoutMs, TimeUnit.MILLISECONDS);
            Assert.assertNull(intent);
            assertThat(intent).isNull();
        } catch (InterruptedException e) {
            Assert.fail("Cannot obtain an Intent from the queue: " + e.getMessage());
        }
+4 −6
Original line number Diff line number Diff line
@@ -172,12 +172,10 @@ public class MediaPlayerWrapperTest {
     */
    @Test
    public void testNullControllerLooper() {
        MediaPlayerWrapper wrapper =
                MediaPlayerWrapperFactory.wrap(mMockContext, null, mThread.getLooper());
        Assert.assertNull(wrapper);
        assertThat(MediaPlayerWrapperFactory.wrap(mMockContext, null, mThread.getLooper()))
                .isNull();

        wrapper = MediaPlayerWrapperFactory.wrap(mMockContext, mMockController, null);
        Assert.assertNull(wrapper);
        assertThat(MediaPlayerWrapperFactory.wrap(mMockContext, mMockController, null)).isNull();
    }

    /*
@@ -556,7 +554,7 @@ public class MediaPlayerWrapperTest {

        // Ensure that everything was cleaned up
        verify(mMockController).unregisterCallback(any());
        Assert.assertNull(wrapper.getTimeoutHandler());
        assertThat(wrapper.getTimeoutHandler()).isNull();
    }

    /*
+3 −6
Original line number Diff line number Diff line
@@ -1380,8 +1380,7 @@ public class AvrcpControllerStateMachineTest {
        MediaControllerCompat controller = session.getController();
        Assert.assertNotNull(controller);

        MediaMetadataCompat metadata = controller.getMetadata();
        Assert.assertNull(metadata); // track starts as null and shouldn't change
        assertThat(controller.getMetadata()).isNull(); // track starts as null and shouldn't change
    }

    /** Test receiving a playback status of playing when we're not the active device */
@@ -1465,8 +1464,7 @@ public class AvrcpControllerStateMachineTest {
        MediaControllerCompat controller = session.getController();
        Assert.assertNotNull(controller);

        List<MediaSessionCompat.QueueItem> queue = controller.getQueue();
        Assert.assertNull(queue);
        assertThat(controller.getQueue()).isNull();
    }

    /**
@@ -2008,8 +2006,7 @@ public class AvrcpControllerStateMachineTest {
        Assert.assertNotNull(session);
        MediaControllerCompat controller = session.getController();
        Assert.assertNotNull(controller);
        List<MediaSessionCompat.QueueItem> queue = controller.getQueue();
        Assert.assertNull(queue);
        assertThat(controller.getQueue()).isNull();
    }

    /**
+5 −3
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.bluetooth.avrcpcontroller;

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

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.net.Uri;
@@ -552,7 +554,7 @@ public final class AvrcpItemTest {
        Assert.assertEquals(UUID, desc.getMediaId());
        Assert.assertEquals(null, desc.getMediaUri());
        Assert.assertEquals(title, desc.getTitle().toString());
        Assert.assertNull(desc.getSubtitle());
        assertThat(desc.getSubtitle()).isNull();
        Assert.assertEquals(uri, desc.getIconUri());
        Assert.assertEquals(null, desc.getIconBitmap());
    }
@@ -581,7 +583,7 @@ public final class AvrcpItemTest {
        Assert.assertEquals(UUID, desc.getMediaId());
        Assert.assertEquals(null, desc.getMediaUri());
        Assert.assertEquals(displayName, desc.getTitle().toString());
        Assert.assertNull(desc.getSubtitle());
        assertThat(desc.getSubtitle()).isNull();
        Assert.assertEquals(uri, desc.getIconUri());
        Assert.assertEquals(null, desc.getIconBitmap());
    }
@@ -608,7 +610,7 @@ public final class AvrcpItemTest {
        Assert.assertEquals(UUID, desc.getMediaId());
        Assert.assertEquals(null, desc.getMediaUri());
        Assert.assertEquals(title, desc.getTitle().toString());
        Assert.assertNull(desc.getSubtitle());
        assertThat(desc.getSubtitle()).isNull();
        Assert.assertEquals(uri, desc.getIconUri());
        Assert.assertEquals(null, desc.getIconBitmap());
    }
+5 −6
Original line number Diff line number Diff line
@@ -50,7 +50,6 @@ import static com.android.bluetooth.bass_client.BassConstants.CLIENT_CHARACTERIS
import static com.google.common.truth.Truth.assertThat;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
@@ -282,7 +281,7 @@ public class BassClientStateMachineTest {
        Assert.assertThat(
                mBassClientStateMachine.getCurrentState(),
                IsInstanceOf.instanceOf(BassClientStateMachine.Disconnected.class));
        assertNull(mBassClientStateMachine.mBluetoothGatt);
        assertThat(mBassClientStateMachine.mBluetoothGatt).isNull();
    }

    @Test
@@ -1564,7 +1563,7 @@ public class BassClientStateMachineTest {
        mBassClientStateMachine.mBluetoothGatt = btGatt;
        sendMessageAndVerifyTransition(msg, BassClientStateMachine.Disconnected.class);
        verify(btGatt).close();
        assertNull(mBassClientStateMachine.mBluetoothGatt);
        assertThat(mBassClientStateMachine.mBluetoothGatt).isNull();
    }

    @Test
@@ -1593,7 +1592,7 @@ public class BassClientStateMachineTest {
        Message msg = mBassClientStateMachine.obtainMessage(CONNECT_TIMEOUT, mTestDevice);
        sendMessageAndVerifyTransition(msg, BassClientStateMachine.Disconnected.class);
        verify(btGatt).close();
        assertNull(mBassClientStateMachine.mBluetoothGatt);
        assertThat(mBassClientStateMachine.mBluetoothGatt).isNull();
    }

    @Test
@@ -1656,7 +1655,7 @@ public class BassClientStateMachineTest {
        noneConnectedMsg.obj = BluetoothProfile.STATE_DISCONNECTING;
        sendMessageAndVerifyTransition(noneConnectedMsg, BassClientStateMachine.Disconnected.class);
        verify(btGatt).close();
        assertNull(mBassClientStateMachine.mBluetoothGatt);
        assertThat(mBassClientStateMachine.mBluetoothGatt).isNull();
    }

    @Test
@@ -2222,7 +2221,7 @@ public class BassClientStateMachineTest {
        sendMessageAndVerifyTransition(
                msgToNoneConnectedState, BassClientStateMachine.Disconnected.class);
        verify(btGatt).close();
        assertNull(mBassClientStateMachine.mBluetoothGatt);
        assertThat(mBassClientStateMachine.mBluetoothGatt).isNull();
    }

    /** This also tests BassClientStateMachine#sendPendingCallbacks */
Loading