From 035a15ac374ae934c3697ea3c999108a4af08eb7 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 6 Feb 2025 17:30:18 +0000 Subject: [PATCH] Added unit test for MobileNetworkPhoneNumberPreferenceController visibility The new test checks whether the item is available when the SubscriptionUtil.isSimHardwareVisible() method returns true, i.e. if the config_show_sim_info boolean flag is true on non-test runtime. The default visibility status for all tests is defined in the test setup() method, as this will also simplify the addition of new checks later on. Bug: 392808943 Flag: EXEMPT test only Test: atest MobileNetworkPhoneNumberPreferenceControllerTest Change-Id: Icedef190a8140fd8164dd8035ae93735a666b9f0 --- ...eNetworkPhoneNumberPreferenceControllerTest.kt | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/spa_unit/src/com/android/settings/network/telephony/MobileNetworkPhoneNumberPreferenceControllerTest.kt b/tests/spa_unit/src/com/android/settings/network/telephony/MobileNetworkPhoneNumberPreferenceControllerTest.kt index f56c0c4b351..a7a87380c8d 100644 --- a/tests/spa_unit/src/com/android/settings/network/telephony/MobileNetworkPhoneNumberPreferenceControllerTest.kt +++ b/tests/spa_unit/src/com/android/settings/network/telephony/MobileNetworkPhoneNumberPreferenceControllerTest.kt @@ -61,6 +61,9 @@ class MobileNetworkPhoneNumberPreferenceControllerTest { .strictness(Strictness.LENIENT) .startMocking() + // By default, available + whenever(SubscriptionUtil.isSimHardwareVisible(context)).thenReturn(true) + preferenceScreen.addPreference(preference) controller.init(SUB_ID) controller.displayPreference(preferenceScreen) @@ -73,7 +76,6 @@ class MobileNetworkPhoneNumberPreferenceControllerTest { @Test fun onViewCreated_cannotGetPhoneNumber_displayUnknown() = runBlocking { - whenever(SubscriptionUtil.isSimHardwareVisible(context)).thenReturn(true) mockSubscriptionRepository.stub { on { phoneNumberFlow(SUB_ID) } doReturn flowOf(null) } @@ -86,7 +88,6 @@ class MobileNetworkPhoneNumberPreferenceControllerTest { @Test fun onViewCreated_canGetPhoneNumber_displayPhoneNumber() = runBlocking { - whenever(SubscriptionUtil.isSimHardwareVisible(context)).thenReturn(true) mockSubscriptionRepository.stub { on { phoneNumberFlow(SUB_ID) } doReturn flowOf(PHONE_NUMBER) } @@ -98,11 +99,17 @@ class MobileNetworkPhoneNumberPreferenceControllerTest { } @Test - fun getAvailabilityStatus_notSimHardwareVisible() { + fun getAvailabilityStatus_simHardwareVisible_displayed() { + // Use defaults from setup() + val availabilityStatus = controller.availabilityStatus + assertThat(availabilityStatus).isEqualTo(BasePreferenceController.AVAILABLE) + } + + @Test + fun getAvailabilityStatus_notSimHardwareVisible_notDisplayed() { whenever(SubscriptionUtil.isSimHardwareVisible(context)).thenReturn(false) val availabilityStatus = controller.availabilityStatus - assertThat(availabilityStatus).isEqualTo(BasePreferenceController.CONDITIONALLY_UNAVAILABLE) }