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

Commit e97e59c7 authored by William Escande's avatar William Escande Committed by Gerrit Code Review
Browse files

Merge changes I5d46fb81,I9b55f091,I8f5d19d3,I2cde94f0,I48bfaa55, ... into main

* changes:
  migration to truth Follow-up nit fixes
  Migration Assert to Truth: assertFalse
  Migration Assert to Truth: assertTrue
  Migration Assert to Truth: assertNotNull
  Migration Assert to Truth: assertNull
  waitForNoIntent: don't return null
parents 9cea1101 241d2b70
Loading
Loading
Loading
Loading
+8 −19
Original line number Diff line number Diff line
@@ -15,10 +15,11 @@
 */
package com.android.bluetooth;

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

import androidx.test.filters.MediumTest;
import androidx.test.runner.AndroidJUnit4;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

@@ -30,35 +31,23 @@ import java.io.IOException;
@RunWith(AndroidJUnit4.class)
public class FileSystemWriteTest {
    @Test
    public void testBluetoothDirWrite() {
        try {
    public void testBluetoothDirWrite() throws IOException {
            File file = new File("/data/misc/bluetooth/test.file");
            Assert.assertTrue("File not created", file.createNewFile());
        assertThat(file.createNewFile()).isTrue();
            file.delete();
        } catch (IOException e) {
            Assert.fail("Exception creating file /data/misc/bluetooth/test.file: " + e);
        }
    }

    @Test
    public void testBluedroidDirWrite() {
        try {
    public void testBluedroidDirWrite() throws IOException {
            File file = new File("/data/misc/bluedroid/test.file");
            Assert.assertTrue("File not created", file.createNewFile());
        assertThat(file.createNewFile()).isTrue();
            file.delete();
        } catch (IOException e) {
            Assert.fail("Exception creating file /data/misc/bluedroid/test.file: " + e);
        }
    }

    @Test
    public void testBluetoothLogsDirWrite() {
        try {
    public void testBluetoothLogsDirWrite() throws IOException {
            File file = new File("/data/misc/bluetooth/logs/test.file");
            Assert.assertTrue("File not created", file.createNewFile());
        assertThat(file.createNewFile()).isTrue();
            file.delete();
        } catch (IOException e) {
            Assert.fail("Exception creating file /data/misc/bluetooth/logs/test.file: " + e);
        }
    }
}
+15 −16
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,11 +94,12 @@ 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());
        Assert.assertNotNull("Adapter service should not be null", adapterService);
                                + " AdapterService")
                .that(AdapterService.getAdapterService())
                .isNull();
        assertThat(adapterService).isNotNull();
        // We cannot mock AdapterService.getAdapterService() with Mockito.
        // Hence we need to set AdapterService.sAdapterService field.
        AdapterService.setAdapterService(adapterService);
@@ -115,7 +117,7 @@ public class TestUtils {
                        + " supplied adapterService in this method",
                adapterService,
                AdapterService.getAdapterService());
        Assert.assertNotNull("Adapter service should not be null", adapterService);
        assertThat(adapterService).isNotNull();
        AdapterService.clearAdapterService(adapterService);
    }

