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
This commit is contained in:
Aleksander Morgado
2025-02-06 17:30:18 +00:00
parent 616fbc4f93
commit 035a15ac37

View File

@@ -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)
}