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

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

TestErrorProne: NarrowCalculation & UndefinedEquals

Bug: 344658662
Test: m BluetoothInstrumentationTests
Flag: Exempt refactor of test only
Change-Id: I6842932f41992ea93c8addd62b9aaa9fc095b35f
parent c68b1235
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -72,6 +72,7 @@ java_defaults {
            "-Xep:InvalidParam:ERROR",
            "-Xep:InvalidParam:ERROR",
            "-Xep:MockNotUsedInProduction:ERROR",
            "-Xep:MockNotUsedInProduction:ERROR",
            "-Xep:ModifiedButNotUsed:ERROR",
            "-Xep:ModifiedButNotUsed:ERROR",
            "-Xep:NarrowCalculation:ERROR",
            "-Xep:NonApiType:ERROR",
            "-Xep:NonApiType:ERROR",
            "-Xep:NonCanonicalType:ERROR",
            "-Xep:NonCanonicalType:ERROR",
            "-Xep:NotJavadoc:ERROR",
            "-Xep:NotJavadoc:ERROR",
@@ -80,6 +81,7 @@ java_defaults {
            "-Xep:StringCharset:ERROR",
            "-Xep:StringCharset:ERROR",
            "-Xep:TruthConstantAsserts:ERROR",
            "-Xep:TruthConstantAsserts:ERROR",
            "-Xep:TruthIncompatibleType:ERROR",
            "-Xep:TruthIncompatibleType:ERROR",
            "-Xep:UndefinedEquals:ERROR",
            "-Xep:UnnecessaryAssignment:ERROR",
            "-Xep:UnnecessaryAssignment:ERROR",
            "-Xep:UnnecessaryAsync:ERROR",
            "-Xep:UnnecessaryAsync:ERROR",
            "-Xep:UnusedMethod:ERROR",
            "-Xep:UnusedMethod:ERROR",
+2 −4
Original line number Original line Diff line number Diff line
@@ -26,12 +26,10 @@ import android.bluetooth.BluetoothCodecConfig;
import android.bluetooth.BluetoothCodecStatus;
import android.bluetooth.BluetoothCodecStatus;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.os.Bundle;
import android.os.Bundle;
import android.os.HandlerThread;
import android.os.HandlerThread;


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


@@ -252,7 +250,7 @@ public class A2dpStateMachineTest {


        // Verify that one connection state broadcast is executed
        // Verify that one connection state broadcast is executed
        ArgumentCaptor<Intent> intentArgument2 = ArgumentCaptor.forClass(Intent.class);
        ArgumentCaptor<Intent> intentArgument2 = ArgumentCaptor.forClass(Intent.class);
        verify(mA2dpService, timeout(A2dpStateMachine.sConnectTimeoutMs * 2).times(2))
        verify(mA2dpService, timeout(A2dpStateMachine.sConnectTimeoutMs * 2L).times(2))
                .sendBroadcast(intentArgument2.capture(), anyString(), any(Bundle.class));
                .sendBroadcast(intentArgument2.capture(), anyString(), any(Bundle.class));
        assertThat(intentArgument2.getValue().getIntExtra(BluetoothProfile.EXTRA_STATE, -1))
        assertThat(intentArgument2.getValue().getIntExtra(BluetoothProfile.EXTRA_STATE, -1))
                .isEqualTo(BluetoothProfile.STATE_DISCONNECTED);
                .isEqualTo(BluetoothProfile.STATE_DISCONNECTED);
@@ -289,7 +287,7 @@ public class A2dpStateMachineTest {


        // Verify that one connection state broadcast is executed
        // Verify that one connection state broadcast is executed
        ArgumentCaptor<Intent> intentArgument2 = ArgumentCaptor.forClass(Intent.class);
        ArgumentCaptor<Intent> intentArgument2 = ArgumentCaptor.forClass(Intent.class);
        verify(mA2dpService, timeout(A2dpStateMachine.sConnectTimeoutMs * 2).times(2))
        verify(mA2dpService, timeout(A2dpStateMachine.sConnectTimeoutMs * 2L).times(2))
                .sendBroadcast(intentArgument2.capture(), anyString(), any(Bundle.class));
                .sendBroadcast(intentArgument2.capture(), anyString(), any(Bundle.class));
        assertThat(intentArgument2.getValue().getIntExtra(BluetoothProfile.EXTRA_STATE, -1))
        assertThat(intentArgument2.getValue().getIntExtra(BluetoothProfile.EXTRA_STATE, -1))
                .isEqualTo(BluetoothProfile.STATE_DISCONNECTED);
                .isEqualTo(BluetoothProfile.STATE_DISCONNECTED);
+6 −4
Original line number Original line Diff line number Diff line
@@ -396,14 +396,16 @@ public class BrowserPlayerWrapperTest {
                Assert.assertNotNull(folder);
                Assert.assertNotNull(folder);
                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(), folder.title);
                Assert.assertEquals(expected.getDescription().getTitle().toString(), folder.title);
            } else {
            } else {
                Metadata song = item.song;
                Metadata song = item.song;
                Assert.assertNotNull(song);
                Assert.assertNotNull(song);
                Assert.assertEquals(expected.getDescription().getMediaId(), song.mediaId);
                Assert.assertEquals(expected.getDescription().getMediaId(), song.mediaId);
                Assert.assertEquals(expected.getDescription().getTitle(), song.title);
                Assert.assertEquals(expected.getDescription().getTitle().toString(), song.title);
                Assert.assertEquals(expected.getDescription().getSubtitle(), song.artist);
                Assert.assertEquals(
                Assert.assertEquals(expected.getDescription().getDescription(), song.album);
                        expected.getDescription().getSubtitle().toString(), song.artist);
                Assert.assertEquals(
                        expected.getDescription().getDescription().toString(), song.album);
                if (expected.getDescription().getIconBitmap() != null) {
                if (expected.getDescription().getIconBitmap() != null) {
                    Assert.assertNotNull(song.image);
                    Assert.assertNotNull(song.image);
                    Bitmap expectedBitmap = expected.getDescription().getIconBitmap();
                    Bitmap expectedBitmap = expected.getDescription().getIconBitmap();
+3 −5
Original line number Original line Diff line number Diff line
@@ -18,13 +18,11 @@ package com.android.bluetooth.avrcpcontroller;


import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.net.Uri;
import android.net.Uri;
import android.support.v4.media.MediaBrowserCompat.MediaItem;
import android.support.v4.media.MediaBrowserCompat.MediaItem;
import android.support.v4.media.MediaDescriptionCompat;
import android.support.v4.media.MediaDescriptionCompat;
import android.support.v4.media.MediaMetadataCompat;
import android.support.v4.media.MediaMetadataCompat;


import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;
import androidx.test.runner.AndroidJUnit4;


import org.junit.After;
import org.junit.After;
@@ -554,7 +552,7 @@ public final class AvrcpItemTest {
        Assert.assertEquals(UUID, desc.getMediaId());
        Assert.assertEquals(UUID, desc.getMediaId());
        Assert.assertEquals(null, desc.getMediaUri());
        Assert.assertEquals(null, desc.getMediaUri());
        Assert.assertEquals(title, desc.getTitle().toString());
        Assert.assertEquals(title, desc.getTitle().toString());
        Assert.assertEquals(desc.getSubtitle(), null);
        Assert.assertNull(desc.getSubtitle());
        Assert.assertEquals(uri, desc.getIconUri());
        Assert.assertEquals(uri, desc.getIconUri());
        Assert.assertEquals(null, desc.getIconBitmap());
        Assert.assertEquals(null, desc.getIconBitmap());
    }
    }
@@ -583,7 +581,7 @@ public final class AvrcpItemTest {
        Assert.assertEquals(UUID, desc.getMediaId());
        Assert.assertEquals(UUID, desc.getMediaId());
        Assert.assertEquals(null, desc.getMediaUri());
        Assert.assertEquals(null, desc.getMediaUri());
        Assert.assertEquals(displayName, desc.getTitle().toString());
        Assert.assertEquals(displayName, desc.getTitle().toString());
        Assert.assertEquals(desc.getSubtitle(), null);
        Assert.assertNull(desc.getSubtitle());
        Assert.assertEquals(uri, desc.getIconUri());
        Assert.assertEquals(uri, desc.getIconUri());
        Assert.assertEquals(null, desc.getIconBitmap());
        Assert.assertEquals(null, desc.getIconBitmap());
    }
    }
@@ -610,7 +608,7 @@ public final class AvrcpItemTest {
        Assert.assertEquals(UUID, desc.getMediaId());
        Assert.assertEquals(UUID, desc.getMediaId());
        Assert.assertEquals(null, desc.getMediaUri());
        Assert.assertEquals(null, desc.getMediaUri());
        Assert.assertEquals(title, desc.getTitle().toString());
        Assert.assertEquals(title, desc.getTitle().toString());
        Assert.assertEquals(desc.getSubtitle(), null);
        Assert.assertNull(desc.getSubtitle());
        Assert.assertEquals(uri, desc.getIconUri());
        Assert.assertEquals(uri, desc.getIconUri());
        Assert.assertEquals(null, desc.getIconBitmap());
        Assert.assertEquals(null, desc.getIconBitmap());
    }
    }
+4 −0
Original line number Original line Diff line number Diff line
@@ -16,6 +16,8 @@


package com.android.bluetooth.avrcpcontroller;
package com.android.bluetooth.avrcpcontroller;


import android.annotation.SuppressLint;

import androidx.test.runner.AndroidJUnit4;
import androidx.test.runner.AndroidJUnit4;


import org.junit.Assert;
import org.junit.Assert;
@@ -44,6 +46,7 @@ public class BipAttachmentFormatTest {
        return makeDate(month, day, year, hours, min, sec, null);
        return makeDate(month, day, year, hours, min, sec, null);
    }
    }


    @SuppressLint("UndefinedEquals")
    private void testParse(
    private void testParse(
            String contentType,
            String contentType,
            String charset,
            String charset,
@@ -78,6 +81,7 @@ public class BipAttachmentFormatTest {
        }
        }
    }
    }


    @SuppressLint("UndefinedEquals")
    private void testCreate(
    private void testCreate(
            String contentType,
            String contentType,
            String charset,
            String charset,
Loading