@@ -24,7 +24,6 @@ import androidx.work.WorkManager
2424import com.duckduckgo.app.CoroutineTestRule
2525import com.duckduckgo.app.notification.NotificationScheduler.*
2626import com.duckduckgo.app.notification.model.SchedulableNotification
27- import com.duckduckgo.app.notification.model.SearchNotification
2827import com.duckduckgo.app.statistics.VariantManager
2928import com.duckduckgo.app.statistics.VariantManager.Companion.DEFAULT_VARIANT
3029import com.nhaarman.mockitokotlin2.any
@@ -48,7 +47,6 @@ class AndroidNotificationSchedulerTest {
4847 private val variantManager: VariantManager = mock()
4948 private val clearNotification: SchedulableNotification = mock()
5049 private val privacyNotification: SchedulableNotification = mock()
51- private val searchPromptNotification: SearchNotification = mock()
5250
5351 private val context = InstrumentationRegistry .getInstrumentation().targetContext
5452 private var workManager = WorkManager .getInstance(context)
@@ -60,136 +58,59 @@ class AndroidNotificationSchedulerTest {
6058 testee = NotificationScheduler (
6159 workManager,
6260 clearNotification,
63- privacyNotification,
64- searchPromptNotification
61+ privacyNotification
6562 )
6663 }
6764
68- @After
69- fun resetWorkers () {
70- workManager.cancelAllWorkByTag(NotificationScheduler .CONTINUOUS_APP_USE_REQUEST_TAG )
71- }
72-
73- @Test
74- fun whenPrivacyNotificationClearDataAndSearchPromptCanShowThenBothAreScheduled () = runBlocking<Unit > {
75- whenever(privacyNotification.canShow()).thenReturn(true )
76- whenever(clearNotification.canShow()).thenReturn(true )
77- whenever(searchPromptNotification.canShow()).thenReturn(true )
78- testee.scheduleNextNotification()
79-
80- assertUnusedAppNotificationScheduled(PrivacyNotificationWorker ::class .jvmName)
81- assertContinuousAppUseNotificationScheduled(SearchPromptNotificationWorker ::class .jvmName)
82- }
83-
8465 @Test
85- fun whenPrivacyNotificationClearDataAndSearchPromptCanShowThenPrivacyNotificationScheduled () = runBlocking<Unit > {
66+ fun whenPrivacyNotificationClearDataCanShowThenPrivacyNotificationIsScheduled () = runBlocking<Unit > {
8667 whenever(privacyNotification.canShow()).thenReturn(true )
8768 whenever(clearNotification.canShow()).thenReturn(true )
88- whenever(searchPromptNotification.canShow()).thenReturn(false )
8969 testee.scheduleNextNotification()
9070
9171 assertUnusedAppNotificationScheduled(PrivacyNotificationWorker ::class .jvmName)
92- assertNoContinuousAppNotificationScheduled()
9372 }
9473
9574 @Test
96- fun whenPrivacyNotificationAndSearchPromptCanShowButClearDataCannotThenThenBothAreScheduled () = runBlocking<Unit > {
75+ fun whenPrivacyNotificationCanShowButClearDataCannotThenPrivacyNotificationIsScheduled () = runBlocking<Unit > {
9776 whenever(privacyNotification.canShow()).thenReturn(true )
9877 whenever(clearNotification.canShow()).thenReturn(false )
99- whenever(searchPromptNotification.canShow()).thenReturn(true )
10078 testee.scheduleNextNotification()
10179
10280 assertUnusedAppNotificationScheduled(PrivacyNotificationWorker ::class .jvmName)
103- assertContinuousAppUseNotificationScheduled(SearchPromptNotificationWorker ::class .jvmName)
10481 }
10582
10683 @Test
107- fun whenPrivacyNotificationCanShowButClearDataAndSearchPromptCannotThenPrivacyNotificationScheduled () = runBlocking<Unit > {
108- whenever(privacyNotification.canShow()).thenReturn(true )
109- whenever(clearNotification.canShow()).thenReturn(false )
110- whenever(searchPromptNotification.canShow()).thenReturn(false )
111- testee.scheduleNextNotification()
112-
113- assertUnusedAppNotificationScheduled(PrivacyNotificationWorker ::class .jvmName)
114- assertNoContinuousAppNotificationScheduled()
115- }
116-
117- @Test
118- fun whenPrivacyNotificationAndSearchPromptCannotShowAndClearNotificationCanShowThenBothAreScheduled () = runBlocking<Unit > {
84+ fun whenPrivacyNotificationCannotShowAndClearNotificationCanShowThenClearNotificationIsScheduled () = runBlocking<Unit > {
11985 whenever(privacyNotification.canShow()).thenReturn(false )
12086 whenever(clearNotification.canShow()).thenReturn(true )
121- whenever(searchPromptNotification.canShow()).thenReturn(true )
12287 testee.scheduleNextNotification()
12388
12489 assertUnusedAppNotificationScheduled(ClearDataNotificationWorker ::class .jvmName)
125- assertContinuousAppUseNotificationScheduled(SearchPromptNotificationWorker ::class .jvmName)
12690 }
12791
12892 @Test
129- fun whenPrivacyNotificationAndClearNotificationCannotShowButSearchPromptCanShowThenNotificationScheduled () = runBlocking<Unit > {
93+ fun whenPrivacyNotificationAndClearNotificationCannotShowThenNoNotificationScheduled () = runBlocking<Unit > {
13094 whenever(privacyNotification.canShow()).thenReturn(false )
13195 whenever(clearNotification.canShow()).thenReturn(false )
132- whenever(searchPromptNotification.canShow()).thenReturn(true )
13396 testee.scheduleNextNotification()
13497
135- assertContinuousAppUseNotificationScheduled(SearchPromptNotificationWorker ::class .jvmName)
13698 assertNoUnusedAppNotificationScheduled()
13799 }
138100
139- @Test
140- fun whenPrivacyNotificationAndClearNotificationCannotShowButSearchPromptCanThenSearchPromptNotificationScheduled () = runBlocking<Unit > {
141- whenever(privacyNotification.canShow()).thenReturn(false )
142- whenever(clearNotification.canShow()).thenReturn(false )
143- whenever(searchPromptNotification.canShow()).thenReturn(true )
144-
145- testee.scheduleNextNotification()
146-
147- assertContinuousAppUseNotificationScheduled(SearchPromptNotificationWorker ::class .jvmName)
148- assertNoUnusedAppNotificationScheduled()
149- }
150-
151- @Test
152- fun whenNoNotificationCanShowThenNoNotificationScheduled () = runBlocking<Unit > {
153- whenever(privacyNotification.canShow()).thenReturn(false )
154- whenever(clearNotification.canShow()).thenReturn(false )
155- whenever(searchPromptNotification.canShow()).thenReturn(false )
156- testee.scheduleNextNotification()
157-
158- assertNoNotificationScheduled()
159- }
160-
161101 private fun assertUnusedAppNotificationScheduled (workerName : String ) {
162102 assertTrue(getUnusedAppScheduledWorkers().any { it.tags.contains(workerName) })
163103 }
164104
165- private fun assertContinuousAppUseNotificationScheduled (workerName : String ) {
166- assertTrue(getContinuousAppUseScheduledWorkers().any { it.tags.contains(workerName) })
167- }
168-
169105 private fun assertNoUnusedAppNotificationScheduled () {
170106 assertTrue(getUnusedAppScheduledWorkers().isEmpty())
171107 }
172108
173- private fun assertNoContinuousAppNotificationScheduled () {
174- assertTrue(getContinuousAppUseScheduledWorkers().isEmpty())
175- }
176-
177- private fun assertNoNotificationScheduled () {
178- assertTrue(getUnusedAppScheduledWorkers().isEmpty())
179- assertTrue(getContinuousAppUseScheduledWorkers().isEmpty())
180- }
181-
182109 private fun getUnusedAppScheduledWorkers (): List <WorkInfo > {
183110 return workManager
184111 .getWorkInfosByTag(NotificationScheduler .UNUSED_APP_WORK_REQUEST_TAG )
185112 .get()
186113 .filter { it.state == WorkInfo .State .ENQUEUED }
187114 }
188115
189- private fun getContinuousAppUseScheduledWorkers (): List <WorkInfo > {
190- return workManager
191- .getWorkInfosByTag(NotificationScheduler .CONTINUOUS_APP_USE_REQUEST_TAG )
192- .get()
193- .filter { it.state == WorkInfo .State .ENQUEUED }
194- }
195116}
0 commit comments