@@ -21,10 +21,8 @@ import io.mockk.every
2121import io.mockk.mockk
2222import io.mockk.verify
2323import kotlinx.coroutines.ExperimentalCoroutinesApi
24- import kotlinx.coroutines.async
2524import kotlinx.coroutines.channels.BufferOverflow
2625import kotlinx.coroutines.flow.MutableSharedFlow
27- import kotlinx.coroutines.flow.first
2826import kotlinx.coroutines.test.StandardTestDispatcher
2927import kotlinx.coroutines.test.TestScope
3028import kotlinx.coroutines.test.advanceUntilIdle
@@ -73,20 +71,6 @@ class PermissionWatchmenTest {
7371 assertEquals(1 , foregroundEvents.subscriptionCount.value)
7472 }
7573
76- @Test
77- fun shouldWakeUpAndReturnFlow_whenWatchPermissionEventForTheFirstTime () {
78- // Given: Permission
79- val permission = " permission"
80-
81- // When: Starts watching permission for the first time.
82- val flow = watchmen.watchStateEvents(permission)
83-
84- // Then: Should start watching activity foreground events.
85- dispatcher.scheduler.runCurrent()
86- verify(exactly = 1 ) { applicationStateMonitor.activityForegroundEvents }
87- assertEquals(1 , foregroundEvents.subscriptionCount.value)
88- }
89-
9074 @Test
9175 fun shouldWakeUpAndReturnFlow_whenWatchMultiplePermissionForTheFirstTime () {
9276 // Given: Multiple Permission
@@ -152,44 +136,6 @@ class PermissionWatchmenTest {
152136 assertFalse(state.value.isGranted)
153137 }
154138
155- @Test
156- fun shouldNotEmitCurrentState_whenEventIsWatched () = runTest {
157- // Given: Watching a permission flow as event and permission is not granted
158- val permission = " permission"
159- mockPermissions(permission to false )
160- watchmen.notifyPermissionsChanged(permissions = arrayOf(permission))
161-
162- // When: Watching state event
163- val state = async { watchmen.watchStateEvents(permission).first() }
164- advanceUntilIdle()
165-
166- // Then: Event should not be emitted with current value
167- assertTrue(state.isActive)
168-
169- // When: Change in state is notified for the same permission
170- watchmen.notifyPermissionsChanged(permissions = arrayOf(permission))
171-
172- // Then: Current value of flow should be false i.e. Not granted
173- assertEquals(permission, state.await().permission)
174- assertFalse(state.await().isGranted)
175- }
176-
177- @Test
178- fun shouldEmitStateEvent_whenPermissionChangesAreNotified () = runTest {
179- // Given: Watching a permission flow as event
180- val permission = " permission"
181- val event = watchmen.watchStateEvents(permission)
182-
183- // When: Change in state is notified for the same permission
184- mockPermissions(permission to false )
185- watchmen.notifyPermissionsChanged(permissions = arrayOf(permission))
186-
187- // Then: Current value of flow should be false i.e. Not granted
188- val state = event.first()
189- assertEquals(permission, state.permission)
190- assertFalse(state.isGranted)
191- }
192-
193139 @Test
194140 fun shouldUpdateMultiplePermissionFlowState_whenPermissionChangesAreNotified () {
195141 // Given: Watching multiple permission state
@@ -225,24 +171,6 @@ class PermissionWatchmenTest {
225171 assertFalse(flow.value.isGranted)
226172 }
227173
228- @Test
229- fun shouldEmitPermissionFlowStateEvent_whenWatchmenWakesAfterSleeping () = runTest {
230- // Given: Watching a permission
231- val permission = " permission"
232- mockPermissions(permission to true )
233- val state = async { watchmen.watchStateEvents(permission).first() }
234- advanceUntilIdle()
235-
236- // When: Watchmen sleeps, permission state changes and watchmen wakes after that
237- watchmen.sleep()
238- mockPermissions(permission to false )
239- watchmen.wakeUp()
240- advanceUntilIdle()
241-
242- // Then: Permission state should be get updated
243- assertFalse(state.await().isGranted)
244- }
245-
246174 @Test
247175 fun shouldUpdateMultiplePermissionFlowState_whenWatchmenWakesAfterSleeping () {
248176 // Given: Watching multiple permissions
@@ -278,23 +206,6 @@ class PermissionWatchmenTest {
278206 assertTrue(flow.value.isGranted)
279207 }
280208
281- @Test
282- fun shouldEmitStateEvent_whenPermissionChangesAreNotifiedEvenIfWatchmenIsSleeping () = runTest {
283- // Given: Watching a permission flow events and watchmen is sleeping
284- val permission = " permission"
285- mockPermissions(permission to true )
286- val state = async { watchmen.watchStateEvents(permission).first() }
287- watchmen.sleep()
288-
289- // When: Change in state is notified for the same permission
290- mockPermissions(permission to false )
291- watchmen.notifyPermissionsChanged(permissions = arrayOf(permission))
292- advanceUntilIdle()
293-
294- // Then: Current value of flow should be changed
295- assertFalse(state.await().isGranted)
296- }
297-
298209 @Test
299210 fun shouldNotUpdateMultipleFlowState_whenPermissionChangesAreNotifiedAndWatchmenIsSleeping () {
300211 // Given: Watching a permission flow and watchmen is sleeping
0 commit comments