Loading android/app/tests/unit/src/com/android/bluetooth/TestUtils.java +15 −1 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -29,11 +30,12 @@ import android.content.res.Resources; import android.os.Handler; import android.os.Looper; import android.os.MessageQueue; import android.os.Process; import android.service.media.MediaBrowserService; import androidx.test.InstrumentationRegistry; import androidx.test.rule.ServiceTestRule; import com.android.bluetooth.avrcpcontroller.BluetoothMediaBrowserService; import com.android.bluetooth.btservice.AdapterService; import com.android.bluetooth.btservice.ProfileService; Loading Loading @@ -366,6 +368,18 @@ public class TestUtils { return adapterConfig; } /** * Prepare the intent to start bluetooth browser media service. * * @return intent with the appropriate component & action set. */ public static Intent prepareIntentToStartBluetoothBrowserMediaService() { final Intent intent = new Intent(InstrumentationRegistry.getTargetContext(), BluetoothMediaBrowserService.class); intent.setAction(MediaBrowserService.SERVICE_INTERFACE); return intent; } /** * Helper class used to run synchronously a runnable action on a looper. */ Loading android/app/tests/unit/src/com/android/bluetooth/a2dpsink/A2dpSinkStreamHandlerTest.java +8 −3 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.*; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.content.res.Resources; import android.media.AudioManager; Loading @@ -39,7 +40,6 @@ import com.android.bluetooth.avrcpcontroller.BluetoothMediaBrowserService; import com.android.bluetooth.btservice.AdapterService; import org.junit.After; import org.junit.Assume; import org.junit.Before; import org.junit.Rule; import org.junit.Test; Loading Loading @@ -68,6 +68,9 @@ public class A2dpSinkStreamHandlerTest { @Rule public final ServiceTestRule mServiceRule = new ServiceTestRule(); @Rule public final ServiceTestRule mBluetoothBrowserMediaServiceTestRule = new ServiceTestRule(); @Mock private AdapterService mAdapterService; Loading @@ -82,6 +85,9 @@ public class A2dpSinkStreamHandlerTest { TestUtils.setAdapterService(mAdapterService); doReturn(true, false).when(mAdapterService).isStartedProfile(anyString()); TestUtils.startService(mServiceRule, AvrcpControllerService.class); final Intent bluetoothBrowserMediaServiceStartIntent = TestUtils.prepareIntentToStartBluetoothBrowserMediaService(); mBluetoothBrowserMediaServiceTestRule.startService(bluetoothBrowserMediaServiceStartIntent); mHandlerThread = new HandlerThread("A2dpSinkStreamHandlerTest"); mHandlerThread.start(); Loading @@ -101,7 +107,6 @@ public class A2dpSinkStreamHandlerTest { when(mMockPackageManager.hasSystemFeature(any())).thenReturn(false); mStreamHandler = spy(new A2dpSinkStreamHandler(mMockA2dpSink, mMockNativeInterface)); BluetoothMediaBrowserService.setActive(false); } @After Loading android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpBipClientTest.java +7 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import static org.mockito.Mockito.doReturn; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothProfile; import android.content.Intent; import androidx.test.filters.SmallTest; import androidx.test.rule.ServiceTestRule; Loading @@ -49,6 +50,9 @@ public class AvrcpBipClientTest { @Rule public final ServiceTestRule mServiceRule = new ServiceTestRule(); @Rule public final ServiceTestRule mBluetoothBrowserMediaServiceTestRule = new ServiceTestRule(); @Mock private AdapterService mAdapterService; Loading @@ -65,6 +69,9 @@ public class AvrcpBipClientTest { doReturn(true, false).when(mAdapterService).isStartedProfile(anyString()); TestUtils.startService(mServiceRule, AvrcpControllerService.class); mService = AvrcpControllerService.getAvrcpControllerService(); final Intent bluetoothBrowserMediaServiceStartIntent = TestUtils.prepareIntentToStartBluetoothBrowserMediaService(); mBluetoothBrowserMediaServiceTestRule.startService(bluetoothBrowserMediaServiceStartIntent); mAdapter = BluetoothAdapter.getDefaultAdapter(); mTestDevice = mAdapter.getRemoteDevice("00:01:02:03:04:05"); Loading android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerServiceTest.java +7 −2 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import static org.mockito.Mockito.when; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothProfile; import android.content.Intent; import android.media.AudioManager; import android.support.v4.media.session.PlaybackStateCompat; Loading Loading @@ -60,6 +61,8 @@ public class AvrcpControllerServiceTest { private BluetoothAdapter mAdapter = null; @Rule public final ServiceTestRule mServiceRule = new ServiceTestRule(); @Rule public final ServiceTestRule mBluetoothBrowserMediaServiceTestRule = new ServiceTestRule(); @Mock private AdapterService mAdapterService; @Mock private AvrcpControllerStateMachine mStateMachine; Loading @@ -79,7 +82,9 @@ public class AvrcpControllerServiceTest { assertThat(mAdapter).isNotNull(); mRemoteDevice = mAdapter.getRemoteDevice(REMOTE_DEVICE_ADDRESS); mService.mDeviceStateMap.put(mRemoteDevice, mStateMachine); BluetoothMediaBrowserService.setActive(false); final Intent bluetoothBrowserMediaServiceStartIntent = TestUtils.prepareIntentToStartBluetoothBrowserMediaService(); mBluetoothBrowserMediaServiceTestRule.startService(bluetoothBrowserMediaServiceStartIntent); } @After Loading Loading
android/app/tests/unit/src/com/android/bluetooth/TestUtils.java +15 −1 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -29,11 +30,12 @@ import android.content.res.Resources; import android.os.Handler; import android.os.Looper; import android.os.MessageQueue; import android.os.Process; import android.service.media.MediaBrowserService; import androidx.test.InstrumentationRegistry; import androidx.test.rule.ServiceTestRule; import com.android.bluetooth.avrcpcontroller.BluetoothMediaBrowserService; import com.android.bluetooth.btservice.AdapterService; import com.android.bluetooth.btservice.ProfileService; Loading Loading @@ -366,6 +368,18 @@ public class TestUtils { return adapterConfig; } /** * Prepare the intent to start bluetooth browser media service. * * @return intent with the appropriate component & action set. */ public static Intent prepareIntentToStartBluetoothBrowserMediaService() { final Intent intent = new Intent(InstrumentationRegistry.getTargetContext(), BluetoothMediaBrowserService.class); intent.setAction(MediaBrowserService.SERVICE_INTERFACE); return intent; } /** * Helper class used to run synchronously a runnable action on a looper. */ Loading
android/app/tests/unit/src/com/android/bluetooth/a2dpsink/A2dpSinkStreamHandlerTest.java +8 −3 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.*; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.content.res.Resources; import android.media.AudioManager; Loading @@ -39,7 +40,6 @@ import com.android.bluetooth.avrcpcontroller.BluetoothMediaBrowserService; import com.android.bluetooth.btservice.AdapterService; import org.junit.After; import org.junit.Assume; import org.junit.Before; import org.junit.Rule; import org.junit.Test; Loading Loading @@ -68,6 +68,9 @@ public class A2dpSinkStreamHandlerTest { @Rule public final ServiceTestRule mServiceRule = new ServiceTestRule(); @Rule public final ServiceTestRule mBluetoothBrowserMediaServiceTestRule = new ServiceTestRule(); @Mock private AdapterService mAdapterService; Loading @@ -82,6 +85,9 @@ public class A2dpSinkStreamHandlerTest { TestUtils.setAdapterService(mAdapterService); doReturn(true, false).when(mAdapterService).isStartedProfile(anyString()); TestUtils.startService(mServiceRule, AvrcpControllerService.class); final Intent bluetoothBrowserMediaServiceStartIntent = TestUtils.prepareIntentToStartBluetoothBrowserMediaService(); mBluetoothBrowserMediaServiceTestRule.startService(bluetoothBrowserMediaServiceStartIntent); mHandlerThread = new HandlerThread("A2dpSinkStreamHandlerTest"); mHandlerThread.start(); Loading @@ -101,7 +107,6 @@ public class A2dpSinkStreamHandlerTest { when(mMockPackageManager.hasSystemFeature(any())).thenReturn(false); mStreamHandler = spy(new A2dpSinkStreamHandler(mMockA2dpSink, mMockNativeInterface)); BluetoothMediaBrowserService.setActive(false); } @After Loading
android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpBipClientTest.java +7 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import static org.mockito.Mockito.doReturn; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothProfile; import android.content.Intent; import androidx.test.filters.SmallTest; import androidx.test.rule.ServiceTestRule; Loading @@ -49,6 +50,9 @@ public class AvrcpBipClientTest { @Rule public final ServiceTestRule mServiceRule = new ServiceTestRule(); @Rule public final ServiceTestRule mBluetoothBrowserMediaServiceTestRule = new ServiceTestRule(); @Mock private AdapterService mAdapterService; Loading @@ -65,6 +69,9 @@ public class AvrcpBipClientTest { doReturn(true, false).when(mAdapterService).isStartedProfile(anyString()); TestUtils.startService(mServiceRule, AvrcpControllerService.class); mService = AvrcpControllerService.getAvrcpControllerService(); final Intent bluetoothBrowserMediaServiceStartIntent = TestUtils.prepareIntentToStartBluetoothBrowserMediaService(); mBluetoothBrowserMediaServiceTestRule.startService(bluetoothBrowserMediaServiceStartIntent); mAdapter = BluetoothAdapter.getDefaultAdapter(); mTestDevice = mAdapter.getRemoteDevice("00:01:02:03:04:05"); Loading
android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerServiceTest.java +7 −2 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import static org.mockito.Mockito.when; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothProfile; import android.content.Intent; import android.media.AudioManager; import android.support.v4.media.session.PlaybackStateCompat; Loading Loading @@ -60,6 +61,8 @@ public class AvrcpControllerServiceTest { private BluetoothAdapter mAdapter = null; @Rule public final ServiceTestRule mServiceRule = new ServiceTestRule(); @Rule public final ServiceTestRule mBluetoothBrowserMediaServiceTestRule = new ServiceTestRule(); @Mock private AdapterService mAdapterService; @Mock private AvrcpControllerStateMachine mStateMachine; Loading @@ -79,7 +82,9 @@ public class AvrcpControllerServiceTest { assertThat(mAdapter).isNotNull(); mRemoteDevice = mAdapter.getRemoteDevice(REMOTE_DEVICE_ADDRESS); mService.mDeviceStateMap.put(mRemoteDevice, mStateMachine); BluetoothMediaBrowserService.setActive(false); final Intent bluetoothBrowserMediaServiceStartIntent = TestUtils.prepareIntentToStartBluetoothBrowserMediaService(); mBluetoothBrowserMediaServiceTestRule.startService(bluetoothBrowserMediaServiceStartIntent); } @After Loading