Loading core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/IRadioServiceAidlImplTest.java +11 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; 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; Loading Loading @@ -123,6 +124,16 @@ public final class IRadioServiceAidlImplTest extends ExtendedRadioMockitoTestCas .that(tuner).isEqualTo(mTunerMock); } @Test public void openTuner_withNullCallbackForAidlImpl_fails() throws Exception { IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> mAidlImpl.openTuner(/* moduleId= */ 0, mBandConfigMock, /* withAudio= */ true, /* callback= */ null, TARGET_SDK_VERSION)); assertWithMessage("Exception for opening tuner with null callback") .that(thrown).hasMessageThat().contains("Callback must not be null"); } @Test public void addAnnouncementListener_forAidlImpl() { ICloseHandle closeHandle = mAidlImpl.addAnnouncementListener(ENABLE_TYPES, mListenerMock); Loading core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/IRadioServiceHidlImplTest.java +11 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.server.broadcastradio; 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; Loading Loading @@ -120,6 +121,16 @@ public final class IRadioServiceHidlImplTest { .that(tuner).isEqualTo(mHal2TunerMock); } @Test public void openTuner_withNullCallbackForHidlImpl_fails() throws Exception { NullPointerException thrown = assertThrows(NullPointerException.class, () -> mHidlImpl.openTuner(/* moduleId= */ 0, mBandConfigMock, /* withAudio= */ true, /* callback= */ null, TARGET_SDK_VERSION)); assertWithMessage("Exception for opening tuner with null callback") .that(thrown).hasMessageThat().contains("Callback must not be null"); } @Test public void addAnnouncementListener_forHidlImpl() { when(mHal2Mock.hasAnyModules()).thenReturn(true); Loading core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/RadioServiceUserControllerTest.java +9 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.server.broadcastradio; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doThrow; import static com.google.common.truth.Truth.assertWithMessage; Loading Loading @@ -78,4 +79,12 @@ public final class RadioServiceUserControllerTest extends ExtendedRadioMockitoTe assertWithMessage("System user") .that(RadioServiceUserController.isCurrentOrSystemUser()).isTrue(); } @Test public void isCurrentUser_withActivityManagerFails_returnsFalse() { doThrow(new RuntimeException()).when(() -> ActivityManager.getCurrentUser()); assertWithMessage("User when activity manager fails") .that(RadioServiceUserController.isCurrentOrSystemUser()).isFalse(); } } core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/AnnouncementAggregatorTest.java +29 −0 Original line number Diff line number Diff line Loading @@ -18,9 +18,11 @@ package com.android.server.broadcastradio.aidl; 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.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; Loading Loading @@ -107,6 +109,33 @@ public final class AnnouncementAggregatorTest { } } @Test public void onListUpdated_afterClosed_notUpdated() throws Exception { ArgumentCaptor<IAnnouncementListener> moduleWatcherCaptor = ArgumentCaptor.forClass(IAnnouncementListener.class); watchModules(/* moduleNumber= */ 1); verify(mRadioModuleMocks[0]).addAnnouncementListener(moduleWatcherCaptor.capture(), any()); mAnnouncementAggregator.close(); moduleWatcherCaptor.getValue().onListUpdated(Arrays.asList(mAnnouncementMocks[0])); verify(mListenerMock, never()).onListUpdated(any()); } @Test public void watchModule_afterClosed_throwsException() throws Exception { watchModules(/* moduleNumber= */ 1); mAnnouncementAggregator.close(); IllegalStateException thrown = assertThrows(IllegalStateException.class, () -> mAnnouncementAggregator.watchModule(mRadioModuleMocks[0], TEST_ENABLED_TYPES)); assertWithMessage("Exception for watching module after aggregator has been closed") .that(thrown).hasMessageThat() .contains("announcement aggregator has already been closed"); } @Test public void close_withOneModuleWatcher_invokesCloseHandle() throws Exception { watchModules(/* moduleNumber= */ 1); Loading core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/hal2/AnnouncementAggregatorHidlTest.java +29 −0 Original line number Diff line number Diff line Loading @@ -18,9 +18,11 @@ package com.android.server.broadcastradio.hal2; 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.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; Loading Loading @@ -108,6 +110,33 @@ public final class AnnouncementAggregatorHidlTest { } } @Test public void onListUpdated_afterClosed_notUpdated() throws Exception { ArgumentCaptor<IAnnouncementListener> moduleWatcherCaptor = ArgumentCaptor.forClass(IAnnouncementListener.class); watchModules(/* moduleNumber= */ 1); verify(mRadioModuleMocks[0]).addAnnouncementListener(any(), moduleWatcherCaptor.capture()); mAnnouncementAggregator.close(); moduleWatcherCaptor.getValue().onListUpdated(Arrays.asList(mAnnouncementMocks[0])); verify(mListenerMock, never()).onListUpdated(any()); } @Test public void watchModule_afterClosed_throwsException() throws Exception { watchModules(/* moduleNumber= */ 1); mAnnouncementAggregator.close(); IllegalStateException thrown = assertThrows(IllegalStateException.class, () -> mAnnouncementAggregator.watchModule(mRadioModuleMocks[0], TEST_ENABLED_TYPES)); assertWithMessage("Exception for watching module after aggregator has been closed") .that(thrown).hasMessageThat() .contains("announcement aggregator has already been closed"); } @Test public void close_withOneModuleWatcher_invokesCloseHandle() throws Exception { watchModules(/* moduleNumber= */ 1); Loading Loading
core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/IRadioServiceAidlImplTest.java +11 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; 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; Loading Loading @@ -123,6 +124,16 @@ public final class IRadioServiceAidlImplTest extends ExtendedRadioMockitoTestCas .that(tuner).isEqualTo(mTunerMock); } @Test public void openTuner_withNullCallbackForAidlImpl_fails() throws Exception { IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> mAidlImpl.openTuner(/* moduleId= */ 0, mBandConfigMock, /* withAudio= */ true, /* callback= */ null, TARGET_SDK_VERSION)); assertWithMessage("Exception for opening tuner with null callback") .that(thrown).hasMessageThat().contains("Callback must not be null"); } @Test public void addAnnouncementListener_forAidlImpl() { ICloseHandle closeHandle = mAidlImpl.addAnnouncementListener(ENABLE_TYPES, mListenerMock); Loading
core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/IRadioServiceHidlImplTest.java +11 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.server.broadcastradio; 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; Loading Loading @@ -120,6 +121,16 @@ public final class IRadioServiceHidlImplTest { .that(tuner).isEqualTo(mHal2TunerMock); } @Test public void openTuner_withNullCallbackForHidlImpl_fails() throws Exception { NullPointerException thrown = assertThrows(NullPointerException.class, () -> mHidlImpl.openTuner(/* moduleId= */ 0, mBandConfigMock, /* withAudio= */ true, /* callback= */ null, TARGET_SDK_VERSION)); assertWithMessage("Exception for opening tuner with null callback") .that(thrown).hasMessageThat().contains("Callback must not be null"); } @Test public void addAnnouncementListener_forHidlImpl() { when(mHal2Mock.hasAnyModules()).thenReturn(true); Loading
core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/RadioServiceUserControllerTest.java +9 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.server.broadcastradio; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doThrow; import static com.google.common.truth.Truth.assertWithMessage; Loading Loading @@ -78,4 +79,12 @@ public final class RadioServiceUserControllerTest extends ExtendedRadioMockitoTe assertWithMessage("System user") .that(RadioServiceUserController.isCurrentOrSystemUser()).isTrue(); } @Test public void isCurrentUser_withActivityManagerFails_returnsFalse() { doThrow(new RuntimeException()).when(() -> ActivityManager.getCurrentUser()); assertWithMessage("User when activity manager fails") .that(RadioServiceUserController.isCurrentOrSystemUser()).isFalse(); } }
core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/AnnouncementAggregatorTest.java +29 −0 Original line number Diff line number Diff line Loading @@ -18,9 +18,11 @@ package com.android.server.broadcastradio.aidl; 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.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; Loading Loading @@ -107,6 +109,33 @@ public final class AnnouncementAggregatorTest { } } @Test public void onListUpdated_afterClosed_notUpdated() throws Exception { ArgumentCaptor<IAnnouncementListener> moduleWatcherCaptor = ArgumentCaptor.forClass(IAnnouncementListener.class); watchModules(/* moduleNumber= */ 1); verify(mRadioModuleMocks[0]).addAnnouncementListener(moduleWatcherCaptor.capture(), any()); mAnnouncementAggregator.close(); moduleWatcherCaptor.getValue().onListUpdated(Arrays.asList(mAnnouncementMocks[0])); verify(mListenerMock, never()).onListUpdated(any()); } @Test public void watchModule_afterClosed_throwsException() throws Exception { watchModules(/* moduleNumber= */ 1); mAnnouncementAggregator.close(); IllegalStateException thrown = assertThrows(IllegalStateException.class, () -> mAnnouncementAggregator.watchModule(mRadioModuleMocks[0], TEST_ENABLED_TYPES)); assertWithMessage("Exception for watching module after aggregator has been closed") .that(thrown).hasMessageThat() .contains("announcement aggregator has already been closed"); } @Test public void close_withOneModuleWatcher_invokesCloseHandle() throws Exception { watchModules(/* moduleNumber= */ 1); Loading
core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/hal2/AnnouncementAggregatorHidlTest.java +29 −0 Original line number Diff line number Diff line Loading @@ -18,9 +18,11 @@ package com.android.server.broadcastradio.hal2; 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.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; Loading Loading @@ -108,6 +110,33 @@ public final class AnnouncementAggregatorHidlTest { } } @Test public void onListUpdated_afterClosed_notUpdated() throws Exception { ArgumentCaptor<IAnnouncementListener> moduleWatcherCaptor = ArgumentCaptor.forClass(IAnnouncementListener.class); watchModules(/* moduleNumber= */ 1); verify(mRadioModuleMocks[0]).addAnnouncementListener(any(), moduleWatcherCaptor.capture()); mAnnouncementAggregator.close(); moduleWatcherCaptor.getValue().onListUpdated(Arrays.asList(mAnnouncementMocks[0])); verify(mListenerMock, never()).onListUpdated(any()); } @Test public void watchModule_afterClosed_throwsException() throws Exception { watchModules(/* moduleNumber= */ 1); mAnnouncementAggregator.close(); IllegalStateException thrown = assertThrows(IllegalStateException.class, () -> mAnnouncementAggregator.watchModule(mRadioModuleMocks[0], TEST_ENABLED_TYPES)); assertWithMessage("Exception for watching module after aggregator has been closed") .that(thrown).hasMessageThat() .contains("announcement aggregator has already been closed"); } @Test public void close_withOneModuleWatcher_invokesCloseHandle() throws Exception { watchModules(/* moduleNumber= */ 1); Loading