@@ -28,11 +28,7 @@ import androidx.work.testing.WorkManagerTestInitHelper
2828import com.duckduckgo.app.CoroutineTestRule
2929import com.duckduckgo.app.notification.NotificationScheduler.ClearDataNotificationWorker
3030import com.duckduckgo.app.notification.NotificationScheduler.PrivacyNotificationWorker
31- import com.duckduckgo.app.notification.NotificationScheduler.UseOurAppNotificationWorker
3231import com.duckduckgo.app.notification.model.SchedulableNotification
33- import com.duckduckgo.app.statistics.Variant
34- import com.duckduckgo.app.statistics.VariantManager
35- import com.duckduckgo.app.statistics.VariantManager.Companion.DEFAULT_VARIANT
3632import com.nhaarman.mockitokotlin2.mock
3733import com.nhaarman.mockitokotlin2.whenever
3834import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -49,10 +45,8 @@ class AndroidNotificationSchedulerTest {
4945 @get:Rule
5046 var coroutinesTestRule = CoroutineTestRule ()
5147
52- private val variantManager: VariantManager = mock()
5348 private val clearNotification: SchedulableNotification = mock()
5449 private val privacyNotification: SchedulableNotification = mock()
55- private val useOurAppNotification: SchedulableNotification = mock()
5650
5751 private val context = InstrumentationRegistry .getInstrumentation().targetContext
5852 private lateinit var workManager: WorkManager
@@ -65,9 +59,7 @@ class AndroidNotificationSchedulerTest {
6559 testee = NotificationScheduler (
6660 workManager,
6761 clearNotification,
68- privacyNotification,
69- useOurAppNotification,
70- variantManager
62+ privacyNotification
7163 )
7264 }
7365
@@ -84,7 +76,6 @@ class AndroidNotificationSchedulerTest {
8476
8577 @Test
8678 fun whenPrivacyNotificationClearDataCanShowThenPrivacyNotificationIsScheduled () = runBlocking<Unit > {
87- setDefaultVariant()
8879 whenever(privacyNotification.canShow()).thenReturn(true )
8980 whenever(clearNotification.canShow()).thenReturn(true )
9081 testee.scheduleNextNotification()
@@ -94,7 +85,6 @@ class AndroidNotificationSchedulerTest {
9485
9586 @Test
9687 fun whenPrivacyNotificationCanShowButClearDataCannotThenPrivacyNotificationIsScheduled () = runBlocking<Unit > {
97- setDefaultVariant()
9888 whenever(privacyNotification.canShow()).thenReturn(true )
9989 whenever(clearNotification.canShow()).thenReturn(false )
10090 testee.scheduleNextNotification()
@@ -104,7 +94,6 @@ class AndroidNotificationSchedulerTest {
10494
10595 @Test
10696 fun whenPrivacyNotificationCannotShowAndClearNotificationCanShowThenClearNotificationIsScheduled () = runBlocking<Unit > {
107- setDefaultVariant()
10897 whenever(privacyNotification.canShow()).thenReturn(false )
10998 whenever(clearNotification.canShow()).thenReturn(true )
11099 testee.scheduleNextNotification()
@@ -114,135 +103,13 @@ class AndroidNotificationSchedulerTest {
114103
115104 @Test
116105 fun whenPrivacyNotificationAndClearNotificationCannotShowThenNoNotificationScheduled () = runBlocking<Unit > {
117- setDefaultVariant()
118106 whenever(privacyNotification.canShow()).thenReturn(false )
119107 whenever(clearNotification.canShow()).thenReturn(false )
120108 testee.scheduleNextNotification()
121109
122110 assertNoNotificationScheduled()
123111 }
124112
125- @Test
126- fun whenInAppUsageVariantAndUseOurAppNotificationCanShowThenNotificationScheduled () = runBlocking {
127- givenNoInactiveUserNotifications()
128- setInAppUsageVariant()
129- whenever(useOurAppNotification.canShow()).thenReturn(true )
130-
131- testee.scheduleNextNotification()
132-
133- assertNotificationScheduled(UseOurAppNotificationWorker ::class .jvmName, NotificationScheduler .USE_OUR_APP_WORK_REQUEST_TAG )
134- }
135-
136- @Test
137- fun whenInAppUsageVariantUseOurAppNotificationCannotShowThenNoNotificationScheduled () = runBlocking {
138- givenNoInactiveUserNotifications()
139- setInAppUsageVariant()
140- whenever(useOurAppNotification.canShow()).thenReturn(false )
141-
142- testee.scheduleNextNotification()
143-
144- assertNoNotificationScheduled(NotificationScheduler .USE_OUR_APP_WORK_REQUEST_TAG )
145- }
146-
147- @Test
148- fun whenInAppUsageSecondControlVariantThenNoNotificationScheduled () = runBlocking<Unit > {
149- setInAppUsageSecondControlVariant()
150- whenever(useOurAppNotification.canShow()).thenReturn(true )
151-
152- testee.scheduleNextNotification()
153-
154- assertNoNotificationScheduled(NotificationScheduler .USE_OUR_APP_WORK_REQUEST_TAG )
155- }
156-
157- @Test
158- fun whenInAppUsageControlVariantThenNoNotificationScheduled () = runBlocking<Unit > {
159- givenNoInactiveUserNotifications()
160- setInAppUsageControlVariant()
161- whenever(useOurAppNotification.canShow()).thenReturn(true )
162-
163- testee.scheduleNextNotification()
164-
165- assertNoNotificationScheduled(NotificationScheduler .USE_OUR_APP_WORK_REQUEST_TAG )
166- }
167-
168- @Test
169- fun whenInAppUsageControlVariantAndPrivacyNotificationClearDataCanShowThenPrivacyNotificationIsScheduled () = runBlocking<Unit > {
170- setInAppUsageControlVariant()
171- whenever(privacyNotification.canShow()).thenReturn(true )
172- whenever(clearNotification.canShow()).thenReturn(true )
173- testee.scheduleNextNotification()
174-
175- assertNotificationScheduled(PrivacyNotificationWorker ::class .jvmName)
176- }
177-
178- @Test
179- fun whenInAppUsageControlVariantAndPrivacyNotificationCanShowButClearDataCannotThenPrivacyNotificationIsScheduled () = runBlocking<Unit > {
180- setInAppUsageControlVariant()
181- whenever(privacyNotification.canShow()).thenReturn(true )
182- whenever(clearNotification.canShow()).thenReturn(false )
183- testee.scheduleNextNotification()
184-
185- assertNotificationScheduled(PrivacyNotificationWorker ::class .jvmName)
186- }
187-
188- @Test
189- fun whenInAppUsageControlVariantAndPrivacyNotificationCannotShowAndClearNotificationCanShowThenClearNotificationScheduled () = runBlocking<Unit > {
190- setInAppUsageControlVariant()
191- whenever(privacyNotification.canShow()).thenReturn(false )
192- whenever(clearNotification.canShow()).thenReturn(true )
193- testee.scheduleNextNotification()
194-
195- assertNotificationScheduled(ClearDataNotificationWorker ::class .jvmName)
196- }
197-
198- @Test
199- fun whenInAppUsageControlVariantAndPrivacyNotificationAndClearNotificationCannotShowThenNoNotificationScheduled () = runBlocking<Unit > {
200- setDefaultVariant()
201- whenever(privacyNotification.canShow()).thenReturn(false )
202- whenever(clearNotification.canShow()).thenReturn(false )
203- testee.scheduleNextNotification()
204-
205- assertNoNotificationScheduled()
206- }
207-
208- private suspend fun givenNoInactiveUserNotifications () {
209- whenever(privacyNotification.canShow()).thenReturn(false )
210- whenever(clearNotification.canShow()).thenReturn(false )
211- }
212-
213- private fun setInAppUsageVariant () {
214- whenever(variantManager.getVariant()).thenReturn(
215- Variant (
216- " test" ,
217- features = listOf (
218- VariantManager .VariantFeature .InAppUsage ,
219- VariantManager .VariantFeature .RemoveDay1AndDay3Notifications ,
220- VariantManager .VariantFeature .KillOnboarding
221- ),
222- filterBy = { true })
223- )
224- }
225-
226- private fun setInAppUsageSecondControlVariant () {
227- whenever(variantManager.getVariant()).thenReturn(
228- Variant (
229- " test" ,
230- features = listOf (
231- VariantManager .VariantFeature .RemoveDay1AndDay3Notifications ,
232- VariantManager .VariantFeature .KillOnboarding
233- ),
234- filterBy = { true })
235- )
236- }
237-
238- private fun setInAppUsageControlVariant () {
239- whenever(variantManager.getVariant()).thenReturn(Variant (" test" , features = emptyList(), filterBy = { true }))
240- }
241-
242- private fun setDefaultVariant () {
243- whenever(variantManager.getVariant()).thenReturn(DEFAULT_VARIANT )
244- }
245-
246113 private fun assertNotificationScheduled (workerName : String , tag : String = NotificationScheduler .UNUSED_APP_WORK_REQUEST_TAG ) {
247114 assertTrue(getScheduledWorkers(tag).any { it.tags.contains(workerName) })
248115 }
0 commit comments