diff options
3 files changed, 386 insertions, 6 deletions
diff --git a/core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/unittests/ProgramListTest.java b/core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/unittests/ProgramListTest.java index 9e99b7c99e0d..9a999e4067c5 100644 --- a/core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/unittests/ProgramListTest.java +++ b/core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/unittests/ProgramListTest.java @@ -276,6 +276,19 @@ public final class ProgramListTest { } @Test + public void getProgramList_forTunerAdapterWhenServiceDied_fails() throws Exception { + Map<String, String> parameters = Map.of("ParameterKeyMock", "ParameterValueMock"); + createRadioTuner(); + doThrow(new RemoteException()).when(mTunerMock).startProgramListUpdates(any()); + + RuntimeException thrown = assertThrows(RuntimeException.class, + () -> mRadioTuner.getProgramList(parameters)); + + assertWithMessage("Exception for getting program list when service is dead") + .that(thrown).hasMessageThat().contains("Service died"); + } + + @Test public void getDynamicProgramList_forTunerAdapter() throws Exception { createRadioTuner(); diff --git a/core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/unittests/RadioManagerTest.java b/core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/unittests/RadioManagerTest.java index 7dd13394e48d..afbf8c304e3d 100644 --- a/core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/unittests/RadioManagerTest.java +++ b/core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/unittests/RadioManagerTest.java @@ -18,7 +18,9 @@ package android.hardware.radio.tests.unittests; import static com.google.common.truth.Truth.assertWithMessage; +import static org.junit.Assert.assertThrows; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.never; @@ -1006,6 +1008,35 @@ public final class RadioManagerTest { } @Test + public void listModules_forRadioManagerWithNullListAsInput_fails() throws Exception { + createRadioManager(); + + assertWithMessage("Status when listing module with empty list input") + .that(mRadioManager.listModules(null)).isEqualTo(RadioManager.STATUS_BAD_VALUE); + } + + @Test + public void listModules_withNullListFromService_fails() throws Exception { + createRadioManager(); + when(mRadioServiceMock.listModules()).thenReturn(null); + List<RadioManager.ModuleProperties> modules = new ArrayList<>(); + + assertWithMessage("Status for listing module when getting null list from HAL client") + .that(mRadioManager.listModules(modules)).isEqualTo(RadioManager.STATUS_ERROR); + } + + @Test + public void listModules_whenServiceDied_fails() throws Exception { + createRadioManager(); + when(mRadioServiceMock.listModules()).thenThrow(new RemoteException()); + List<RadioManager.ModuleProperties> modules = new ArrayList<>(); + + assertWithMessage("Status for listing module when HAL client service is dead") + .that(mRadioManager.listModules(modules)) + .isEqualTo(RadioManager.STATUS_DEAD_OBJECT); + } + + @Test public void openTuner_forRadioModule() throws Exception { createRadioManager(); int moduleId = 0; @@ -1019,6 +1050,18 @@ public final class RadioManagerTest { } @Test + public void openTuner_whenServiceDied_returnsNull() throws Exception { + createRadioManager(); + when(mRadioServiceMock.openTuner(anyInt(), any(), anyBoolean(), any(), anyInt())) + .thenThrow(new RemoteException()); + + RadioTuner nullTuner = mRadioManager.openTuner(/* moduleId= */ 0, FM_BAND_CONFIG, + /* withAudio= */ true, mCallbackMock, /* handler= */ null); + + assertWithMessage("Radio tuner when service is dead").that(nullTuner).isNull(); + } + + @Test public void addAnnouncementListener_withListenerNotAddedBefore() throws Exception { createRadioManager(); Set<Integer> enableTypeSet = createAnnouncementTypeSet(EVENT_ANNOUNCEMENT_TYPE); @@ -1049,6 +1092,21 @@ public final class RadioManagerTest { } @Test + public void addAnnouncementListener_whenServiceDied_throwException() throws Exception { + createRadioManager(); + String exceptionMessage = "service is dead"; + when(mRadioServiceMock.addAnnouncementListener(any(), any())) + .thenThrow(new RemoteException(exceptionMessage)); + Set<Integer> enableTypeSet = createAnnouncementTypeSet(EVENT_ANNOUNCEMENT_TYPE); + + RuntimeException thrown = assertThrows(RuntimeException.class, + () -> mRadioManager.addAnnouncementListener(enableTypeSet, mEventListener)); + + assertWithMessage("Exception for adding announcement listener with dead service") + .that(thrown).hasMessageThat().contains(exceptionMessage); + } + + @Test public void removeAnnouncementListener_withListenerNotAddedBefore_ignores() throws Exception { createRadioManager(); diff --git a/core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/unittests/TunerAdapterTest.java b/core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/unittests/TunerAdapterTest.java index d851a7724e8e..c8b4493a07d7 100644 --- a/core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/unittests/TunerAdapterTest.java +++ b/core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/unittests/TunerAdapterTest.java @@ -18,10 +18,13 @@ package android.hardware.radio.tests.unittests; import static com.google.common.truth.Truth.assertWithMessage; +import static org.junit.Assert.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -37,6 +40,7 @@ import android.hardware.radio.RadioManager; import android.hardware.radio.RadioMetadata; import android.hardware.radio.RadioTuner; import android.os.Build; +import android.os.RemoteException; import org.junit.After; import org.junit.Before; @@ -46,7 +50,6 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; -import java.util.Arrays; import java.util.List; import java.util.Map; @@ -131,6 +134,24 @@ public final class TunerAdapterTest { } @Test + public void setConfiguration_withInvalidParameters_fails() throws Exception { + doThrow(new IllegalArgumentException()).when(mTunerMock).setConfiguration(any()); + + assertWithMessage("Status for setting configuration with invalid parameters") + .that(mRadioTuner.setConfiguration(TEST_BAND_CONFIG)) + .isEqualTo(RadioManager.STATUS_BAD_VALUE); + } + + @Test + public void setConfiguration_whenServiceDied_fails() throws Exception { + doThrow(new RemoteException()).when(mTunerMock).setConfiguration(any()); + + assertWithMessage("Status for setting configuration when service is dead") + .that(mRadioTuner.setConfiguration(TEST_BAND_CONFIG)) + .isEqualTo(RadioManager.STATUS_DEAD_OBJECT); + } + + @Test public void getConfiguration_forTunerAdapter() throws Exception { when(mTunerMock.getConfiguration()).thenReturn(TEST_BAND_CONFIG); RadioManager.BandConfig[] bandConfigs = new RadioManager.BandConfig[1]; @@ -144,14 +165,52 @@ public final class TunerAdapterTest { } @Test + public void getConfiguration_withInvalidParameters_fails() throws Exception { + RadioManager.BandConfig[] bandConfigs = new RadioManager.BandConfig[0]; + + IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, + () -> mRadioTuner.getConfiguration(bandConfigs)); + + assertWithMessage("Exception for getting configuration with invalid parameters") + .that(thrown).hasMessageThat().contains("must be an array of length 1"); + } + + @Test + public void getConfiguration_whenServiceDied_fails() throws Exception { + doThrow(new RemoteException()).when(mTunerMock).getConfiguration(); + RadioManager.BandConfig[] bandConfigs = new RadioManager.BandConfig[1]; + + assertWithMessage("Status for getting configuration when service is dead") + .that(mRadioTuner.getConfiguration(bandConfigs)) + .isEqualTo(RadioManager.STATUS_DEAD_OBJECT); + } + + @Test public void setMute_forTunerAdapter() { - int status = mRadioTuner.setMute(/* mute= */ true); + int status = mRadioTuner.setMute(true); assertWithMessage("Status for setting mute") .that(status).isEqualTo(RadioManager.STATUS_OK); } @Test + public void setMute_whenIllegalState_fails() throws Exception { + doThrow(new IllegalStateException()).when(mTunerMock).setMuted(anyBoolean()); + + assertWithMessage("Status for setting muted when service is in illegal state") + .that(mRadioTuner.setMute(true)).isEqualTo(RadioManager.STATUS_ERROR); + } + + @Test + public void setMute_whenServiceDied_fails() throws Exception { + doThrow(new RemoteException()).when(mTunerMock).setMuted(anyBoolean()); + + assertWithMessage("Status for setting muted when service is dead") + .that(mRadioTuner.setMute(true)) + .isEqualTo(RadioManager.STATUS_DEAD_OBJECT); + } + + @Test public void getMute_forTunerAdapter() throws Exception { when(mTunerMock.isMuted()).thenReturn(true); @@ -161,6 +220,14 @@ public final class TunerAdapterTest { } @Test + public void getMute_whenServiceDied_returnsTrue() throws Exception { + when(mTunerMock.isMuted()).thenThrow(new RemoteException()); + + assertWithMessage("Status for getting muted when service is dead") + .that(mRadioTuner.getMute()).isEqualTo(true); + } + + @Test public void step_forTunerAdapter_succeeds() throws Exception { doAnswer(invocation -> { mTunerCallback.onCurrentProgramInfoChanged(FM_PROGRAM_INFO); @@ -176,6 +243,24 @@ public final class TunerAdapterTest { } @Test + public void step_whenIllegalState_fails() throws Exception { + doThrow(new IllegalStateException()).when(mTunerMock).step(anyBoolean(), anyBoolean()); + + assertWithMessage("Status for stepping when service is in illegal state") + .that(mRadioTuner.step(RadioTuner.DIRECTION_UP, /* skipSubChannel= */ false)) + .isEqualTo(RadioManager.STATUS_INVALID_OPERATION); + } + + @Test + public void step_whenServiceDied_fails() throws Exception { + doThrow(new RemoteException()).when(mTunerMock).step(anyBoolean(), anyBoolean()); + + assertWithMessage("Status for stepping when service is dead") + .that(mRadioTuner.step(RadioTuner.DIRECTION_UP, /* skipSubChannel= */ false)) + .isEqualTo(RadioManager.STATUS_DEAD_OBJECT); + } + + @Test public void scan_forTunerAdapter_succeeds() throws Exception { doAnswer(invocation -> { mTunerCallback.onCurrentProgramInfoChanged(FM_PROGRAM_INFO); @@ -191,13 +276,31 @@ public final class TunerAdapterTest { } @Test + public void scan_whenIllegalState_fails() throws Exception { + doThrow(new IllegalStateException()).when(mTunerMock).seek(anyBoolean(), anyBoolean()); + + assertWithMessage("Status for scanning when service is in illegal state") + .that(mRadioTuner.scan(RadioTuner.DIRECTION_UP, /* skipSubChannel= */ false)) + .isEqualTo(RadioManager.STATUS_INVALID_OPERATION); + } + + @Test + public void scan_whenServiceDied_fails() throws Exception { + doThrow(new RemoteException()).when(mTunerMock).seek(anyBoolean(), anyBoolean()); + + assertWithMessage("Status for scan when service is dead") + .that(mRadioTuner.scan(RadioTuner.DIRECTION_UP, /* skipSubChannel= */ true)) + .isEqualTo(RadioManager.STATUS_DEAD_OBJECT); + } + + @Test public void seek_forTunerAdapter_succeeds() throws Exception { doAnswer(invocation -> { mTunerCallback.onCurrentProgramInfoChanged(FM_PROGRAM_INFO); return RadioManager.STATUS_OK; }).when(mTunerMock).seek(anyBoolean(), anyBoolean()); - int scanStatus = mRadioTuner.scan(RadioTuner.DIRECTION_DOWN, /* skipSubChannel= */ false); + int scanStatus = mRadioTuner.seek(RadioTuner.DIRECTION_DOWN, /* skipSubChannel= */ false); verify(mTunerMock).seek(/* directionDown= */ true, /* skipSubChannel= */ false); assertWithMessage("Status for seeking") @@ -212,13 +315,31 @@ public final class TunerAdapterTest { return RadioManager.STATUS_OK; }).when(mTunerMock).seek(anyBoolean(), anyBoolean()); - mRadioTuner.scan(RadioTuner.DIRECTION_UP, /* skipSubChannel*/ true); + mRadioTuner.seek(RadioTuner.DIRECTION_UP, /* skipSubChannel= */ true); verify(mCallbackMock, timeout(CALLBACK_TIMEOUT_MS)).onTuneFailed( RadioTuner.TUNER_RESULT_TIMEOUT, FM_SELECTOR); } @Test + public void seek_whenIllegalState_fails() throws Exception { + doThrow(new IllegalStateException()).when(mTunerMock).seek(anyBoolean(), anyBoolean()); + + assertWithMessage("Status for seeking when service is in illegal state") + .that(mRadioTuner.seek(RadioTuner.DIRECTION_UP, /* skipSubChannel= */ false)) + .isEqualTo(RadioManager.STATUS_INVALID_OPERATION); + } + + @Test + public void seek_whenServiceDied_fails() throws Exception { + doThrow(new RemoteException()).when(mTunerMock).seek(anyBoolean(), anyBoolean()); + + assertWithMessage("Status for seeking when service is dead") + .that(mRadioTuner.seek(RadioTuner.DIRECTION_UP, /* skipSubChannel= */ true)) + .isEqualTo(RadioManager.STATUS_DEAD_OBJECT); + } + + @Test public void tune_withChannelsForTunerAdapter_succeeds() { int status = mRadioTuner.tune(/* channel= */ 92300, /* subChannel= */ 0); @@ -228,6 +349,33 @@ public final class TunerAdapterTest { } @Test + public void tune_withInvalidChannel_fails() throws Exception { + doThrow(new IllegalArgumentException()).when(mTunerMock).tune(any()); + + assertWithMessage("Status for tuning when service is in illegal state") + .that(mRadioTuner.tune(/* channel= */ 300, /* subChannel= */ 0)) + .isEqualTo(RadioManager.STATUS_BAD_VALUE); + } + + @Test + public void tune_withChannelsWhenIllegalState_fails() throws Exception { + doThrow(new IllegalStateException()).when(mTunerMock).tune(any()); + + assertWithMessage("Status for tuning when service is in illegal state") + .that(mRadioTuner.tune(/* channel= */ 92300, /* subChannel= */ 0)) + .isEqualTo(RadioManager.STATUS_INVALID_OPERATION); + } + + @Test + public void tune_withChannelsWhenServiceDied_fails() throws Exception { + doThrow(new RemoteException()).when(mTunerMock).tune(any()); + + assertWithMessage("Status for tuning when service is dead") + .that(mRadioTuner.tune(/* channel= */ 92300, /* subChannel= */ 0)) + .isEqualTo(RadioManager.STATUS_DEAD_OBJECT); + } + + @Test public void tune_withValidSelectorForTunerAdapter_succeeds() throws Exception { mRadioTuner.tune(FM_SELECTOR); @@ -250,6 +398,17 @@ public final class TunerAdapterTest { } @Test + public void tune_withSelectorWhenServiceDied_fails() throws Exception { + doThrow(new RemoteException()).when(mTunerMock).tune(any()); + + RuntimeException thrown = assertThrows(RuntimeException.class, + () -> mRadioTuner.tune(FM_SELECTOR)); + + assertWithMessage("Exception for tuning when service is dead") + .that(thrown).hasMessageThat().contains("Service died"); + } + + @Test public void cancel_forTunerAdapter() throws Exception { mRadioTuner.tune(FM_SELECTOR); @@ -259,6 +418,22 @@ public final class TunerAdapterTest { } @Test + public void cancel_whenIllegalState_fails() throws Exception { + doThrow(new IllegalStateException()).when(mTunerMock).cancel(); + + assertWithMessage("Status for canceling when service is in illegal state") + .that(mRadioTuner.cancel()).isEqualTo(RadioManager.STATUS_INVALID_OPERATION); + } + + @Test + public void cancel_forTunerAdapterWhenServiceDied_fails() throws Exception { + doThrow(new RemoteException()).when(mTunerMock).cancel(); + + assertWithMessage("Status for canceling when service is dead") + .that(mRadioTuner.cancel()).isEqualTo(RadioManager.STATUS_DEAD_OBJECT); + } + + @Test public void cancelAnnouncement_forTunerAdapter() throws Exception { mRadioTuner.cancelAnnouncement(); @@ -266,6 +441,17 @@ public final class TunerAdapterTest { } @Test + public void cancelAnnouncement_whenServiceDied_fails() throws Exception { + doThrow(new RemoteException()).when(mTunerMock).cancelAnnouncement(); + + RuntimeException thrown = assertThrows(RuntimeException.class, + () -> mRadioTuner.cancelAnnouncement()); + + assertWithMessage("Exception for canceling announcement when service is dead") + .that(thrown).hasMessageThat().contains("Service died"); + } + + @Test public void getProgramInfo_beforeProgramInfoSetForTunerAdapter() { RadioManager.ProgramInfo[] programInfoArray = new RadioManager.ProgramInfo[1]; @@ -295,13 +481,24 @@ public final class TunerAdapterTest { when(mTunerMock.getImage(anyInt())).thenReturn(bitmapExpected); int imageId = 1; - Bitmap image = mRadioTuner.getMetadataImage(/* id= */ imageId); + Bitmap image = mRadioTuner.getMetadataImage(imageId); assertWithMessage("Image obtained from id %s", imageId) .that(image).isEqualTo(bitmapExpected); } @Test + public void getMetadataImage_whenServiceDied_fails() throws Exception { + when(mTunerMock.getImage(anyInt())).thenThrow(new RemoteException()); + + RuntimeException thrown = assertThrows(RuntimeException.class, + () -> mRadioTuner.getMetadataImage(/* id= */ 1)); + + assertWithMessage("Exception for getting metadata image when service is dead") + .that(thrown).hasMessageThat().contains("Service died"); + } + + @Test public void startBackgroundScan_forTunerAdapter() throws Exception { when(mTunerMock.startBackgroundScan()).thenReturn(false); @@ -312,6 +509,17 @@ public final class TunerAdapterTest { } @Test + public void startBackgroundScan_whenServiceDied_fails() throws Exception { + when(mTunerMock.startBackgroundScan()).thenThrow(new RemoteException()); + + RuntimeException thrown = assertThrows(RuntimeException.class, + () -> mRadioTuner.startBackgroundScan()); + + assertWithMessage("Exception for background scan when service is dead") + .that(thrown).hasMessageThat().contains("Service died"); + } + + @Test public void isAnalogForced_forTunerAdapter() throws Exception { when(mTunerMock.isConfigFlagSet(RadioManager.CONFIG_FORCE_ANALOG)).thenReturn(true); @@ -322,6 +530,19 @@ public final class TunerAdapterTest { } @Test + public void isAnalogForced_whenNotSupported_fails() throws Exception { + String errorMessage = "Analog forced switch is not supported"; + when(mTunerMock.isConfigFlagSet(RadioManager.CONFIG_FORCE_ANALOG)) + .thenThrow(new UnsupportedOperationException(errorMessage)); + + IllegalStateException thrown = assertThrows(IllegalStateException.class, + () -> mRadioTuner.isAnalogForced()); + + assertWithMessage("Exception for checking analog playback switch when not supported") + .that(thrown).hasMessageThat().contains(errorMessage); + } + + @Test public void setAnalogForced_forTunerAdapter() throws Exception { boolean analogForced = true; @@ -331,6 +552,19 @@ public final class TunerAdapterTest { } @Test + public void setAnalogForced_whenNotSupported_fails() throws Exception { + String errorMessage = "Analog forced switch is not supported"; + doThrow(new UnsupportedOperationException(errorMessage)) + .when(mTunerMock).setConfigFlag(eq(RadioManager.CONFIG_FORCE_ANALOG), anyBoolean()); + + IllegalStateException thrown = assertThrows(IllegalStateException.class, + () -> mRadioTuner.setAnalogForced(/* isForced= */ false)); + + assertWithMessage("Exception for setting analog playback switch when not supported") + .that(thrown).hasMessageThat().contains(errorMessage); + } + + @Test public void isConfigFlagSupported_forTunerAdapter() throws Exception { when(mTunerMock.isConfigFlagSupported(RadioManager.CONFIG_DAB_DAB_LINKING)) .thenReturn(true); @@ -343,6 +577,17 @@ public final class TunerAdapterTest { } @Test + public void isConfigFlagSupported_whenServiceDied_fails() throws Exception { + when(mTunerMock.isConfigFlagSupported(anyInt())).thenThrow(new RemoteException()); + + RuntimeException thrown = assertThrows(RuntimeException.class, + () -> mRadioTuner.isConfigFlagSupported(RadioManager.CONFIG_DAB_DAB_LINKING)); + + assertWithMessage("Exception for checking config flag support when service is dead") + .that(thrown).hasMessageThat().contains("Service died"); + } + + @Test public void isConfigFlagSet_forTunerAdapter() throws Exception { when(mTunerMock.isConfigFlagSet(RadioManager.CONFIG_DAB_FM_SOFT_LINKING)) .thenReturn(true); @@ -355,6 +600,17 @@ public final class TunerAdapterTest { } @Test + public void isConfigFlagSet_whenServiceDied_fails() throws Exception { + when(mTunerMock.isConfigFlagSet(anyInt())).thenThrow(new RemoteException()); + + RuntimeException thrown = assertThrows(RuntimeException.class, + () -> mRadioTuner.isConfigFlagSet(RadioManager.CONFIG_DAB_DAB_LINKING)); + + assertWithMessage("Exception for getting config flag when service is dead") + .that(thrown).hasMessageThat().contains("Service died"); + } + + @Test public void setConfigFlag_forTunerAdapter() throws Exception { boolean dabFmLinking = true; @@ -364,8 +620,20 @@ public final class TunerAdapterTest { } @Test + public void setConfigFlag_whenServiceDied_fails() throws Exception { + doThrow(new RemoteException()).when(mTunerMock).setConfigFlag(anyInt(), anyBoolean()); + + RuntimeException thrown = assertThrows(RuntimeException.class, + () -> mRadioTuner.setConfigFlag(RadioManager.CONFIG_DAB_DAB_LINKING, + /* value= */ true)); + + assertWithMessage("Exception for setting config flag when service is dead") + .that(thrown).hasMessageThat().contains("Service died"); + } + + @Test public void getParameters_forTunerAdapter() throws Exception { - List<String> parameterKeys = Arrays.asList("ParameterKeyMock"); + List<String> parameterKeys = List.of("ParameterKeyMock"); Map<String, String> parameters = Map.of("ParameterKeyMock", "ParameterValueMock"); when(mTunerMock.getParameters(parameterKeys)).thenReturn(parameters); @@ -374,6 +642,18 @@ public final class TunerAdapterTest { } @Test + public void getParameters_whenServiceDied_fails() throws Exception { + List<String> parameterKeys = List.of("ParameterKeyMock"); + when(mTunerMock.getParameters(parameterKeys)).thenThrow(new RemoteException()); + + RuntimeException thrown = assertThrows(RuntimeException.class, + () -> mRadioTuner.getParameters(parameterKeys)); + + assertWithMessage("Exception for getting parameters when service is dead") + .that(thrown).hasMessageThat().contains("Service died"); + } + + @Test public void setParameters_forTunerAdapter() throws Exception { Map<String, String> parameters = Map.of("ParameterKeyMock", "ParameterValueMock"); when(mTunerMock.setParameters(parameters)).thenReturn(parameters); @@ -383,6 +663,18 @@ public final class TunerAdapterTest { } @Test + public void setParameters_whenServiceDied_fails() throws Exception { + Map<String, String> parameters = Map.of("ParameterKeyMock", "ParameterValueMock"); + when(mTunerMock.setParameters(parameters)).thenThrow(new RemoteException()); + + RuntimeException thrown = assertThrows(RuntimeException.class, + () -> mRadioTuner.setParameters(parameters)); + + assertWithMessage("Exception for setting parameters when service is dead") + .that(thrown).hasMessageThat().contains("Service died"); + } + + @Test public void isAntennaConnected_forTunerAdapter() throws Exception { mTunerCallback.onAntennaState(/* connected= */ false); @@ -391,6 +683,15 @@ public final class TunerAdapterTest { } @Test + public void onError_forTunerAdapter() throws Exception { + int errorStatus = RadioTuner.ERROR_HARDWARE_FAILURE; + + mTunerCallback.onError(errorStatus); + + verify(mCallbackMock, timeout(CALLBACK_TIMEOUT_MS)).onError(errorStatus); + } + + @Test public void hasControl_forTunerAdapter() throws Exception { when(mTunerMock.isClosed()).thenReturn(true); @@ -398,6 +699,14 @@ public final class TunerAdapterTest { } @Test + public void hasControl_whenServiceDied_returnsFalse() throws Exception { + when(mTunerMock.isClosed()).thenThrow(new RemoteException()); + + assertWithMessage("Control on tuner when service is dead") + .that(mRadioTuner.hasControl()).isFalse(); + } + + @Test public void onConfigurationChanged_forTunerCallbackAdapter() throws Exception { mTunerCallback.onConfigurationChanged(TEST_BAND_CONFIG); |