@@ -142,11 +144,11 @@ public class TestUtils {
     * @return {@link BluetoothDevice} test device for the device ID
     */
    public static BluetoothDevice getTestDevice(BluetoothAdapter bluetoothAdapter, int id) {
        Assert.assertTrue(id <= 0xFF);
        Assert.assertNotNull(bluetoothAdapter);
        assertThat(id).isAtMost(0xFF);
        assertThat(bluetoothAdapter).isNotNull();
        BluetoothDevice testDevice =
                bluetoothAdapter.getRemoteDevice(String.format("00:01:02:03:04:%02X", id));
        Assert.assertNotNull(testDevice);
        assertThat(testDevice).isNotNull();
        return testDevice;
    }

@@ -173,7 +175,7 @@ public class TestUtils {
    public static Intent waitForIntent(int timeoutMs, BlockingQueue<Intent> queue) {
        try {
            Intent intent = queue.poll(timeoutMs, TimeUnit.MILLISECONDS);
            Assert.assertNotNull(intent);
            assertThat(intent).isNotNull();
            return intent;
        } catch (InterruptedException e) {
            Assert.fail("Cannot obtain an Intent from the queue: " + e.getMessage());
@@ -186,17 +188,14 @@ public class TestUtils {
     *
     * @param timeoutMs the time (in milliseconds) to wait and verify no intent has been received
     * @param queue the queue for the intent
     * @return the received intent. Should be null under normal circumstances
     */
    public static Intent waitForNoIntent(int timeoutMs, BlockingQueue<Intent> queue) {
    public static void waitForNoIntent(int timeoutMs, BlockingQueue<Intent> queue) {
        try {
            Intent intent = queue.poll(timeoutMs, TimeUnit.MILLISECONDS);
            Assert.assertNull(intent);
            return intent;
            assertThat(intent).isNull();
        } catch (InterruptedException e) {
            Assert.fail("Cannot obtain an Intent from the queue: " + e.getMessage());
        }
        return null;
    }

    /**
@@ -279,7 +278,7 @@ public class TestUtils {
     * <pre>{@code
     * TestUtils.runOnMainSync(new Runnable() {
     *       public void run() {
     *           Assert.assertTrue(mA2dpService.stop());
     *           assertThat(mA2dpService.stop()).isTrue();
     *       }
     *   });
     * }</pre>
+8 −6
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.bluetooth.audio_util;

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

import static org.mockito.Mockito.*;

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

        AudioManager mockAudioManager = mock(AudioManager.class);
        when(mMockContext.getSystemService(Context.AUDIO_SERVICE)).thenReturn(mockAudioManager);
+22 −27
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();
    }

    /*
@@ -188,24 +186,24 @@ public class MediaPlayerWrapperTest {
    public void testIsReady() {
        MediaPlayerWrapper wrapper =
                MediaPlayerWrapperFactory.wrap(mMockContext, mMockController, mThread.getLooper());
        Assert.assertTrue(wrapper.isPlaybackStateReady());
        Assert.assertTrue(wrapper.isMetadataReady());
        assertThat(wrapper.isPlaybackStateReady()).isTrue();
        assertThat(wrapper.isMetadataReady()).isTrue();

        // Test isPlaybackStateReady() is false when the playback state is null
        doReturn(null).when(mMockController).getPlaybackState();
        Assert.assertFalse(wrapper.isPlaybackStateReady());
        assertThat(wrapper.isPlaybackStateReady()).isFalse();

        // Restore the old playback state
        doReturn(mTestState.build()).when(mMockController).getPlaybackState();
        Assert.assertTrue(wrapper.isPlaybackStateReady());
        assertThat(wrapper.isPlaybackStateReady()).isTrue();

        // Test isMetadataReady() is false when the metadata is null
        doReturn(null).when(mMockController).getMetadata();
        Assert.assertFalse(wrapper.isMetadataReady());
        assertThat(wrapper.isMetadataReady()).isFalse();

        // Restore the old metadata
        doReturn(mTestMetadata.build()).when(mMockController).getMetadata();
        Assert.assertTrue(wrapper.isMetadataReady());
        assertThat(wrapper.isMetadataReady()).isTrue();
    }

    /*
@@ -217,8 +215,8 @@ public class MediaPlayerWrapperTest {
        // Create the wrapper object and register the looper with the timeout handler
        MediaPlayerWrapper wrapper =
                MediaPlayerWrapperFactory.wrap(mMockContext, mMockController, mThread.getLooper());
        Assert.assertTrue(wrapper.isPlaybackStateReady());
        Assert.assertTrue(wrapper.isMetadataReady());
        assertThat(wrapper.isPlaybackStateReady()).isTrue();
        assertThat(wrapper.isMetadataReady()).isTrue();
        wrapper.registerCallback(mTestCbs);

        // Create a new MediaController that has different metadata than the previous controller
@@ -296,7 +294,7 @@ public class MediaPlayerWrapperTest {
        Assert.assertEquals("Returned Queue isn't empty", data.queue.size(), 0);

        // Verify that there are no timeout messages pending and there were no timeouts
        Assert.assertFalse(wrapper.getTimeoutHandler().hasMessages(MSG_TIMEOUT));
        assertThat(wrapper.getTimeoutHandler().hasMessages(MSG_TIMEOUT)).isFalse();
        verify(mFailHandler, never()).onTerribleFailure(any(), any(), anyBoolean());
    }

@@ -345,7 +343,7 @@ public class MediaPlayerWrapperTest {
        Assert.assertEquals("Returned Queue isn't empty", data.queue.size(), 0);

        // Verify that there are no timeout messages pending and there were no timeouts
        Assert.assertFalse(wrapper.getTimeoutHandler().hasMessages(MSG_TIMEOUT));
        assertThat(wrapper.getTimeoutHandler().hasMessages(MSG_TIMEOUT)).isFalse();
        verify(mFailHandler, never()).onTerribleFailure(any(), any(), anyBoolean());
    }

@@ -470,19 +468,16 @@ public class MediaPlayerWrapperTest {
                MediaPlayerWrapperFactory.wrap(mMockContext, mMockController, mThread.getLooper());

        doReturn(null).when(mMockController).getMetadata();
        Assert.assertFalse(
                Util.toMetadata(mMockContext, mTestMetadata.build())
                        .duration
                        .equals(wrapper.getCurrentQueue().get(0).duration));
        assertThat(Util.toMetadata(mMockContext, mTestMetadata.build()).duration)
                .isNotEqualTo(wrapper.getCurrentQueue().get(0).duration);
        doReturn(mTestMetadata.build()).when(mMockController).getMetadata();
        Assert.assertEquals(
                Util.toMetadata(mMockContext, mTestMetadata.build()).duration,
                wrapper.getCurrentQueue().get(0).duration);
        // The MediaController Metadata should still not be equal to the queue
        // as the track count is different and should not be overridden.
        Assert.assertFalse(
                Util.toMetadata(mMockContext, mTestMetadata.build())
                        .equals(wrapper.getCurrentQueue().get(0)));
        assertThat(Util.toMetadata(mMockContext, mTestMetadata.build()))
                .isNotEqualTo(wrapper.getCurrentQueue().get(0));
    }

    /*
@@ -537,7 +532,7 @@ public class MediaPlayerWrapperTest {
        controllerCallbacks.onPlaybackStateChanged(mTestState.build());

        // Verify that there are no timeout messages pending and there were no timeouts
        Assert.assertFalse(wrapper.getTimeoutHandler().hasMessages(MSG_TIMEOUT));
        assertThat(wrapper.getTimeoutHandler().hasMessages(MSG_TIMEOUT)).isFalse();
        verify(mFailHandler, never()).onTerribleFailure(any(), any(), anyBoolean());
    }

@@ -556,7 +551,7 @@ public class MediaPlayerWrapperTest {

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

    /*
@@ -583,7 +578,7 @@ public class MediaPlayerWrapperTest {
        verify(mTestCbs, never()).mediaUpdatedCallback(any());

        // Verify that there are no timeout messages pending and there were no timeouts
        Assert.assertFalse(wrapper.getTimeoutHandler().hasMessages(MSG_TIMEOUT));
        assertThat(wrapper.getTimeoutHandler().hasMessages(MSG_TIMEOUT)).isFalse();
        verify(mFailHandler, never()).onTerribleFailure(any(), any(), anyBoolean());
    }

@@ -642,7 +637,7 @@ public class MediaPlayerWrapperTest {
                Util.toMetadataList(mMockContext, getQueueFromDescriptions(mTestQueue)));

        // Verify that there are no timeout messages pending and there were no timeouts
        Assert.assertFalse(wrapper.getTimeoutHandler().hasMessages(MSG_TIMEOUT));
        assertThat(wrapper.getTimeoutHandler().hasMessages(MSG_TIMEOUT)).isFalse();
        verify(mFailHandler, never()).onTerribleFailure(any(), any(), anyBoolean());
    }

@@ -771,7 +766,7 @@ public class MediaPlayerWrapperTest {
        }

        // Verify that there are no timeout messages pending and there were no timeouts
        Assert.assertFalse(wrapper.getTimeoutHandler().hasMessages(MSG_TIMEOUT));
        assertThat(wrapper.getTimeoutHandler().hasMessages(MSG_TIMEOUT)).isFalse();
        verify(mFailHandler, never()).onTerribleFailure(any(), any(), anyBoolean());
    }

Loading