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

Commit 7a6bbddb authored by Weilin Xu's avatar Weilin Xu Committed by Android (Google) Code Review
Browse files

Merge "Improve code coverage for radio manager and tuner" into main

parents f3ff3b5f bdd35016
Loading
Loading
Loading
Loading
+17 −4
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ 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.doThrow;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -728,10 +729,10 @@ public final class RadioManagerTest {

    @Test
    public void equals_withFmBandConfigsOfDifferentAfSupportValues() {
        RadioManager.FmBandConfig fmBandConfigCompared = new RadioManager.FmBandConfig(
                new RadioManager.FmBandDescriptor(REGION, RadioManager.BAND_FM, FM_LOWER_LIMIT,
                        FM_UPPER_LIMIT, FM_SPACING, STEREO_SUPPORTED, RDS_SUPPORTED, TA_SUPPORTED,
                        !AF_SUPPORTED, EA_SUPPORTED));
        RadioManager.FmBandConfig.Builder builder = new RadioManager.FmBandConfig.Builder(
                createFmBandDescriptor()).setStereo(STEREO_SUPPORTED).setRds(RDS_SUPPORTED)
                .setTa(TA_SUPPORTED).setAf(!AF_SUPPORTED).setEa(EA_SUPPORTED);
        RadioManager.FmBandConfig fmBandConfigCompared = builder.build();

        assertWithMessage("FM Band Config of different af support value")
                .that(FM_BAND_CONFIG).isNotEqualTo(fmBandConfigCompared);
@@ -1299,6 +1300,18 @@ public final class RadioManagerTest {
        verify(mCloseHandleMock).close();
    }

    @Test
    public void addAnnouncementListener_withListenerAddedBeforeAndCloseException_throws()
            throws Exception {
        createRadioManager();
        Set<Integer> enableTypeSet = createAnnouncementTypeSet(EVENT_ANNOUNCEMENT_TYPE);
        mRadioManager.addAnnouncementListener(enableTypeSet, mEventListener);
        doThrow(new RemoteException()).when(mCloseHandleMock).close();

        assertThrows(RuntimeException.class,
                () -> mRadioManager.addAnnouncementListener(enableTypeSet, mEventListener));
    }

    @Test
    public void addAnnouncementListener_whenServiceDied_throwException() throws Exception {
        createRadioManager();
+25 −0
Original line number Diff line number Diff line
@@ -124,6 +124,16 @@ public final class TunerAdapterTest {
        verify(mTunerMock).close();
    }

    @Test
    public void close_forTunerAdapterCalledTwice() throws Exception {
        mRadioTuner.close();
        verify(mTunerMock).close();

        mRadioTuner.close();

        verify(mTunerMock).close();
    }

    @Test
    public void setConfiguration_forTunerAdapter() throws Exception {
        int status = mRadioTuner.setConfiguration(TEST_BAND_CONFIG);
@@ -133,6 +143,12 @@ public final class TunerAdapterTest {
                .that(status).isEqualTo(RadioManager.STATUS_OK);
    }

    @Test
    public void setConfiguration_withNull_fails() throws Exception {
        assertWithMessage("Status for setting configuration with null")
                .that(mRadioTuner.setConfiguration(null)).isEqualTo(RadioManager.STATUS_BAD_VALUE);
    }

    @Test
    public void setConfiguration_withInvalidParameters_fails() throws Exception {
        doThrow(new IllegalArgumentException()).when(mTunerMock).setConfiguration(any());
@@ -839,6 +855,15 @@ public final class TunerAdapterTest {
        verify(mCallbackMock, timeout(CALLBACK_TIMEOUT_MS)).onError(RadioTuner.ERROR_CANCELLED);
    }

    @Test
    public void onTuneFailed_withDeadService() throws Exception {
        mTunerCallback.onTuneFailed(RadioManager.STATUS_DEAD_OBJECT, FM_SELECTOR);

        verify(mCallbackMock, timeout(CALLBACK_TIMEOUT_MS)).onTuneFailed(
                RadioManager.STATUS_DEAD_OBJECT, FM_SELECTOR);
        verify(mCallbackMock, timeout(CALLBACK_TIMEOUT_MS)).onError(RadioTuner.ERROR_SERVER_DIED);
    }

    @Test
    public void onProgramListChanged_forTunerCallbackAdapter() throws Exception {
        mTunerCallback.onProgramListChanged();