Add unit tests about throwing expection for radio
Bug: 262583864 Test: atest android.hardware.radio.tests.unittests Test: com.android.server.broadcastradio Change-Id: I0264c0541cca4a026e4b4d3ab37cd4301f9887ab
This commit is contained in:
@@ -275,6 +275,19 @@ public final class ProgramListTest {
|
||||
assertWithMessage("Chunks").that(chunks).hasLength(CREATOR_ARRAY_SIZE);
|
||||
}
|
||||
|
||||
@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();
|
||||
|
||||
@@ -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;
|
||||
@@ -1005,6 +1007,35 @@ public final class RadioManagerTest {
|
||||
.that(modules).containsExactly(AMFM_PROPERTIES);
|
||||
}
|
||||
|
||||
@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();
|
||||
@@ -1018,6 +1049,18 @@ public final class RadioManagerTest {
|
||||
anyInt());
|
||||
}
|
||||
|
||||
@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();
|
||||
@@ -1048,6 +1091,21 @@ public final class RadioManagerTest {
|
||||
verify(mCloseHandleMock).close();
|
||||
}
|
||||
|
||||
@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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -130,6 +133,24 @@ public final class TunerAdapterTest {
|
||||
.that(status).isEqualTo(RadioManager.STATUS_OK);
|
||||
}
|
||||
|
||||
@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);
|
||||
@@ -143,14 +164,52 @@ public final class TunerAdapterTest {
|
||||
.that(bandConfigs[0]).isEqualTo(TEST_BAND_CONFIG);
|
||||
}
|
||||
|
||||
@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);
|
||||
@@ -160,6 +219,14 @@ public final class TunerAdapterTest {
|
||||
assertWithMessage("Mute status").that(muteStatus).isTrue();
|
||||
}
|
||||
|
||||
@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 -> {
|
||||
@@ -175,6 +242,24 @@ public final class TunerAdapterTest {
|
||||
verify(mCallbackMock, timeout(CALLBACK_TIMEOUT_MS)).onProgramInfoChanged(FM_PROGRAM_INFO);
|
||||
}
|
||||
|
||||
@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 -> {
|
||||
@@ -190,6 +275,24 @@ public final class TunerAdapterTest {
|
||||
verify(mCallbackMock, timeout(CALLBACK_TIMEOUT_MS)).onProgramInfoChanged(FM_PROGRAM_INFO);
|
||||
}
|
||||
|
||||
@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 -> {
|
||||
@@ -197,7 +300,7 @@ public final class TunerAdapterTest {
|
||||
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,12 +315,30 @@ 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);
|
||||
@@ -227,6 +348,33 @@ public final class TunerAdapterTest {
|
||||
verify(mCallbackMock, timeout(CALLBACK_TIMEOUT_MS)).onProgramInfoChanged(FM_PROGRAM_INFO);
|
||||
}
|
||||
|
||||
@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);
|
||||
@@ -249,6 +397,17 @@ public final class TunerAdapterTest {
|
||||
.onTuneFailed(RadioTuner.TUNER_RESULT_INVALID_ARGUMENTS, invalidSelector);
|
||||
}
|
||||
|
||||
@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);
|
||||
@@ -258,6 +417,22 @@ public final class TunerAdapterTest {
|
||||
verify(mTunerMock).cancel();
|
||||
}
|
||||
|
||||
@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();
|
||||
@@ -265,6 +440,17 @@ public final class TunerAdapterTest {
|
||||
verify(mTunerMock).cancelAnnouncement();
|
||||
}
|
||||
|
||||
@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,12 +481,23 @@ 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);
|
||||
@@ -311,6 +508,17 @@ public final class TunerAdapterTest {
|
||||
assertWithMessage("Status for starting background scan").that(scanStatus).isFalse();
|
||||
}
|
||||
|
||||
@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);
|
||||
@@ -321,6 +529,19 @@ public final class TunerAdapterTest {
|
||||
.that(isAnalogForced).isTrue();
|
||||
}
|
||||
|
||||
@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;
|
||||
@@ -330,6 +551,19 @@ public final class TunerAdapterTest {
|
||||
verify(mTunerMock).setConfigFlag(RadioManager.CONFIG_FORCE_ANALOG, analogForced);
|
||||
}
|
||||
|
||||
@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))
|
||||
@@ -342,6 +576,17 @@ public final class TunerAdapterTest {
|
||||
.that(dabFmSoftLinking).isTrue();
|
||||
}
|
||||
|
||||
@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))
|
||||
@@ -354,6 +599,17 @@ public final class TunerAdapterTest {
|
||||
.that(dabFmSoftLinking).isTrue();
|
||||
}
|
||||
|
||||
@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;
|
||||
@@ -363,9 +619,21 @@ public final class TunerAdapterTest {
|
||||
verify(mTunerMock).setConfigFlag(RadioManager.CONFIG_DAB_FM_LINKING, dabFmLinking);
|
||||
}
|
||||
|
||||
@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);
|
||||
|
||||
@@ -373,6 +641,18 @@ public final class TunerAdapterTest {
|
||||
.that(mRadioTuner.getParameters(parameterKeys)).isEqualTo(parameters);
|
||||
}
|
||||
|
||||
@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");
|
||||
@@ -382,6 +662,18 @@ public final class TunerAdapterTest {
|
||||
.that(mRadioTuner.setParameters(parameters)).isEqualTo(parameters);
|
||||
}
|
||||
|
||||
@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);
|
||||
@@ -390,6 +682,15 @@ public final class TunerAdapterTest {
|
||||
.that(mRadioTuner.isAntennaConnected()).isFalse();
|
||||
}
|
||||
|
||||
@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);
|
||||
@@ -397,6 +698,14 @@ public final class TunerAdapterTest {
|
||||
assertWithMessage("Control on tuner").that(mRadioTuner.hasControl()).isFalse();
|
||||
}
|
||||
|
||||
@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);
|
||||
|
||||
Reference in New Issue
Block a user