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

Commit c9a2523b authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix ZenModeRepositoryTest failures" into main

parents 0f2458e7 5d1dac91
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ class ZenModeRepositoryImpl(
    val backgroundHandler: Handler?,
) : ZenModeRepository {

    private val notificationBroadcasts =
    private val notificationBroadcasts by lazy {
        callbackFlow {
                val receiver =
                    object : BroadcastReceiver() {
@@ -95,8 +95,9 @@ class ZenModeRepositoryImpl(
                    )
                }
            }
    }

    override val consolidatedNotificationPolicy: StateFlow<NotificationManager.Policy?> =
    override val consolidatedNotificationPolicy: StateFlow<NotificationManager.Policy?> by lazy {
        if (Flags.volumePanelBroadcastFix() && android.app.Flags.modesApi())
            flowFromBroadcast(NotificationManager.ACTION_CONSOLIDATED_NOTIFICATION_POLICY_CHANGED) {
                notificationManager.consolidatedNotificationPolicy
@@ -105,11 +106,13 @@ class ZenModeRepositoryImpl(
            flowFromBroadcast(NotificationManager.ACTION_NOTIFICATION_POLICY_CHANGED) {
                notificationManager.consolidatedNotificationPolicy
            }
    }

    override val globalZenMode: StateFlow<Int?> =
    override val globalZenMode: StateFlow<Int?> by lazy {
        flowFromBroadcast(NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED) {
            notificationManager.zenMode
        }
    }

    private fun <T> flowFromBroadcast(intentAction: String, mapper: () -> T) =
        notificationBroadcasts
+5 −11
Original line number Diff line number Diff line
@@ -48,7 +48,6 @@ import org.robolectric.RobolectricTestRunner
@RunWith(RobolectricTestRunner::class)
@SmallTest
class ZenModeRepositoryTest {

    @Mock private lateinit var context: Context

    @Mock private lateinit var notificationManager: NotificationManager
@@ -73,7 +72,7 @@ class ZenModeRepositoryTest {
            )
    }

    @DisableFlags(android.app.Flags.FLAG_MODES_API, Flags.FLAG_VOLUME_PANEL_BROADCAST_FIX)
    @DisableFlags(Flags.FLAG_VOLUME_PANEL_BROADCAST_FIX)
    @Test
    fun consolidatedPolicyChanges_repositoryEmits_flagsOff() {
        testScope.runTest {
@@ -88,9 +87,7 @@ class ZenModeRepositoryTest {
            triggerIntent(NotificationManager.ACTION_NOTIFICATION_POLICY_CHANGED)
            runCurrent()

            assertThat(values)
                .containsExactlyElementsIn(listOf(null, testPolicy1, testPolicy2))
                .inOrder()
            assertThat(values).containsExactly(null, testPolicy1, testPolicy2).inOrder()
        }
    }

@@ -109,9 +106,7 @@ class ZenModeRepositoryTest {
            triggerIntent(NotificationManager.ACTION_CONSOLIDATED_NOTIFICATION_POLICY_CHANGED)
            runCurrent()

            assertThat(values)
                .containsExactlyElementsIn(listOf(null, testPolicy1, testPolicy2))
                .inOrder()
            assertThat(values).containsExactly(null, testPolicy1, testPolicy2).inOrder()
        }
    }

@@ -128,14 +123,13 @@ class ZenModeRepositoryTest {
            runCurrent()

            assertThat(values)
                .containsExactlyElementsIn(
                    listOf(null, Global.ZEN_MODE_OFF, Global.ZEN_MODE_ALARMS))
                .containsExactly(null, Global.ZEN_MODE_OFF, Global.ZEN_MODE_ALARMS)
                .inOrder()
        }
    }

    private fun triggerIntent(action: String) {
        verify(context).registerReceiver(receiverCaptor.capture(), any())
        verify(context).registerReceiver(receiverCaptor.capture(), any(), any(), any())
        receiverCaptor.value.onReceive(context, Intent(action))
    }