How to use result method of io.kotest.property.internal.Counter class

Best Kotest code snippet using io.kotest.property.internal.Counter.result

NotificationStoreTests.kt

Source:NotificationStoreTests.kt Github

copy

Full Screen

1package com.magicbell.sdk.feature.store2import com.magicbell.sdk.common.error.MagicBellError3import com.magicbell.sdk.common.network.AnyCursor4import com.magicbell.sdk.common.network.PageInfoMotherObject5import com.magicbell.sdk.common.network.anyNotificationEdgeArray6import com.magicbell.sdk.common.query.UserQuery7import com.magicbell.sdk.common.threading.MainThread8import com.magicbell.sdk.feature.notification.data.NotificationActionQuery.Action.ARCHIVE9import com.magicbell.sdk.feature.notification.data.NotificationActionQuery.Action.MARK_ALL_AS_READ10import com.magicbell.sdk.feature.notification.data.NotificationActionQuery.Action.MARK_ALL_AS_SEEN11import com.magicbell.sdk.feature.notification.data.NotificationActionQuery.Action.MARK_AS_READ12import com.magicbell.sdk.feature.notification.data.NotificationActionQuery.Action.MARK_AS_UNREAD13import com.magicbell.sdk.feature.notification.data.NotificationActionQuery.Action.UNARCHIVE14import com.magicbell.sdk.feature.notification.interactor.ActionNotificationInteractor15import com.magicbell.sdk.feature.notification.interactor.DeleteNotificationInteractor16import com.magicbell.sdk.feature.notification.motherobject.ForceProperty17import com.magicbell.sdk.feature.store.interactor.FetchStorePageInteractor18import com.magicbell.sdk.feature.store.motherobject.StoreMotherObject19import com.magicbell.sdk.feature.store.motherobject.givenPageStore20import com.magicbell.sdk.feature.store.utils.ContentObserverMock21import com.magicbell.sdk.feature.store.utils.InitialNotificationStoreCounts22import io.kotest.matchers.booleans.shouldBeFalse23import io.kotest.matchers.booleans.shouldBeTrue24import io.kotest.matchers.ints.shouldBeExactly25import io.kotest.matchers.nulls.shouldBeNull26import io.kotest.matchers.nulls.shouldNotBeNull27import io.kotest.matchers.shouldBe28import io.kotest.matchers.shouldNotBe29import io.mockk.coEvery30import io.mockk.coVerify31import io.mockk.confirmVerified32import io.mockk.mockk33import kotlinx.coroutines.CoroutineScope34import kotlinx.coroutines.Dispatchers35import kotlinx.coroutines.asCoroutineDispatcher36import kotlinx.coroutines.newSingleThreadContext37import kotlinx.coroutines.runBlocking38import kotlinx.coroutines.test.resetMain39import kotlinx.coroutines.test.setMain40import org.junit.jupiter.api.AfterEach41import org.junit.jupiter.api.BeforeEach42import org.junit.jupiter.api.Test43import java.util.concurrent.Executors44import kotlin.random.Random45internal class NotificationStoreTests {46 private val defaultEdgeArraySize = 2047 private val anyIndexForDefaultEdgeArraySize by lazy { Random.nextInt(0, defaultEdgeArraySize) }48 private val userQuery = UserQuery.createEmail("javier@mobilejazz.com")49 private val mainThread = object : MainThread {50 override fun post(run: () -> Unit) {51 run()52 }53 }54 private val coroutineContext = Executors.newFixedThreadPool(1).asCoroutineDispatcher()55 var fetchStorePageInteractor: FetchStorePageInteractor = mockk()56 var actionNotificationInteractor: ActionNotificationInteractor = mockk()57 var deleteNotificationInteractor: DeleteNotificationInteractor = mockk()58 lateinit var notificationStore: NotificationStore59 private val mainThreadSurrogate = newSingleThreadContext("UI thread")60 @BeforeEach61 fun setUp() {62 Dispatchers.setMain(mainThreadSurrogate)63 }64 @AfterEach65 fun tearDown() {66 Dispatchers.resetMain() // reset the main dispatcher to the original Main dispatcher67 mainThreadSurrogate.close()68 }69 private fun createNotificationStore(70 predicate: StorePredicate,71 fetchStoreExpectedResult: Result<StorePage>72 ): NotificationStore {73 fetchStoreExpectedResult.fold(onSuccess = {74 coEvery { fetchStorePageInteractor.invoke(any(), any(), any()) } returns fetchStoreExpectedResult.getOrThrow()75 }, onFailure = {76 coEvery { fetchStorePageInteractor.invoke(any(), any(), any()) } throws it77 })78 notificationStore = NotificationStore(79 predicate,80 coroutineContext,81 CoroutineScope(mainThreadSurrogate),82 mainThread,83 userQuery,84 fetchStorePageInteractor,85 actionNotificationInteractor,86 deleteNotificationInteractor87 )88 return notificationStore89 }90 @Test91 fun test_init_shouldReturnEmptyNotifications() = runBlocking {92 val predicate = StorePredicate()93 val store = createNotificationStore(94 StorePredicate(),95 Result.success(givenPageStore(predicate, defaultEdgeArraySize))96 )97 store.count.shouldBeExactly(0)98 Unit99 }100 @Test101 fun test_fetch_withDefaultStorePredicate_shouldReturnNotification() = runBlocking {102 // GIVEN103 val predicate = StorePredicate()104 val storePage = givenPageStore(predicate, defaultEdgeArraySize)105 val store = createNotificationStore(106 predicate,107 Result.success(storePage)108 )109 // WHEN110 val notifications = store.fetch().getOrThrow()111 // THEN112 coVerify(exactly = 1) { fetchStorePageInteractor.invoke(any(), any(), any()) }113 store.size.shouldBeExactly(defaultEdgeArraySize)114 notifications.size.shouldBeExactly(defaultEdgeArraySize)115 notifications.forEachIndexed { index, notification ->116 store[index].id.shouldBe(notification.id)117 }118 }119 @Test120 fun test_store_allNotifications_shouldReturnAllNotifications() = runBlocking {121 // GIVEN122 val predicate = StorePredicate()123 val storePage = givenPageStore(predicate, defaultEdgeArraySize)124 val store = createNotificationStore(125 predicate,126 Result.success(storePage)127 )128 // WHEN129 store.fetch()130 // THEN131 coVerify(exactly = 1) { fetchStorePageInteractor.invoke(any(), any(), any()) }132 store.size.shouldBeExactly(defaultEdgeArraySize)133 storePage.edges.map { it.node.id }.shouldBe(store.notifications.map { it.id })134 }135 @Test136 fun test_fetch_withDefaultStorePredicateAndError_shouldReturnError() = runBlocking {137 // GIVEN138 val predicate = StorePredicate()139 val store = createNotificationStore(140 predicate,141 Result.failure(MagicBellError("Error"))142 )143 // WHEN144 var errorExpected: Exception? = null145 try {146 store.fetch().getOrThrow()147 } catch (e: Exception) {148 errorExpected = e149 }150 // THEN151 coVerify(exactly = 1) { fetchStorePageInteractor.invoke(any(), any(), any()) }152 store.size.shouldBeExactly(0)153 errorExpected.shouldNotBeNull()154 Unit155 }156 @Test157 fun test_refresh_withDefaultStorePredicate_shouldRefreshContent() = runBlocking {158 // GIVEN159 val predicate = StorePredicate()160 val storePage = givenPageStore(predicate, defaultEdgeArraySize)161 val store = createNotificationStore(162 predicate,163 Result.success(storePage)164 )165 // WHEN166 val notifications = store.refresh().getOrThrow()167 // THEN168 coVerify(exactly = 1) { fetchStorePageInteractor.invoke(any(), any(), any()) }169 store.size.shouldBeExactly(defaultEdgeArraySize)170 notifications.size.shouldBeExactly(defaultEdgeArraySize)171 notifications.forEachIndexed { index, notification ->172 store[index].id.shouldBe(notification.id)173 }174 }175 @Test176 fun test_refresh_withDefaultStorePredicateAndError_shouldReturnError() = runBlocking {177 // GIVEN178 val predicate = StorePredicate()179 val store = createNotificationStore(180 predicate,181 Result.failure(MagicBellError("Error"))182 )183 // WHEN184 var errorExpected: Exception? = null185 try {186 store.refresh().getOrThrow()187 } catch (e: Exception) {188 errorExpected = e189 }190 // THEN191 coVerify(exactly = 1) { fetchStorePageInteractor.invoke(any(), any(), any()) }192 store.size.shouldBeExactly(0)193 errorExpected.shouldNotBeNull()194 Unit195 }196 @Test197 fun test_fetch_withPagination_shouldReturnTwoNotificationPages() = runBlocking {198 // GIVEN199 val predicate = StorePredicate()200 val storePage = StoreMotherObject.createStorePage(201 anyNotificationEdgeArray(predicate, defaultEdgeArraySize, ForceProperty.None),202 PageInfoMotherObject.createPageInfo(AnyCursor.ANY.value, hasNextPage = true)203 )204 val store = createNotificationStore(predicate, Result.success(storePage))205 // WHEN206 store.fetch().getOrThrow()207 // THEN208 coVerify(exactly = 1) { fetchStorePageInteractor.invoke(any(), any(), any()) }209 store.size.shouldBeExactly(defaultEdgeArraySize)210 // WHEN211 val notifications = store.fetch().getOrThrow()212 // THEN213 coVerify(exactly = 2) { fetchStorePageInteractor.invoke(any(), any(), any()) }214 store.size.shouldBeExactly(defaultEdgeArraySize * 2)215 notifications.size.shouldBeExactly(defaultEdgeArraySize)216 store.mapIndexed { index, notification ->217 notifications[index].id.shouldBe(notification.id)218 }219 }220 @Test221 fun test_fetch_withoutPagination_shouldReturnEmptyArray() = runBlocking {222 // GIVEN223 val predicate = StorePredicate()224 val storePage = StoreMotherObject.createStorePage(225 anyNotificationEdgeArray(predicate, defaultEdgeArraySize, ForceProperty.None),226 PageInfoMotherObject.createPageInfo(AnyCursor.ANY.value, hasNextPage = false)227 )228 val store = createNotificationStore(predicate, Result.success(storePage))229 // WHEN230 store.fetch().getOrThrow()231 // THEN232 coVerify(exactly = 1) { fetchStorePageInteractor.invoke(any(), any(), any()) }233 store.size.shouldBeExactly(defaultEdgeArraySize)234 // WHEN235 val notifications = store.fetch().getOrThrow()236 // THEN237 coVerify(exactly = 1) { fetchStorePageInteractor.invoke(any(), any(), any()) }238 store.size.shouldBeExactly(defaultEdgeArraySize)239 notifications.size.shouldBeExactly(0)240 Unit241 }242 @Test243 fun test_refresh_twoTimes_shouldReturnSamePage() = runBlocking {244 // GIVEN245 val predicate = StorePredicate()246 val storePage = StoreMotherObject.createStorePage(247 anyNotificationEdgeArray(predicate, defaultEdgeArraySize, ForceProperty.None),248 PageInfoMotherObject.createPageInfo(AnyCursor.ANY.value, hasNextPage = true)249 )250 val store = createNotificationStore(predicate, Result.success(storePage))251 // WHEN252 store.refresh().getOrThrow()253 // THEN254 coVerify(exactly = 1) { fetchStorePageInteractor.invoke(any(), any(), any()) }255 store.size.shouldBeExactly(defaultEdgeArraySize)256 storePage.edges.mapIndexed { index, edge ->257 store[index].id.shouldBe(edge.node.id)258 }259 // WHEN260 store.refresh().getOrThrow()261 // THEN262 coVerify(exactly = 2) { fetchStorePageInteractor.invoke(any(), any(), any()) }263 store.size.shouldBeExactly(defaultEdgeArraySize)264 storePage.edges.mapIndexed { index, edge ->265 store[index].id.shouldBe(edge.node.id)266 }267 Unit268 }269 @Test270 fun test_fetch_withPageInfoHasNextPageTrue_shouldConfigurePaginationTrue() = runBlocking {271 // GIVEN272 val predicate = StorePredicate()273 val storePage = StoreMotherObject.createStorePage(274 anyNotificationEdgeArray(predicate, defaultEdgeArraySize, ForceProperty.None),275 PageInfoMotherObject.createPageInfo(AnyCursor.ANY.value, hasNextPage = true)276 )277 val store = createNotificationStore(predicate, Result.success(storePage))278 store.hasNextPage.shouldBeTrue()279 // WHEN280 store.fetch().getOrThrow()281 // THEN282 store.hasNextPage.shouldBeTrue()283 }284 @Test285 fun test_fetch_withPageInfoHasNextPageFalse_shouldConfigurePaginationFalse() = runBlocking {286 // GIVEN287 val predicate = StorePredicate()288 val storePage = StoreMotherObject.createStorePage(289 anyNotificationEdgeArray(predicate, defaultEdgeArraySize, ForceProperty.None),290 PageInfoMotherObject.createPageInfo(AnyCursor.ANY.value, hasNextPage = false)291 )292 val store = createNotificationStore(predicate, Result.success(storePage))293 store.hasNextPage.shouldBeTrue()294 // WHEN295 store.fetch().getOrThrow()296 // THEN297 store.hasNextPage.shouldBeFalse()298 }299 @Test300 fun test_refresh_withPageInfoHasNextPageFalse_shouldConfigurePaginationFalse() = runBlocking {301 // GIVEN302 val predicate = StorePredicate()303 val storePage = StoreMotherObject.createStorePage(304 anyNotificationEdgeArray(predicate, defaultEdgeArraySize, ForceProperty.None),305 PageInfoMotherObject.createPageInfo(AnyCursor.ANY.value, hasNextPage = false)306 )307 val store = createNotificationStore(predicate, Result.success(storePage))308 store.hasNextPage.shouldBeTrue()309 // WHEN310 store.refresh().getOrThrow()311 // THEN312 store.hasNextPage.shouldBeFalse()313 }314 @Test315 fun test_deleteNotification_withDefaultStorePredicate_shouldCallActionNotificationInteractor() = runBlocking {316 // GIVEN317 val predicate = StorePredicate()318 val storePage = StoreMotherObject.createStorePage(319 anyNotificationEdgeArray(predicate, defaultEdgeArraySize, ForceProperty.Read),320 PageInfoMotherObject.createPageInfo(AnyCursor.ANY.value, hasNextPage = false)321 )322 val store = createNotificationStore(predicate, Result.success(storePage))323 // WHEN324 store.fetch().getOrThrow()325 val removeIndex = anyIndexForDefaultEdgeArraySize326 val removedNotification = store[removeIndex]327 store.delete(store[removeIndex])328 // THEN329 coVerify(exactly = 1) { fetchStorePageInteractor.invoke(any(), any(), any()) }330 coVerify(exactly = 1) { deleteNotificationInteractor.invoke(removedNotification.id, userQuery) }331 }332 @Test333 fun test_deleteNotification_withError_shouldReturnError() = runBlocking {334 // GIVEN335 val predicate = StorePredicate()336 val storePage = StoreMotherObject.createStorePage(337 anyNotificationEdgeArray(predicate, defaultEdgeArraySize, ForceProperty.Read),338 PageInfoMotherObject.createPageInfo(AnyCursor.ANY.value, hasNextPage = false)339 )340 val store = createNotificationStore(predicate, Result.success(storePage))341 // WHEN342 store.fetch().getOrThrow()343 val removeIndex = anyIndexForDefaultEdgeArraySize344 val removedNotification = store[removeIndex]345 coEvery { deleteNotificationInteractor.invoke(removedNotification.id, userQuery) } throws MagicBellError("Error")346 var errorExpected: Exception? = null347 try {348 store.delete(store[removeIndex]).getOrThrow()349 } catch (e: Exception) {350 errorExpected = e351 }352 // THEN353 coVerify(exactly = 1) { fetchStorePageInteractor.invoke(any(), any(), any()) }354 coVerify(exactly = 1) { deleteNotificationInteractor.invoke(removedNotification.id, userQuery) }355 errorExpected.shouldNotBeNull()356 Unit357 }358 @Test359 fun test_deleteNotification_withDefaultStorePredicateAndReadNotification_shouldRemoveNotificationAndSameUnreadCount() = runBlocking {360 // GIVEN361 val predicate = StorePredicate()362 val storePage = StoreMotherObject.createStorePage(363 anyNotificationEdgeArray(predicate, defaultEdgeArraySize, ForceProperty.Read),364 PageInfoMotherObject.createPageInfo(AnyCursor.ANY.value, hasNextPage = false)365 )366 val store = createNotificationStore(predicate, Result.success(storePage))367 // WHEN368 store.fetch().getOrThrow()369 val initialCounts = InitialNotificationStoreCounts(store)370 val removeIndex = anyIndexForDefaultEdgeArraySize371 val removedNotification = store[removeIndex]372 coEvery { deleteNotificationInteractor.invoke(removedNotification.id, userQuery) } returns Unit373 store.delete(store[removeIndex]).getOrThrow()374 // THEN375 store.totalCount.shouldBeExactly(initialCounts.totalCount - 1)376 store.unreadCount.shouldBeExactly(initialCounts.unreadCount - 1)377 if (store.size > removeIndex) {378 store[removeIndex].id.shouldNotBe(removedNotification.id)379 }380 }381 @Test382 fun test_deleteNotification_withDefaultStorePredicateAndUnreadNotification_shouldRemoveNotificationAndDifferentUnreadCount() = runBlocking {383 // GIVEN384 val predicate = StorePredicate()385 val storePage = StoreMotherObject.createStorePage(386 anyNotificationEdgeArray(predicate, defaultEdgeArraySize, ForceProperty.Unread),387 PageInfoMotherObject.createPageInfo(AnyCursor.ANY.value, hasNextPage = false)388 )389 val store = createNotificationStore(predicate, Result.success(storePage))390 // WHEN391 store.fetch().getOrThrow()392 val initialCounts = InitialNotificationStoreCounts(store)393 val removeIndex = anyIndexForDefaultEdgeArraySize394 val removedNotification = store[removeIndex]395 coEvery { deleteNotificationInteractor.invoke(removedNotification.id, userQuery) } returns Unit396 store.delete(store[removeIndex]).getOrThrow()397 // THEN398 store.totalCount.shouldBeExactly(initialCounts.totalCount - 1)399 store.unreadCount.shouldBeExactly(initialCounts.unreadCount - 1)400 if (store.size > removeIndex) {401 store[removeIndex].id.shouldNotBe(removedNotification.id)402 }403 }404 @Test405 fun test_deleteNotification_withDefaultStorePredicateAndSeenNotification_shouldRemoveNotificationAndSameUnseenCount() = runBlocking {406 // GIVEN407 val predicate = StorePredicate()408 val storePage = StoreMotherObject.createStorePage(409 anyNotificationEdgeArray(predicate, defaultEdgeArraySize, ForceProperty.Seen),410 PageInfoMotherObject.createPageInfo(AnyCursor.ANY.value, hasNextPage = false)411 )412 val store = createNotificationStore(predicate, Result.success(storePage))413 // WHEN414 store.fetch().getOrThrow()415 val initialCounts = InitialNotificationStoreCounts(store)416 val removeIndex = anyIndexForDefaultEdgeArraySize417 val removedNotification = store[removeIndex]418 coEvery { deleteNotificationInteractor.invoke(removedNotification.id, userQuery) } returns Unit419 store.delete(store[removeIndex]).getOrThrow()420 // THEN421 store.totalCount.shouldBeExactly(initialCounts.totalCount - 1)422 store.unseenCount.shouldBeExactly(initialCounts.unseenCount)423 if (store.size > removeIndex) {424 store[removeIndex].id.shouldNotBe(removedNotification.id)425 }426 }427 @Test428 fun test_deleteNotification_withDefaultStorePredicateAndUnseenNotification_shouldRemoveNotificationAndDifferentUnseenCount() = runBlocking {429 // GIVEN430 val predicate = StorePredicate()431 val storePage = StoreMotherObject.createStorePage(432 anyNotificationEdgeArray(predicate, defaultEdgeArraySize, ForceProperty.Unseen),433 PageInfoMotherObject.createPageInfo(AnyCursor.ANY.value, hasNextPage = false)434 )435 val store = createNotificationStore(predicate, Result.success(storePage))436 // WHEN437 store.fetch().getOrThrow()438 val initialCounts = InitialNotificationStoreCounts(store)439 val removeIndex = anyIndexForDefaultEdgeArraySize440 val removedNotification = store[removeIndex]441 coEvery { deleteNotificationInteractor.invoke(removedNotification.id, userQuery) } returns Unit442 store.delete(store[removeIndex]).getOrThrow()443 // THEN444 store.totalCount.shouldBeExactly(initialCounts.totalCount - 1)445 store.unseenCount.shouldBeExactly(initialCounts.unseenCount - 1)446 if (store.size > removeIndex) {447 store[removeIndex].id.shouldNotBe(removedNotification.id)448 }449 }450 @Test451 fun test_deleteNotification_withReadStorePredicate_shouldRemoveNotification() = runBlocking {452 // GIVEN453 val predicate = StorePredicate(read = true)454 val storePage = StoreMotherObject.createStorePage(455 anyNotificationEdgeArray(predicate, defaultEdgeArraySize, ForceProperty.None),456 PageInfoMotherObject.createPageInfo(AnyCursor.ANY.value, hasNextPage = false)457 )458 val store = createNotificationStore(predicate, Result.success(storePage))459 // WHEN460 store.fetch().getOrThrow()461 val initialCounts = InitialNotificationStoreCounts(store)462 val removeIndex = anyIndexForDefaultEdgeArraySize463 coEvery { deleteNotificationInteractor.invoke(any(), any()) } returns Unit464 store.delete(store[removeIndex]).getOrThrow()465 // THEN466 store.totalCount.shouldBeExactly(initialCounts.totalCount - 1)467 store.unreadCount.shouldBeExactly(0)468 Unit469 }470 @Test471 fun test_deleteNotification_withUnreadStorePredicate_shouldRemoveNotification() = runBlocking {472 // GIVEN473 val predicate = StorePredicate(read = false)474 val storePage = StoreMotherObject.createStorePage(475 anyNotificationEdgeArray(predicate, defaultEdgeArraySize, ForceProperty.None),476 PageInfoMotherObject.createPageInfo(AnyCursor.ANY.value, hasNextPage = false)477 )478 val store = createNotificationStore(predicate, Result.success(storePage))479 // WHEN480 store.fetch().getOrThrow()481 store.size.shouldBeExactly(defaultEdgeArraySize)482 val initialCounts = InitialNotificationStoreCounts(store)483 val removeIndex = anyIndexForDefaultEdgeArraySize484 coEvery { deleteNotificationInteractor.invoke(any(), any()) } returns Unit485 store.delete(store[removeIndex]).getOrThrow()486 // THEN487 store.totalCount.shouldBeExactly(initialCounts.totalCount - 1)488 store.unreadCount.shouldBeExactly(initialCounts.unreadCount - 1)489 Unit490 }491 @Test492 fun test_deleteNotification_withUnreadStorePredicateWithUnseenNotifications_shouldRemoveNotificationAndUpdateUnseeCount() = runBlocking {493 // GIVEN494 val predicate = StorePredicate(read = false)495 val storePage = StoreMotherObject.createStorePage(496 anyNotificationEdgeArray(predicate, defaultEdgeArraySize, ForceProperty.Unseen),497 PageInfoMotherObject.createPageInfo(AnyCursor.ANY.value, hasNextPage = false)498 )499 val store = createNotificationStore(predicate, Result.success(storePage))500 // WHEN501 store.fetch().getOrThrow()502 store.size.shouldBeExactly(defaultEdgeArraySize)503 val initialCounts = InitialNotificationStoreCounts(store)504 val removeIndex = anyIndexForDefaultEdgeArraySize505 coEvery { deleteNotificationInteractor.invoke(any(), any()) } returns Unit506 store.delete(store[removeIndex]).getOrThrow()507 // THEN508 store.totalCount.shouldBeExactly(initialCounts.totalCount - 1)509 store.unreadCount.shouldBeExactly(initialCounts.unreadCount - 1)510 store.unseenCount.shouldBeExactly(initialCounts.unseenCount - 1)511 Unit512 }513 @Test514 fun test_deleteNotification_withUnreadStorePredicateWithSeenNotifications_shouldRemoveNotificationAndSameUnseenCount() = runBlocking {515 // GIVEN516 val predicate = StorePredicate(read = false)517 val storePage = StoreMotherObject.createStorePage(518 anyNotificationEdgeArray(predicate, defaultEdgeArraySize, ForceProperty.Seen),519 PageInfoMotherObject.createPageInfo(AnyCursor.ANY.value, hasNextPage = false)520 )521 val store = createNotificationStore(predicate, Result.success(storePage))522 // WHEN523 store.fetch().getOrThrow()524 val initialCounts = InitialNotificationStoreCounts(store)525 val removeIndex = anyIndexForDefaultEdgeArraySize526 coEvery { deleteNotificationInteractor.invoke(any(), any()) } returns Unit527 store.delete(store[removeIndex]).getOrThrow()528 // THEN529 store.totalCount.shouldBeExactly(initialCounts.totalCount - 1)530 store.unreadCount.shouldBeExactly(initialCounts.unreadCount - 1)531 store.unseenCount.shouldBeExactly(initialCounts.unseenCount)532 Unit533 }534 @Test535 fun test_markNotificationAsRead_withDefaultStorePredicate_shouldCallActioNotificationInteractor() = runBlocking {536 // GIVEN537 val predicate = StorePredicate()538 val storePage = givenPageStore(predicate, defaultEdgeArraySize)539 val store = createNotificationStore(540 predicate, Result.success(storePage)541 )542 // WHEN543 store.fetch().getOrThrow()544 val chosenIndex = anyIndexForDefaultEdgeArraySize545 val markReadNotification = store[chosenIndex]546 coEvery { actionNotificationInteractor.invoke(MARK_AS_READ, markReadNotification.id, userQuery) } returns Unit547 store.markAsRead(store[chosenIndex]).getOrThrow()548 // THEN549 coVerify(exactly = 1) { fetchStorePageInteractor.invoke(any(), any(), any()) }550 coVerify(exactly = 1) { actionNotificationInteractor.invoke(MARK_AS_READ, markReadNotification.id, userQuery) }551 }552 @Test553 fun test_markNotificationAsRead_withError_shouldReturnError() = runBlocking {554 // GIVEN555 val predicate = StorePredicate()556 val storePage = givenPageStore(predicate, defaultEdgeArraySize)557 val store = createNotificationStore(558 predicate, Result.success(storePage)559 )560 // WHEN561 store.fetch().getOrThrow()562 val chosenIndex = anyIndexForDefaultEdgeArraySize563 val markReadNotification = store[chosenIndex]564 var errorExpected: Exception? = null565 try {566 store.markAsRead(store[chosenIndex]).getOrThrow()567 } catch (e: Exception) {568 errorExpected = e569 }570 // THEN571 coVerify(exactly = 1) { fetchStorePageInteractor.invoke(any(), any(), any()) }572 coVerify(exactly = 1) { actionNotificationInteractor.invoke(MARK_AS_READ, markReadNotification.id, userQuery) }573 errorExpected.shouldNotBeNull()574 Unit575 }576 @Test577 fun test_markNotificationAsRead_withDefaultStorePredicate_shouldMarkAsReadNotification() = runBlocking {578 // GIVEN579 val predicate = StorePredicate()580 val storePage = givenPageStore(predicate, defaultEdgeArraySize)581 val store = createNotificationStore(582 predicate, Result.success(storePage)583 )584 // WHEN585 store.fetch().getOrThrow()586 val initialCounts = InitialNotificationStoreCounts(store)587 val chosenIndex = anyIndexForDefaultEdgeArraySize588 val markReadNotification = store[chosenIndex]589 coEvery { actionNotificationInteractor.invoke(MARK_AS_READ, markReadNotification.id, userQuery) } returns Unit590 store.markAsRead(store[chosenIndex]).getOrThrow()591 // THEN592 store[chosenIndex].readAt.shouldNotBeNull()593 store.totalCount.shouldBeExactly(initialCounts.totalCount)594 }595 @Test596 fun test_markNotificationAsRead_withDefaultStorePredicateAndUnreadNotification_shouldMarkAsReadNotificationAndUpdateUnreadCounter() = runBlocking {597 // GIVEN598 val predicate = StorePredicate()599 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Unread)600 val store = createNotificationStore(601 predicate, Result.success(storePage)602 )603 // WHEN604 store.fetch().getOrThrow()605 val initialCounts = InitialNotificationStoreCounts(store)606 val chosenIndex = anyIndexForDefaultEdgeArraySize607 val markReadNotification = store[chosenIndex]608 coEvery { actionNotificationInteractor.invoke(MARK_AS_READ, markReadNotification.id, userQuery) } returns Unit609 store.markAsRead(store[chosenIndex]).getOrThrow()610 // THEN611 store[chosenIndex].readAt.shouldNotBeNull()612 store.totalCount.shouldBeExactly(initialCounts.totalCount)613 store.unreadCount.shouldBeExactly(initialCounts.unreadCount - 1)614 Unit615 }616 @Test617 fun test_markNotificationAsRead_withDefaultStorePredicateAndReadNotification_shouldMarkAsReadNotificationAndSameUnreadCounter() = runBlocking {618 // GIVEN619 val predicate = StorePredicate()620 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Read)621 val store = createNotificationStore(622 predicate, Result.success(storePage)623 )624 // WHEN625 store.fetch().getOrThrow()626 val initialCounts = InitialNotificationStoreCounts(store)627 val chosenIndex = anyIndexForDefaultEdgeArraySize628 val markReadNotification = store[chosenIndex]629 coEvery { actionNotificationInteractor.invoke(MARK_AS_READ, markReadNotification.id, userQuery) } returns Unit630 store.markAsRead(store[chosenIndex]).getOrThrow()631 // THEN632 store[chosenIndex].readAt.shouldNotBeNull()633 store.totalCount.shouldBeExactly(initialCounts.totalCount)634 store.unreadCount.shouldBeExactly(initialCounts.unreadCount)635 Unit636 }637 @Test638 fun test_markNotificationAsRead_withDefaultStorePredicateAndUnseenNotification_shouldMarkAsReadNotificationAndUpdateUnseenCounter() = runBlocking {639 // GIVEN640 val predicate = StorePredicate()641 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Unseen)642 val store = createNotificationStore(643 predicate, Result.success(storePage)644 )645 // WHEN646 store.fetch().getOrThrow()647 val initialCounts = InitialNotificationStoreCounts(store)648 val chosenIndex = anyIndexForDefaultEdgeArraySize649 val markReadNotification = store[chosenIndex]650 coEvery { actionNotificationInteractor.invoke(MARK_AS_READ, markReadNotification.id, userQuery) } returns Unit651 store.markAsRead(store[chosenIndex]).getOrThrow()652 // THEN653 store[chosenIndex].readAt.shouldNotBeNull()654 store.totalCount.shouldBeExactly(initialCounts.totalCount)655 store.unseenCount.shouldBeExactly(initialCounts.unseenCount - 1)656 Unit657 }658 @Test659 fun test_markNotificationAsRead_withDefaultStorePredicateAndSeenNotification_shouldMarkAsReadNotificationAndSameUnseenCounter() = runBlocking {660 // GIVEN661 val predicate = StorePredicate()662 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Seen)663 val store = createNotificationStore(664 predicate, Result.success(storePage)665 )666 // WHEN667 store.fetch().getOrThrow()668 val initialCounts = InitialNotificationStoreCounts(store)669 val chosenIndex = anyIndexForDefaultEdgeArraySize670 val markReadNotification = store[chosenIndex]671 coEvery { actionNotificationInteractor.invoke(MARK_AS_READ, markReadNotification.id, userQuery) } returns Unit672 store.markAsRead(store[chosenIndex]).getOrThrow()673 // THEN674 store[chosenIndex].readAt.shouldNotBeNull()675 store.totalCount.shouldBeExactly(initialCounts.totalCount)676 store.unseenCount.shouldBeExactly(initialCounts.unseenCount)677 Unit678 }679 @Test680 fun test_markNotificationAsRead_withUnreadStorePredicate_shouldMarkAsReadNotification() = runBlocking {681 // GIVEN682 val predicate = StorePredicate(read = false)683 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Unread)684 val store = createNotificationStore(685 predicate, Result.success(storePage)686 )687 // WHEN688 store.fetch().getOrThrow()689 val initialCounts = InitialNotificationStoreCounts(store)690 val chosenIndex = anyIndexForDefaultEdgeArraySize691 val markReadNotification = store[chosenIndex]692 coEvery { actionNotificationInteractor.invoke(MARK_AS_READ, markReadNotification.id, userQuery) } returns Unit693 store.markAsRead(store[chosenIndex]).getOrThrow()694 // THEN695 store[chosenIndex].readAt.shouldNotBeNull()696 store.totalCount.shouldBeExactly(initialCounts.totalCount - 1)697 store.unreadCount.shouldBeExactly(initialCounts.unreadCount - 1)698 Unit699 }700 @Test701 fun test_markNotificationAsRead_withUnreadStorePredicateAndUnseenNotification_shouldMarkAsReadNotificationAndUpdateUnseenCount() = runBlocking {702 // GIVEN703 val predicate = StorePredicate(read = false)704 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Unseen)705 val store = createNotificationStore(706 predicate, Result.success(storePage)707 )708 // WHEN709 store.fetch().getOrThrow()710 val initialCounts = InitialNotificationStoreCounts(store)711 val chosenIndex = anyIndexForDefaultEdgeArraySize712 val markReadNotification = store[chosenIndex]713 coEvery { actionNotificationInteractor.invoke(MARK_AS_READ, markReadNotification.id, userQuery) } returns Unit714 store.markAsRead(store[chosenIndex]).getOrThrow()715 // THEN716 store[chosenIndex].readAt.shouldNotBeNull()717 store.totalCount.shouldBeExactly(initialCounts.totalCount - 1)718 store.unseenCount.shouldBeExactly(initialCounts.unseenCount - 1)719 Unit720 }721 @Test722 fun test_markNotificationAsRead_withUnreadStorePredicateAndSeenNotification_shouldMarkAsReadNotificationAndSameUnseenCount() = runBlocking {723 // GIVEN724 val predicate = StorePredicate(read = false)725 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Seen)726 val store = createNotificationStore(727 predicate, Result.success(storePage)728 )729 // WHEN730 store.fetch().getOrThrow()731 val initialCounts = InitialNotificationStoreCounts(store)732 val chosenIndex = anyIndexForDefaultEdgeArraySize733 val markReadNotification = store[chosenIndex]734 coEvery { actionNotificationInteractor.invoke(MARK_AS_READ, markReadNotification.id, userQuery) } returns Unit735 store.markAsRead(store[chosenIndex]).getOrThrow()736 // THEN737 store[chosenIndex].readAt.shouldNotBeNull()738 store.totalCount.shouldBeExactly(initialCounts.totalCount - 1)739 store.unseenCount.shouldBeExactly(initialCounts.unseenCount)740 Unit741 }742 @Test743 fun test_markNotificationAsUnread_withDefaultStorePredicate_shouldCallActioNotificationInteractor() = runBlocking {744 // GIVEN745 val predicate = StorePredicate()746 val storePage = givenPageStore(predicate, defaultEdgeArraySize)747 val store = createNotificationStore(748 predicate, Result.success(storePage)749 )750 // WHEN751 store.fetch().getOrThrow()752 val initialCounts = InitialNotificationStoreCounts(store)753 val chosenIndex = anyIndexForDefaultEdgeArraySize754 val markReadNotification = store[chosenIndex]755 coEvery { actionNotificationInteractor.invoke(MARK_AS_UNREAD, markReadNotification.id, userQuery) } returns Unit756 store.markAsUnread(store[chosenIndex]).getOrThrow()757 // THEN758 coVerify(exactly = 1) { fetchStorePageInteractor.invoke(any(), any(), any()) }759 coVerify { actionNotificationInteractor.invoke(MARK_AS_UNREAD, markReadNotification.id, userQuery) }760 }761 @Test762 fun test_markNotificationAsUnread_withDefaultStorePredicate_shouldMarkAsUnreadNotification() = runBlocking {763 // GIVEN764 val predicate = StorePredicate()765 val storePage = givenPageStore(predicate, defaultEdgeArraySize)766 val store = createNotificationStore(767 predicate, Result.success(storePage)768 )769 // WHEN770 store.fetch().getOrThrow()771 val initialCounts = InitialNotificationStoreCounts(store)772 val chosenIndex = anyIndexForDefaultEdgeArraySize773 val markReadNotification = store[chosenIndex]774 coEvery { actionNotificationInteractor.invoke(MARK_AS_UNREAD, markReadNotification.id, userQuery) } returns Unit775 store.markAsUnread(store[chosenIndex]).getOrThrow()776 // THEN777 store[chosenIndex].readAt.shouldBeNull()778 store.totalCount.shouldBeExactly(initialCounts.totalCount)779 store.unseenCount.shouldBeExactly(initialCounts.unseenCount)780 Unit781 }782 @Test783 fun test_markNotificationAsUnread_withDefaultStorePredicateAndReadNotification_shouldMarkAsUnreadNotificationAndUpdateUnreadCount() = runBlocking {784 // GIVEN785 val predicate = StorePredicate()786 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Read)787 val store = createNotificationStore(788 predicate, Result.success(storePage)789 )790 // WHEN791 store.fetch().getOrThrow()792 val initialCounts = InitialNotificationStoreCounts(store)793 val chosenIndex = anyIndexForDefaultEdgeArraySize794 val markReadNotification = store[chosenIndex]795 coEvery { actionNotificationInteractor.invoke(MARK_AS_UNREAD, markReadNotification.id, userQuery) } returns Unit796 store.markAsUnread(store[chosenIndex]).getOrThrow()797 // THEN798 store[chosenIndex].readAt.shouldBeNull()799 store.totalCount.shouldBeExactly(initialCounts.totalCount)800 store.unreadCount.shouldBeExactly(initialCounts.unreadCount + 1)801 Unit802 }803 @Test804 fun test_markNotificationAsUnread_withReadStorePredicate_shouldRemoveNotification() = runBlocking {805 // GIVEN806 val predicate = StorePredicate(read = true)807 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Read)808 val store = createNotificationStore(809 predicate, Result.success(storePage)810 )811 // WHEN812 store.fetch().getOrThrow()813 val initialCounts = InitialNotificationStoreCounts(store)814 val chosenIndex = anyIndexForDefaultEdgeArraySize815 val markReadNotification = store[chosenIndex]816 coEvery { actionNotificationInteractor.invoke(MARK_AS_UNREAD, markReadNotification.id, userQuery) } returns Unit817 store.markAsUnread(store[chosenIndex]).getOrThrow()818 // THEN819 store[chosenIndex].readAt.shouldBeNull()820 store.totalCount.shouldBeExactly(initialCounts.totalCount - 1)821 store.unreadCount.shouldBeExactly(0)822 store.unseenCount.shouldBeExactly(initialCounts.unseenCount)823 Unit824 }825 @Test826 fun test_markNotificationAsUnread_withUnreadStorePredicate_shouldDoNothing() = runBlocking {827 // GIVEN828 val predicate = StorePredicate(read = true)829 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Unread)830 val store = createNotificationStore(831 predicate, Result.success(storePage)832 )833 // WHEN834 store.fetch().getOrThrow()835 val initialCounts = InitialNotificationStoreCounts(store)836 val chosenIndex = anyIndexForDefaultEdgeArraySize837 val markReadNotification = store[chosenIndex]838 coEvery { actionNotificationInteractor.invoke(MARK_AS_UNREAD, markReadNotification.id, userQuery) } returns Unit839 store.markAsUnread(store[chosenIndex]).getOrThrow()840 // THEN841 store[chosenIndex].readAt.shouldBeNull()842 store.totalCount.shouldBeExactly(initialCounts.totalCount)843 store.unreadCount.shouldBeExactly(initialCounts.unreadCount)844 store.unseenCount.shouldBeExactly(initialCounts.unseenCount)845 Unit846 }847 @Test848 fun test_markNotificationAsArchive_withDefaultStorePredicate_shouldCallActioNotificationInteractor() = runBlocking {849 // GIVEN850 val predicate = StorePredicate()851 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Read)852 val store = createNotificationStore(853 predicate, Result.success(storePage)854 )855 // WHEN856 store.fetch().getOrThrow()857 val initialCounts = InitialNotificationStoreCounts(store)858 val chosenIndex = anyIndexForDefaultEdgeArraySize859 val markReadNotification = store[chosenIndex]860 coEvery { actionNotificationInteractor.invoke(ARCHIVE, markReadNotification.id, userQuery) } returns Unit861 store.archive(store[chosenIndex]).getOrThrow()862 // THEN863 coVerify(exactly = 1) { fetchStorePageInteractor.invoke(any(), any(), any()) }864 coVerify { actionNotificationInteractor.invoke(ARCHIVE, markReadNotification.id, userQuery) }865 confirmVerified(actionNotificationInteractor)866 }867 @Test868 fun test_markNotificationAsArchive_withDefaultStorePredicate_shouldHaveArchiveDate() = runBlocking {869 // GIVEN870 val predicate = StorePredicate()871 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Read)872 val store = createNotificationStore(873 predicate, Result.success(storePage)874 )875 // WHEN876 store.fetch().getOrThrow()877 val initialCounts = InitialNotificationStoreCounts(store)878 val chosenIndex = anyIndexForDefaultEdgeArraySize879 val markReadNotification = store[chosenIndex]880 coEvery { actionNotificationInteractor.invoke(ARCHIVE, markReadNotification.id, userQuery) } returns Unit881 store.archive(store[chosenIndex]).getOrThrow()882 //THEN883 store[chosenIndex].archivedAt.shouldNotBeNull()884 Unit885 }886 @Test887 fun test_markNotificationAsUnarchive_withDefaultStorePredicate_shouldCallActioNotificationInteractor() = runBlocking {888 // GIVEN889 val predicate = StorePredicate()890 val storePage = givenPageStore(predicate, defaultEdgeArraySize)891 val store = createNotificationStore(892 predicate, Result.success(storePage)893 )894 // WHEN895 store.fetch().getOrThrow()896 val initialCounts = InitialNotificationStoreCounts(store)897 val chosenIndex = anyIndexForDefaultEdgeArraySize898 val markReadNotification = store[chosenIndex]899 coEvery { actionNotificationInteractor.invoke(UNARCHIVE, markReadNotification.id, userQuery) } returns Unit900 store.unarchive(store[chosenIndex]).getOrThrow()901 // THEN902 coVerify(exactly = 1) { fetchStorePageInteractor.invoke(any(), any(), any()) }903 coVerify { actionNotificationInteractor.invoke(UNARCHIVE, markReadNotification.id, userQuery) }904 confirmVerified(actionNotificationInteractor)905 }906 @Test907 fun test_markNotificationUnarchive_withDefaultStorePredicate_shouldHaveNilArchiveDate() = runBlocking {908 // GIVEN909 val predicate = StorePredicate()910 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Read)911 val store = createNotificationStore(912 predicate, Result.success(storePage)913 )914 // WHEN915 store.fetch().getOrThrow()916 val initialCounts = InitialNotificationStoreCounts(store)917 val chosenIndex = anyIndexForDefaultEdgeArraySize918 val markReadNotification = store[chosenIndex]919 coEvery { actionNotificationInteractor.invoke(UNARCHIVE, markReadNotification.id, userQuery) } returns Unit920 store.unarchive(store[chosenIndex]).getOrThrow()921 //THEN922 store[chosenIndex].archivedAt.shouldBeNull()923 }924 @Test925 fun test_markNotificationAllRead_withDefaultStorePredicate_shouldCallActioNotificationInteractor() = runBlocking {926 // GIVEN927 val predicate = StorePredicate()928 val storePage = givenPageStore(predicate, defaultEdgeArraySize)929 val store = createNotificationStore(930 predicate, Result.success(storePage)931 )932 // WHEN933 store.fetch().getOrThrow()934 anyIndexForDefaultEdgeArraySize935 coEvery { actionNotificationInteractor.invoke(MARK_ALL_AS_READ, null, userQuery) } returns Unit936 store.markAllNotificationAsRead().getOrThrow()937 // THEN938 coVerify(exactly = 1) { fetchStorePageInteractor.invoke(any(), any(), any()) }939 coVerify { actionNotificationInteractor.invoke(MARK_ALL_AS_READ, null, userQuery) }940 confirmVerified(actionNotificationInteractor)941 }942 @Test943 fun test_markNotificationAllRead_withError_shouldReturnError() = runBlocking {944 // GIVEN945 val predicate = StorePredicate()946 val storePage = givenPageStore(predicate, defaultEdgeArraySize)947 val store = createNotificationStore(948 predicate, Result.success(storePage)949 )950 // WHEN951 store.fetch().getOrThrow()952 anyIndexForDefaultEdgeArraySize953 coEvery { actionNotificationInteractor.invoke(MARK_ALL_AS_READ, null, userQuery) } throws MagicBellError("Error")954 var errorExpected: Exception? = null955 try {956 store.markAllNotificationAsRead().getOrThrow()957 } catch (e: Exception) {958 errorExpected = e959 }960 // THEN961 coVerify(exactly = 1) { fetchStorePageInteractor.invoke(any(), any(), any()) }962 coVerify { actionNotificationInteractor.invoke(MARK_ALL_AS_READ, null, userQuery) }963 confirmVerified(actionNotificationInteractor)964 errorExpected.shouldNotBeNull()965 Unit966 }967 @Test968 fun test_markAllNotificationAsRead_withDefaultStorePredicate_shouldMarkAllNotificationWithReadDate() = runBlocking {969 // GIVEN970 val predicate = StorePredicate()971 val storePage = givenPageStore(predicate, defaultEdgeArraySize)972 val store = createNotificationStore(973 predicate, Result.success(storePage)974 )975 // WHEN976 store.fetch().getOrThrow()977 val initialCounts = InitialNotificationStoreCounts(store)978 anyIndexForDefaultEdgeArraySize979 coEvery { actionNotificationInteractor.invoke(MARK_ALL_AS_READ, null, userQuery) } returns Unit980 store.markAllNotificationAsRead().getOrThrow()981 // THEN982 store.forEach {983 it.readAt.shouldNotBeNull()984 it.seenAt.shouldNotBeNull()985 }986 store.totalCount.shouldBeExactly(initialCounts.totalCount)987 store.unreadCount.shouldBeExactly(0)988 store.unseenCount.shouldBeExactly(0)989 Unit990 }991 @Test992 fun test_markAllNotificationAsRead_withUnreadStorePredicate_shouldClearNotifications() = runBlocking {993 // GIVEN994 val predicate = StorePredicate(read = false)995 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Unread)996 val store = createNotificationStore(997 predicate, Result.success(storePage)998 )999 // WHEN1000 store.fetch().getOrThrow()1001 val initialCounts = InitialNotificationStoreCounts(store)1002 anyIndexForDefaultEdgeArraySize1003 coEvery { actionNotificationInteractor.invoke(MARK_ALL_AS_READ, null, userQuery) } returns Unit1004 store.markAllNotificationAsRead().getOrThrow()1005 // THEN1006 store.forEach {1007 it.readAt.shouldNotBeNull()1008 it.seenAt.shouldNotBeNull()1009 }1010 store.totalCount.shouldNotBe(initialCounts.totalCount)1011 store.unreadCount.shouldNotBe(initialCounts.unreadCount)1012 store.unseenCount.shouldNotBe(initialCounts.unseenCount)1013 Unit1014 }1015 @Test1016 fun test_markAllNotificationAsRead_withReadStorePredicate_shouldBeAllTheSame() = runBlocking {1017 // GIVEN1018 val predicate = StorePredicate(read = true)1019 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Read)1020 val store = createNotificationStore(1021 predicate, Result.success(storePage)1022 )1023 // WHEN1024 store.fetch().getOrThrow()1025 val initialCounts = InitialNotificationStoreCounts(store)1026 anyIndexForDefaultEdgeArraySize1027 coEvery { actionNotificationInteractor.invoke(MARK_ALL_AS_READ, null, userQuery) } returns Unit1028 store.markAllNotificationAsRead().getOrThrow()1029 // THEN1030 store.forEach {1031 it.readAt.shouldNotBeNull()1032 it.seenAt.shouldNotBeNull()1033 }1034 store.totalCount.shouldBeExactly(initialCounts.totalCount)1035 store.unreadCount.shouldBeExactly(initialCounts.unreadCount)1036 store.unseenCount.shouldBeExactly(initialCounts.unseenCount)1037 Unit1038 }1039 @Test1040 fun test_markAllNotificationSeen_withDefaultStorePredicate_shouldCallActioNotificationInteractor() = runBlocking {1041 // GIVEN1042 val predicate = StorePredicate()1043 val storePage = givenPageStore(predicate, defaultEdgeArraySize)1044 val store = createNotificationStore(1045 predicate, Result.success(storePage)1046 )1047 // WHEN1048 store.fetch().getOrThrow()1049 val initialCounts = InitialNotificationStoreCounts(store)1050 anyIndexForDefaultEdgeArraySize1051 coEvery { actionNotificationInteractor.invoke(MARK_ALL_AS_SEEN, null, userQuery) } returns Unit1052 store.markAllNotificationAsSeen().getOrThrow()1053 // THEN1054 coVerify(exactly = 1) { fetchStorePageInteractor.invoke(any(), any(), any()) }1055 coVerify { actionNotificationInteractor.invoke(MARK_ALL_AS_SEEN, null, userQuery) }1056 confirmVerified(actionNotificationInteractor)1057 }1058 @Test1059 fun test_markAllNotificationAsSeen_withDefaultStorePredicate_shouldMarkAllNotificationWithSeenDate() = runBlocking {1060 // GIVEN1061 val predicate = StorePredicate()1062 val storePage = givenPageStore(predicate, defaultEdgeArraySize)1063 val store = createNotificationStore(1064 predicate, Result.success(storePage)1065 )1066 // WHEN1067 store.fetch().getOrThrow()1068 val initialCounts = InitialNotificationStoreCounts(store)1069 anyIndexForDefaultEdgeArraySize1070 coEvery { actionNotificationInteractor.invoke(MARK_ALL_AS_SEEN, null, userQuery) } returns Unit1071 store.markAllNotificationAsSeen().getOrThrow()1072 // THEN1073 store.forEach {1074 it.seenAt.shouldNotBeNull()1075 }1076 store.totalCount.shouldBeExactly(initialCounts.totalCount)1077 store.unreadCount.shouldBeExactly(initialCounts.unreadCount)1078 store.unseenCount.shouldBeExactly(0)1079 Unit1080 }1081 @Test1082 fun test_markAllNotificationAsSeen_withUnreadStorePredicate_shouldMarkAllNotificationWithSeenDate() = runBlocking {1083 // GIVEN1084 val predicate = StorePredicate(read = false)1085 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Unread)1086 val store = createNotificationStore(1087 predicate, Result.success(storePage)1088 )1089 // WHEN1090 store.fetch().getOrThrow()1091 val initialCounts = InitialNotificationStoreCounts(store)1092 anyIndexForDefaultEdgeArraySize1093 coEvery { actionNotificationInteractor.invoke(MARK_ALL_AS_SEEN, null, userQuery) } returns Unit1094 store.markAllNotificationAsSeen().getOrThrow()1095 // THEN1096 store.totalCount.shouldBeExactly(initialCounts.totalCount)1097 store.unreadCount.shouldBeExactly(initialCounts.unreadCount)1098 store.unseenCount.shouldNotBe(initialCounts.unseenCount)1099 Unit1100 }1101 @Test1102 fun test_markAllNotificationAsSeen_withReadStorePredicate_shouldMarkAllNotificationWithSeenDate() = runBlocking {1103 // GIVEN1104 val predicate = StorePredicate(read = true)1105 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Read)1106 val store = createNotificationStore(1107 predicate, Result.success(storePage)1108 )1109 // WHEN1110 store.fetch().getOrThrow()1111 val initialCounts = InitialNotificationStoreCounts(store)1112 anyIndexForDefaultEdgeArraySize1113 coEvery { actionNotificationInteractor.invoke(MARK_ALL_AS_SEEN, null, userQuery) } returns Unit1114 store.markAllNotificationAsSeen().getOrThrow()1115 store.totalCount.shouldBeExactly(initialCounts.totalCount)1116 store.unreadCount.shouldBeExactly(initialCounts.unreadCount)1117 store.unseenCount.shouldBeExactly(initialCounts.unseenCount)1118 Unit1119 }1120 @Test1121 fun test_notifyInsertNotifications_withDefaultStorePredicate_ShouldNotifyInsertIndexesArray() = runBlocking {1122 // GIVEN1123 val contentObserver = ContentObserverMock()1124 val predicate = StorePredicate()1125 val storePage = StoreMotherObject.createStorePage(1126 anyNotificationEdgeArray(predicate, defaultEdgeArraySize, ForceProperty.None),1127 PageInfoMotherObject.createPageInfo(AnyCursor.ANY.value, true)1128 )1129 val store = createNotificationStore(predicate, Result.success(storePage))1130 store.addContentObserver(contentObserver)1131 // WHEN1132 store.fetch().getOrThrow()1133 // THEN1134 var indexes = 0.until(store.size).toList()1135 val sizeIndexes = indexes.size1136 contentObserver.didInsertCounter.shouldBeExactly(1)1137 contentObserver.didInsertSpy[0].indexes.shouldBe(indexes)1138 coVerify(exactly = 1) { fetchStorePageInteractor.invoke(any(), any(), any()) }1139 store.size.shouldBeExactly(defaultEdgeArraySize)1140 store.fetch().getOrThrow()1141 coVerify(exactly = 2) { fetchStorePageInteractor.invoke(any(), any(), any()) }1142 store.size.shouldBeExactly(defaultEdgeArraySize * 2)1143 indexes = sizeIndexes.until(store.size).toList()1144 contentObserver.didInsertCounter.shouldBeExactly(2)1145 contentObserver.didInsertSpy[1].indexes.shouldBe(indexes)1146 }1147 @Test1148 fun test_notifyDeleteNotification_WithDefaultStorePredicate_ShouldNotifyCounters() = runBlocking {1149 // GIVEN1150 val contentObserver = ContentObserverMock()1151 val predicate = StorePredicate()1152 val storePage = StoreMotherObject.createStorePage(1153 anyNotificationEdgeArray(predicate, defaultEdgeArraySize, ForceProperty.None),1154 PageInfoMotherObject.createPageInfo(AnyCursor.ANY.value, true)1155 )1156 val store = createNotificationStore(predicate, Result.success(storePage))1157 store.addContentObserver(contentObserver)1158 // WHEN1159 store.fetch().getOrThrow()1160 val removeIndex = anyIndexForDefaultEdgeArraySize1161 coEvery { deleteNotificationInteractor.invoke(store[removeIndex].id, userQuery) } returns Unit1162 store.delete(store[removeIndex]).getOrThrow()1163 // THEN1164 contentObserver.didDeleteCounter.shouldBeExactly(1)1165 contentObserver.didDeleteSpy[0].indexes.shouldBe(listOf(removeIndex))1166 }1167}...

Full Screen

Full Screen

NotificationStoreRealTimeTests.kt

Source:NotificationStoreRealTimeTests.kt Github

copy

Full Screen

1package com.magicbell.sdk.feature.store2import com.magicbell.sdk.common.query.UserQuery3import com.magicbell.sdk.common.threading.MainThread4import com.magicbell.sdk.feature.config.Config5import com.magicbell.sdk.feature.config.Ws6import com.magicbell.sdk.feature.config.interactor.DeleteConfigInteractor7import com.magicbell.sdk.feature.config.interactor.GetConfigInteractor8import com.magicbell.sdk.feature.notification.interactor.ActionNotificationInteractor9import com.magicbell.sdk.feature.notification.interactor.DeleteNotificationInteractor10import com.magicbell.sdk.feature.notification.motherobject.ForceProperty11import com.magicbell.sdk.feature.store.interactor.FetchStorePageInteractor12import com.magicbell.sdk.feature.store.motherobject.givenPageStore13import com.magicbell.sdk.feature.store.utils.ContentObserverMock14import com.magicbell.sdk.feature.store.utils.CountObserverMock15import com.magicbell.sdk.feature.store.utils.InitialNotificationStoreCounts16import com.magicbell.sdk.feature.storerealtime.mock.RealTimeEventMock17import com.magicbell.sdk.feature.storerealtime.mock.StoreRealTimeMock18import io.kotest.matchers.collections.shouldNotBeEmpty19import io.kotest.matchers.ints.shouldBeExactly20import io.kotest.matchers.nulls.shouldBeNull21import io.kotest.matchers.nulls.shouldNotBeNull22import io.kotest.matchers.shouldBe23import io.kotest.matchers.shouldNotBe24import io.mockk.coEvery25import io.mockk.coVerify26import io.mockk.mockk27import kotlinx.coroutines.CoroutineScope28import kotlinx.coroutines.Dispatchers29import kotlinx.coroutines.asCoroutineDispatcher30import kotlinx.coroutines.delay31import kotlinx.coroutines.newSingleThreadContext32import kotlinx.coroutines.runBlocking33import kotlinx.coroutines.test.resetMain34import kotlinx.coroutines.test.setMain35import org.junit.jupiter.api.AfterEach36import org.junit.jupiter.api.BeforeEach37import org.junit.jupiter.api.Test38import java.util.concurrent.Executors39import kotlin.random.Random40internal class NotificationStoreRealTimeTests {41 private val defaultEdgeArraySize = 2042 private val anyIndexForDefaultEdgeArraySize by lazy { Random.nextInt(0, defaultEdgeArraySize) }43 private val userQuery = UserQuery.createEmail("javier@mobilejazz.com")44 private val coroutineContext = Executors.newFixedThreadPool(1).asCoroutineDispatcher()45 private val mainThread = object : MainThread {46 override fun post(run: () -> Unit) {47 run()48 }49 }50 lateinit var storeRealTime: StoreRealTimeMock51 var fetchStorePageInteractor: FetchStorePageInteractor = mockk()52 var actionNotificationInteractor: ActionNotificationInteractor = mockk()53 var deleteNotificationInteractor: DeleteNotificationInteractor = mockk()54 var getConfigInteractor: GetConfigInteractor = mockk()55 var deleteConfigInteractor: DeleteConfigInteractor = mockk()56 lateinit var storeDirector: StoreDirector57 fun createStoreDirector(58 predicate: StorePredicate,59 fetchStoreExpectedResult: Result<StorePage>60 ): NotificationStore {61 fetchStoreExpectedResult.fold(onSuccess = {62 coEvery { fetchStorePageInteractor.invoke(any(), any(), any()) } returns fetchStoreExpectedResult.getOrThrow()63 }, onFailure = {64 coEvery { fetchStorePageInteractor.invoke(any(), any(), any()) } throws it65 })66 coEvery { getConfigInteractor.invoke(any(), any()) } returns Config(Ws("channel-1"))67 coEvery { deleteConfigInteractor.invoke(any()) } returns Unit68 storeRealTime = StoreRealTimeMock()69 storeDirector = RealTimeByPredicateStoreDirector(70 userQuery,71 coroutineContext,72 CoroutineScope(mainThreadSurrogate),73 mainThread,74 fetchStorePageInteractor,75 actionNotificationInteractor,76 deleteNotificationInteractor,77 getConfigInteractor,78 deleteConfigInteractor,79 storeRealTime80 )81 return storeDirector.build(predicate)82 }83 private val mainThreadSurrogate = newSingleThreadContext("UI thread")84 @BeforeEach85 fun setUp() {86 Dispatchers.setMain(mainThreadSurrogate)87 }88 @AfterEach89 fun tearDown() {90 Dispatchers.resetMain() // reset the main dispatcher to the original Main dispatcher91 mainThreadSurrogate.close()92 }93 @Test94 fun test_addRealTimeStore() {95 // GIVEN96 val predicate = StorePredicate()97 val storePage = givenPageStore(predicate, defaultEdgeArraySize)98 // WHEN99 createStoreDirector(100 predicate,101 Result.success(storePage)102 )103 // THEN104 storeRealTime.observers.size.shouldBeExactly(1)105 }106 @Test107 fun test_notifyNewNotification_withDefaultStorePredicate_shouldRefreshStore() = runBlocking {108 // GIVEN109 val predicate = StorePredicate()110 val storePage = givenPageStore(predicate, defaultEdgeArraySize)111 val store = createStoreDirector(112 predicate,113 Result.success(storePage)114 )115 // WHEN116 store.fetch().getOrThrow()117 storeRealTime.processMessage(RealTimeEventMock.NewNotification("NewNotification"))118 // THEN119 coVerify(exactly = 2) { fetchStorePageInteractor.invoke(any(), any(), any()) }120 store.size.shouldBeExactly(defaultEdgeArraySize)121 storePage.edges.mapIndexed { index, edge ->122 store[index].id.shouldBe(edge.node.id)123 }124 Unit125 }126 @Test127 fun test_notifyReadNotification_withDefaultStorePredicateAndReadAndExists_shouldDoNothing() = runBlocking {128 // GIVEN129 val predicate = StorePredicate()130 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Read)131 val store = createStoreDirector(132 predicate,133 Result.success(storePage)134 )135 // WHEN136 store.fetch().getOrThrow()137 val initialCounter = InitialNotificationStoreCounts(store)138 val chosenIndex = anyIndexForDefaultEdgeArraySize139 storeRealTime.processMessage(RealTimeEventMock.ReadNotification(chosenIndex.toString()))140 // THEN141 coVerify(exactly = 1) { fetchStorePageInteractor.invoke(any(), any(), any()) }142 store.size.shouldBeExactly(defaultEdgeArraySize)143 store.totalCount.shouldBeExactly(initialCounter.totalCount)144 store.unreadCount.shouldBeExactly(initialCounter.unreadCount)145 Unit146 }147 @Test148 fun test_notifyReadNotification_withDefaultStorePredicateAndUnreadAndExists_shouldUpdateNotification() = runBlocking {149 // GIVEN150 val predicate = StorePredicate()151 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Unread)152 val store = createStoreDirector(153 predicate,154 Result.success(storePage)155 )156 // WHEN157 store.fetch().getOrThrow()158 val initialCounter = InitialNotificationStoreCounts(store)159 val chosenIndex = anyIndexForDefaultEdgeArraySize160 storeRealTime.processMessage(RealTimeEventMock.ReadNotification(chosenIndex.toString()))161 // THEN162 store[chosenIndex].readAt.shouldNotBeNull()163 coVerify(exactly = 1) { fetchStorePageInteractor.invoke(any(), any(), any()) }164 store.size.shouldBeExactly(defaultEdgeArraySize)165 store.totalCount.shouldBeExactly(initialCounter.totalCount)166 store.unreadCount.shouldBeExactly(initialCounter.unreadCount - 1)167 Unit168 }169 @Test170 fun test_notifyReadNotification_withDefaultStorePredicateAndUnseenAndExists_shouldUpdateNotification() = runBlocking {171 // GIVEN172 val predicate = StorePredicate()173 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Unseen)174 val store = createStoreDirector(175 predicate,176 Result.success(storePage)177 )178 // WHEN179 store.fetch().getOrThrow()180 val initialCounter = InitialNotificationStoreCounts(store)181 val chosenIndex = anyIndexForDefaultEdgeArraySize182 storeRealTime.processMessage(RealTimeEventMock.ReadNotification(chosenIndex.toString()))183 // THEN184 store[chosenIndex].readAt.shouldNotBeNull()185 store[chosenIndex].seenAt.shouldNotBeNull()186 coVerify(exactly = 1) { fetchStorePageInteractor.invoke(any(), any(), any()) }187 store.size.shouldBeExactly(defaultEdgeArraySize)188 store.totalCount.shouldBeExactly(initialCounter.totalCount)189 store.unreadCount.shouldBeExactly(initialCounter.unreadCount - 1)190 store.unseenCount.shouldBeExactly(initialCounter.unseenCount - 1)191 Unit192 }193 @Test194 fun test_notifyReadNotification_withDefaultStorePredicateAndDoesntExists_shouldRefresh() = runBlocking {195 // GIVEN196 val predicate = StorePredicate()197 val storePage = givenPageStore(predicate, defaultEdgeArraySize)198 val store = createStoreDirector(199 predicate,200 Result.success(storePage)201 )202 // WHEN203 store.fetch().getOrThrow()204 val initialCounter = InitialNotificationStoreCounts(store)205 storeRealTime.processMessage(RealTimeEventMock.ReadNotification("Not exists"))206 // THEN207 coVerify(exactly = 2) { fetchStorePageInteractor.invoke(any(), any(), any()) }208 store.size.shouldBeExactly(defaultEdgeArraySize)209 store.totalCount.shouldBeExactly(initialCounter.totalCount)210 storePage.edges.mapIndexed { index, edge ->211 store[index].id.shouldBe(edge.node.id)212 }213 Unit214 }215 @Test216 fun test_notifyUnreadNotification_withDefaultStorePredicateAndReadAndExists_shouldUpdateNotification() = runBlocking {217 // GIVEN218 val predicate = StorePredicate()219 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Read)220 val store = createStoreDirector(221 predicate,222 Result.success(storePage)223 )224 // WHEN225 store.fetch().getOrThrow()226 val initialCounter = InitialNotificationStoreCounts(store)227 val chosenIndex = anyIndexForDefaultEdgeArraySize228 storeRealTime.processMessage(RealTimeEventMock.UnreadNotification(chosenIndex.toString()))229 // THEN230 store[chosenIndex].readAt.shouldBeNull()231 coVerify(exactly = 1) { fetchStorePageInteractor.invoke(any(), any(), any()) }232 store.size.shouldBeExactly(defaultEdgeArraySize)233 store.totalCount.shouldBeExactly(initialCounter.totalCount)234 store.unreadCount.shouldBeExactly(initialCounter.unreadCount + 1)235 store.unseenCount.shouldBeExactly(initialCounter.unseenCount)236 Unit237 }238 @Test239 fun test_notifyUnreadNotification_withDefaultStorePredicateAndUnreadAndExists_shouldUpdateNotification() = runBlocking {240 // GIVEN241 val predicate = StorePredicate()242 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Unread)243 val store = createStoreDirector(244 predicate,245 Result.success(storePage)246 )247 // WHEN248 store.fetch().getOrThrow()249 val initialCounter = InitialNotificationStoreCounts(store)250 val chosenIndex = anyIndexForDefaultEdgeArraySize251 storeRealTime.processMessage(RealTimeEventMock.UnreadNotification(chosenIndex.toString()))252 // THEN253 store[chosenIndex].readAt.shouldBeNull()254 coVerify(exactly = 1) { fetchStorePageInteractor.invoke(any(), any(), any()) }255 store.size.shouldBeExactly(defaultEdgeArraySize)256 store.totalCount.shouldBeExactly(initialCounter.totalCount)257 store.unreadCount.shouldBeExactly(initialCounter.unreadCount)258 store.unseenCount.shouldBeExactly(initialCounter.unseenCount)259 Unit260 }261 @Test262 fun test_notifyUnreadNotification_withDefaultStorePredicateAndNotExists_shouldRefresh() = runBlocking {263 // GIVEN264 val predicate = StorePredicate()265 val storePage = givenPageStore(predicate, defaultEdgeArraySize)266 val store = createStoreDirector(267 predicate,268 Result.success(storePage)269 )270 // WHEN271 store.fetch().getOrThrow()272 storeRealTime.processMessage(RealTimeEventMock.UnreadNotification("Not exists"))273 // THEN274 coVerify(exactly = 2) { fetchStorePageInteractor.invoke(any(), any(), any()) }275 store.size.shouldBeExactly(defaultEdgeArraySize)276 Unit277 }278 @Test279 fun test_notifyDeleteNotification_withDefaultStorePredicateAndUnreadAndExists_shouldRemoveNotificationAndUnreadCount() = runBlocking {280 // GIVEN281 val predicate = StorePredicate()282 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Unread)283 val store = createStoreDirector(284 predicate,285 Result.success(storePage)286 )287 // WHEN288 store.fetch().getOrThrow()289 val initialCounter = InitialNotificationStoreCounts(store)290 val chosenIndex = anyIndexForDefaultEdgeArraySize291 val removedNotificationId = store[chosenIndex].id292 storeRealTime.processMessage(RealTimeEventMock.DeleteNotification(chosenIndex.toString()))293 // THEN294 coVerify(exactly = 1) { fetchStorePageInteractor.invoke(any(), any(), any()) }295 store.totalCount.shouldBeExactly(initialCounter.totalCount - 1)296 store.unreadCount.shouldBeExactly(initialCounter.unreadCount - 1)297 store.forEach { notification ->298 notification.id.shouldNotBe(removedNotificationId)299 }300 }301 @Test302 fun test_notifyDeleteNotification_withDefaultStorePredicateAndUnseenAndExists_shouldUpdateUnseenCount() = runBlocking {303 // GIVEN304 val predicate = StorePredicate()305 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Unseen)306 val store = createStoreDirector(307 predicate,308 Result.success(storePage)309 )310 // WHEN311 store.fetch().getOrThrow()312 val initialCounter = InitialNotificationStoreCounts(store)313 val chosenIndex = anyIndexForDefaultEdgeArraySize314 storeRealTime.processMessage(RealTimeEventMock.DeleteNotification(chosenIndex.toString()))315 // THEN316 coVerify(exactly = 1) { fetchStorePageInteractor.invoke(any(), any(), any()) }317 store.unseenCount.shouldBeExactly(initialCounter.unseenCount - 1)318 Unit319 }320 @Test321 fun test_notifyDeleteNotification_withDefaultStorePredicateAndSeenAndExists_shouldSameUnseenCount() = runBlocking {322 // GIVEN323 val predicate = StorePredicate()324 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Seen)325 val store = createStoreDirector(326 predicate,327 Result.success(storePage)328 )329 // WHEN330 store.fetch().getOrThrow()331 val initialCounter = InitialNotificationStoreCounts(store)332 val chosenIndex = anyIndexForDefaultEdgeArraySize333 storeRealTime.processMessage(RealTimeEventMock.DeleteNotification(chosenIndex.toString()))334 // THEN335 coVerify(exactly = 1) { fetchStorePageInteractor.invoke(any(), any(), any()) }336 store.unseenCount.shouldBeExactly(initialCounter.unseenCount)337 Unit338 }339 @Test340 fun test_notifyDeleteNotification_withDefaultStorePredicateAndNotExists_shouldDoNothing() = runBlocking {341 // GIVEN342 val predicate = StorePredicate()343 val storePage = givenPageStore(predicate, defaultEdgeArraySize)344 val store = createStoreDirector(345 predicate,346 Result.success(storePage)347 )348 // WHEN349 store.fetch().getOrThrow()350 val initialCounter = InitialNotificationStoreCounts(store)351 storeRealTime.processMessage(RealTimeEventMock.DeleteNotification("Not exists"))352 // THEN353 coVerify(exactly = 1) { fetchStorePageInteractor.invoke(any(), any(), any()) }354 store.totalCount.shouldBeExactly(initialCounter.totalCount)355 store.unreadCount.shouldBeExactly(initialCounter.unreadCount)356 store.unseenCount.shouldBeExactly(initialCounter.unseenCount)357 Unit358 }359 @Test360 fun test_notifyReadAllNotification_withDefaultStorePredicate_shouldRefresh() = runBlocking {361 // GIVEN362 val predicate = StorePredicate()363 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Read)364 val store = createStoreDirector(365 predicate,366 Result.success(storePage)367 )368 // WHEN369 store.fetch().getOrThrow()370 storeRealTime.processMessage(RealTimeEventMock.ReadAllNotification)371 // THEN372 coVerify(exactly = 2) { fetchStorePageInteractor.invoke(any(), any(), any()) }373 store.size.shouldBeExactly(defaultEdgeArraySize)374 store.forEach { notification ->375 notification.readAt.shouldNotBeNull()376 }377 }378 @Test379 fun test_notifySeenAllNotification_withDefaultStorePredicate_shouldRefresh() = runBlocking {380 // GIVEN381 val predicate = StorePredicate()382 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Read)383 val store = createStoreDirector(384 predicate,385 Result.success(storePage)386 )387 // WHEN388 store.fetch().getOrThrow()389 storeRealTime.processMessage(RealTimeEventMock.SeenAllNotification)390 // THEN391 coVerify(exactly = 2) { fetchStorePageInteractor.invoke(any(), any(), any()) }392 store.size.shouldBeExactly(defaultEdgeArraySize)393 store.forEach { notification ->394 notification.seenAt.shouldNotBeNull()395 }396 }397 // MARK: - Observer tests398 @Test399 fun test_addContentObserver_ShouldNotifyRefreshStore() = runBlocking {400 // GIVEN401 val contentObserver = ContentObserverMock()402 val predicate = StorePredicate()403 val storePage = givenPageStore(predicate, defaultEdgeArraySize)404 val store = createStoreDirector(405 predicate,406 Result.success(storePage)407 )408 store.addContentObserver(contentObserver)409 // WHEN410 storeRealTime.processMessage(RealTimeEventMock.NewNotification("NewNotification"))411 // THEN412 delay(100)413 contentObserver.reloadStoreCounter.shouldBeExactly(1)414 contentObserver.reloadStoreSpy.shouldNotBeEmpty()415 Unit416 }417 @Test418 fun test_notifyReadNotification_withReadStorePredicateAndExists_ShouldDidChangeDelegate() = runBlocking {419 // GIVEN420 val contentObserver = ContentObserverMock()421 val predicate = StorePredicate(read = true)422 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Read)423 val store = createStoreDirector(424 predicate,425 Result.success(storePage)426 )427 store.addContentObserver(contentObserver)428 // WHEN429 store.fetch().getOrThrow()430 val chosenIndex = anyIndexForDefaultEdgeArraySize431 storeRealTime.processMessage(RealTimeEventMock.ReadNotification(chosenIndex.toString()))432 // THEN433 contentObserver.reloadStoreCounter.shouldBeExactly(0)434 contentObserver.didChangeCounter.shouldBeExactly(1)435 contentObserver.didChangeSpy[0].indexes.shouldBe(listOf(chosenIndex))436 }437 @Test438 fun test_notifyReadNotification_withReadStorePredicateAndDoesntExist_ShouldNotifyReadNotification() = runBlocking {439 // GIVEN440 val contentObserver = ContentObserverMock()441 val predicate = StorePredicate(read = true)442 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Read)443 val store = createStoreDirector(444 predicate,445 Result.success(storePage)446 )447 store.addContentObserver(contentObserver)448 // WHEN449 store.fetch().getOrThrow()450 storeRealTime.processMessage(RealTimeEventMock.ReadNotification("Not exists"))451 // THEN452 delay(100)453 contentObserver.reloadStoreCounter.shouldBeExactly(1)454 contentObserver.didChangeCounter.shouldBeExactly(0)455 Unit456 }457 @Test458 fun test_notifyReadNotification_WithUnreadStorePredicateAndExists_ShouldNotifyChange() = runBlocking {459 // GIVEN460 val contentObserver = ContentObserverMock()461 val predicate = StorePredicate(read = false)462 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Unread)463 val store = createStoreDirector(464 predicate,465 Result.success(storePage)466 )467 store.addContentObserver(contentObserver)468 // WHEN469 store.fetch().getOrThrow()470 val chosenIndex = anyIndexForDefaultEdgeArraySize471 storeRealTime.processMessage(RealTimeEventMock.ReadNotification(chosenIndex.toString()))472 // THEN473 contentObserver.reloadStoreCounter.shouldBeExactly(0)474 contentObserver.didChangeCounter.shouldBeExactly(0)475 contentObserver.didDeleteCounter.shouldBeExactly(1)476 contentObserver.didDeleteSpy[0].indexes.shouldBe(listOf(chosenIndex))477 }478 @Test479 fun test_notifyDeleteNotification_WithDefaultStorePredicateAndExists_ShouldNotifyDeletion() = runBlocking {480 // GIVEN481 val contentObserver = ContentObserverMock()482 val predicate = StorePredicate()483 val storePage = givenPageStore(predicate, defaultEdgeArraySize)484 val store = createStoreDirector(485 predicate,486 Result.success(storePage)487 )488 store.addContentObserver(contentObserver)489 // WHEN490 store.fetch().getOrThrow()491 val chosenIndex = anyIndexForDefaultEdgeArraySize492 storeRealTime.processMessage(RealTimeEventMock.DeleteNotification(chosenIndex.toString()))493 // THEN494 contentObserver.reloadStoreCounter.shouldBeExactly(0)495 contentObserver.didChangeCounter.shouldBeExactly(0)496 contentObserver.didDeleteCounter.shouldBeExactly(1)497 contentObserver.didDeleteSpy[0].indexes.shouldBe(listOf(chosenIndex))498 }499 @Test500 fun test_notifyMarkAllRead_WithUnreadStorePredicate_ShouldClearStore() = runBlocking {501 // GIVEN502 val contentObserver = ContentObserverMock()503 val predicate = StorePredicate(read = false)504 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Unread)505 val store = createStoreDirector(506 predicate,507 Result.success(storePage)508 )509 store.addContentObserver(contentObserver)510 // WHEN511 store.fetch().getOrThrow()512 val initialCounts = InitialNotificationStoreCounts(store)513 storeRealTime.processMessage(RealTimeEventMock.ReadAllNotification)514 // THEN515 contentObserver.reloadStoreCounter.shouldBeExactly(0)516 contentObserver.didChangeCounter.shouldBeExactly(0)517 contentObserver.didDeleteCounter.shouldBeExactly(1)518 contentObserver.didDeleteSpy[0].indexes.shouldBe(0.until(initialCounts.totalCount).toList())519 store.totalCount.shouldBeExactly(0)520 store.unreadCount.shouldBeExactly(0)521 store.unseenCount.shouldBeExactly(0)522 Unit523 }524 @Test525 fun test_notifyMarkAllSeen_WithUnseenStorePredicate_ShouldClearStore() = runBlocking {526 // GIVEN527 val contentObserver = ContentObserverMock()528 val predicate = StorePredicate(seen = false)529 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Unseen)530 val store = createStoreDirector(531 predicate,532 Result.success(storePage)533 )534 store.addContentObserver(contentObserver)535 // WHEN536 store.fetch().getOrThrow()537 val initialCounts = InitialNotificationStoreCounts(store)538 storeRealTime.processMessage(RealTimeEventMock.SeenAllNotification)539 // THEN540 contentObserver.reloadStoreCounter.shouldBeExactly(0)541 contentObserver.didChangeCounter.shouldBeExactly(0)542 contentObserver.didDeleteCounter.shouldBeExactly(1)543 contentObserver.didDeleteSpy[0].indexes.shouldBe(0.until(initialCounts.totalCount).toList())544 store.totalCount.shouldBeExactly(0)545 store.unreadCount.shouldBeExactly(0)546 store.unseenCount.shouldBeExactly(0)547 Unit548 }549 @Test550 fun test_notifyNewNotification_WithDefaultStorePredicate_ShouldRefreshStoreAndCounters() = runBlocking {551 // GIVEN552 val countObserver = CountObserverMock()553 val predicate = StorePredicate()554 val storePage = givenPageStore(predicate, defaultEdgeArraySize)555 val store = createStoreDirector(556 predicate,557 Result.success(storePage)558 )559 store.addCountObserver(countObserver)560 // WHEN561 store.fetch().getOrThrow()562 storeRealTime.processMessage(RealTimeEventMock.NewNotification("NewId"))563 // THEN564 delay(100)565 countObserver.totalCountCounter.shouldBeExactly(2)566 countObserver.unreadCountCounter.shouldBeExactly(2)567 countObserver.unseenCountCounter.shouldBeExactly(2)568 Unit569 }570 @Test571 fun test_notifyReadNotification_WithDefaultStorePredicateAndUnread_ShouldRefreshStoreAndCounters() = runBlocking {572 // GIVEN573 val countObserver = CountObserverMock()574 val predicate = StorePredicate()575 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Unread)576 val store = createStoreDirector(577 predicate,578 Result.success(storePage)579 )580 store.addCountObserver(countObserver)581 // WHEN582 store.fetch().getOrThrow()583 val initialCounts = InitialNotificationStoreCounts(store)584 val chosenIndex = anyIndexForDefaultEdgeArraySize585 storeRealTime.processMessage(RealTimeEventMock.ReadNotification(chosenIndex.toString()))586 // THEN587 countObserver.totalCountCounter.shouldBeExactly(1)588 countObserver.totalCountSpy[0].count.shouldBeExactly(store.totalCount)589 countObserver.unreadCountCounter.shouldBeExactly(2)590 countObserver.unreadCountSpy[0].count.shouldBeExactly(initialCounts.unreadCount)591 countObserver.unreadCountSpy[1].count.shouldBeExactly(initialCounts.unreadCount - 1)592 Unit593 }594 @Test595 fun test_notifyReadNotification_WithDefaultStorePredicateAndRead_ShouldRefreshStoreAndCounters() = runBlocking {596 // GIVEN597 val countObserver = CountObserverMock()598 val predicate = StorePredicate()599 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Read)600 val store = createStoreDirector(601 predicate,602 Result.success(storePage)603 )604 store.addCountObserver(countObserver)605 // WHEN606 store.fetch().getOrThrow()607 val chosenIndex = anyIndexForDefaultEdgeArraySize608 storeRealTime.processMessage(RealTimeEventMock.ReadNotification(chosenIndex.toString()))609 // THEN610 delay(100)611 countObserver.totalCountCounter.shouldBeExactly(1)612 countObserver.totalCountSpy[0].count.shouldBeExactly(store.size)613 countObserver.unreadCountCounter.shouldBeExactly(0)614 Unit615 }616 @Test617 fun test_notifyReadNotification_WithDefaultStorePredicateAndUnseen_ShouldRefreshStoreAndCounters() = runBlocking {618 // GIVEN619 val countObserver = CountObserverMock()620 val predicate = StorePredicate()621 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Unseen)622 val store = createStoreDirector(623 predicate,624 Result.success(storePage)625 )626 store.addCountObserver(countObserver)627 // WHEN628 store.fetch().getOrThrow()629 val initialCounts = InitialNotificationStoreCounts(store)630 val chosenIndex = anyIndexForDefaultEdgeArraySize631 storeRealTime.processMessage(RealTimeEventMock.ReadNotification(chosenIndex.toString()))632 // THEN633 countObserver.totalCountCounter.shouldBeExactly(1)634 countObserver.totalCountSpy[0].count.shouldBeExactly(store.size)635 countObserver.unseenCountCounter.shouldBeExactly(2)636 countObserver.unseenCountSpy[0].count.shouldBeExactly(initialCounts.unseenCount)637 countObserver.unseenCountSpy[1].count.shouldBeExactly(initialCounts.unseenCount - 1)638 Unit639 }640 @Test641 fun test_notifyReadNotification_WithDefaultStorePredicateAndSeen_ShouldRefreshStoreAndCounters() = runBlocking {642 // GIVEN643 val countObserver = CountObserverMock()644 val predicate = StorePredicate()645 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Seen)646 val store = createStoreDirector(647 predicate,648 Result.success(storePage)649 )650 store.addCountObserver(countObserver)651 // WHEN652 store.fetch().getOrThrow()653 val chosenIndex = anyIndexForDefaultEdgeArraySize654 storeRealTime.processMessage(RealTimeEventMock.ReadNotification(chosenIndex.toString()))655 // THEN656 countObserver.totalCountCounter.shouldBeExactly(1)657 countObserver.totalCountSpy[0].count.shouldBeExactly(store.size)658 countObserver.unseenCountCounter.shouldBeExactly(0)659 Unit660 }661 @Test662 fun test_notifyReadNotification_WithUnreadStorePredicateAndUnread_ShouldRefreshStoreAndCounters() = runBlocking {663 // GIVEN664 val countObserver = CountObserverMock()665 val predicate = StorePredicate(read = false)666 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Unread)667 val store = createStoreDirector(668 predicate,669 Result.success(storePage)670 )671 store.addCountObserver(countObserver)672 // WHEN673 store.fetch().getOrThrow()674 val initialCounts = InitialNotificationStoreCounts(store)675 val chosenIndex = anyIndexForDefaultEdgeArraySize676 storeRealTime.processMessage(RealTimeEventMock.ReadNotification(chosenIndex.toString()))677 // THEN678 delay(100)679 countObserver.totalCountCounter.shouldBeExactly(2)680 countObserver.unreadCountCounter.shouldBeExactly(2)681 countObserver.unreadCountSpy[0].count.shouldBeExactly(initialCounts.unreadCount)682 countObserver.unreadCountSpy[1].count.shouldBeExactly(initialCounts.unreadCount - 1)683 Unit684 }685 @Test686 fun test_notifyReadNotification_WithUnreadStorePredicateAndRead_ShouldRefreshStoreAndCounters() = runBlocking {687 // GIVEN688 val countObserver = CountObserverMock()689 val predicate = StorePredicate(read = false)690 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Read)691 val store = createStoreDirector(692 predicate,693 Result.success(storePage)694 )695 store.addCountObserver(countObserver)696 // WHEN697 store.fetch().getOrThrow()698 val chosenIndex = anyIndexForDefaultEdgeArraySize699 storeRealTime.processMessage(RealTimeEventMock.ReadNotification(chosenIndex.toString()))700 countObserver.totalCountCounter.shouldBeExactly(1)701 countObserver.unreadCountCounter.shouldBeExactly(0)702 Unit703 }704 @Test705 fun test_notifyReadNotification_WithUnreadStorePredicateAndUnseen_ShouldRefreshStoreAndCounters() = runBlocking {706 // GIVEN707 val countObserver = CountObserverMock()708 val predicate = StorePredicate(read = false)709 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Unseen)710 val store = createStoreDirector(711 predicate,712 Result.success(storePage)713 )714 store.addCountObserver(countObserver)715 // WHEN716 store.fetch().getOrThrow()717 val initialCounts = InitialNotificationStoreCounts(store)718 val chosenIndex = anyIndexForDefaultEdgeArraySize719 storeRealTime.processMessage(RealTimeEventMock.ReadNotification(chosenIndex.toString()))720 // THEN721 countObserver.totalCountCounter.shouldBeExactly(2)722 countObserver.totalCountSpy[0].count.shouldBeExactly(initialCounts.totalCount)723 countObserver.totalCountSpy[1].count.shouldBeExactly(initialCounts.totalCount - 1)724 countObserver.unseenCountCounter.shouldBeExactly(2)725 countObserver.unseenCountSpy[0].count.shouldBeExactly(initialCounts.unseenCount)726 countObserver.unseenCountSpy[1].count.shouldBeExactly(initialCounts.unseenCount - 1)727 Unit728 }729 @Test730 fun test_notifyReadNotification_WithUnreadStorePredicateAndSeen_ShouldRefreshStoreAndCounters() = runBlocking {731 // GIVEN732 val countObserver = CountObserverMock()733 val predicate = StorePredicate(read = false)734 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Seen)735 val store = createStoreDirector(736 predicate,737 Result.success(storePage)738 )739 store.addCountObserver(countObserver)740 // WHEN741 store.fetch().getOrThrow()742 val initialCounts = InitialNotificationStoreCounts(store)743 val chosenIndex = anyIndexForDefaultEdgeArraySize744 storeRealTime.processMessage(RealTimeEventMock.ReadNotification(chosenIndex.toString()))745 // THEN746 countObserver.totalCountCounter.shouldBeExactly(2)747 countObserver.totalCountSpy[0].count.shouldBeExactly(initialCounts.totalCount)748 countObserver.totalCountSpy[1].count.shouldBeExactly(initialCounts.totalCount - 1)749 countObserver.unseenCountCounter.shouldBeExactly(0)750 Unit751 }752 @Test753 fun test_notifyReadAllNotification_WithDefaultStorePredicateAndRead_ShouldNotifyCounters() = runBlocking {754 // GIVEN755 val countObserver = CountObserverMock()756 val predicate = StorePredicate()757 val storePage = givenPageStore(predicate, defaultEdgeArraySize)758 val store = createStoreDirector(759 predicate,760 Result.success(storePage)761 )762 store.addCountObserver(countObserver)763 // WHEN764 store.fetch().getOrThrow()765 val initialCounts = InitialNotificationStoreCounts(store)766 coEvery { fetchStorePageInteractor.invoke(any(), any(), any()) } returns givenPageStore(predicate, 15, forceProperty = ForceProperty.Read)767 storeRealTime.processMessage(RealTimeEventMock.ReadAllNotification)768 // THEN769 delay(100)770 countObserver.totalCountCounter.shouldBeExactly(2)771 countObserver.unreadCountCounter.shouldBeExactly(1)772 countObserver.unreadCountSpy[0].count.shouldBeExactly(initialCounts.unreadCount)773 countObserver.unseenCountCounter.shouldBeExactly(1)774 Unit775 }776 @Test777 fun test_notifySeenAllNotification_WithDefaultStorePredicate_ShouldNotifyCounters() = runBlocking {778 // GIVEN779 val countObserver = CountObserverMock()780 val predicate = StorePredicate()781 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Unread)782 val store = createStoreDirector(783 predicate,784 Result.success(storePage)785 )786 store.addCountObserver(countObserver)787 // WHEN788 store.fetch().getOrThrow()789 val initialCounts = InitialNotificationStoreCounts(store)790 coEvery { fetchStorePageInteractor.invoke(any(), any(), any()) } returns givenPageStore(predicate, 15, forceProperty = ForceProperty.Read)791 storeRealTime.processMessage(RealTimeEventMock.SeenAllNotification)792 // THEN793 delay(100)794 countObserver.totalCountCounter.shouldBeExactly(2)795 countObserver.unreadCountCounter.shouldBeExactly(1)796 countObserver.unreadCountSpy[0].count.shouldBeExactly(initialCounts.unreadCount)797 countObserver.unseenCountCounter.shouldBeExactly(1)798 countObserver.unseenCountSpy[0].count.shouldBeExactly(initialCounts.unseenCount)799 Unit800 }801 @Test802 fun test_removeCountObserver() = runBlocking {803 // GIVEN804 val countObserver = CountObserverMock()805 val predicate = StorePredicate()806 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Unread)807 val store = createStoreDirector(808 predicate,809 Result.success(storePage)810 )811 // WHEN812 store.addCountObserver(countObserver)813 store.removeCountObserver(countObserver)814 storeRealTime.processMessage(RealTimeEventMock.SeenAllNotification)815 store.fetch().getOrThrow()816 // THEN817 countObserver.totalCountCounter.shouldBeExactly(0)818 Unit819 }820 @Test821 fun test_removeContentObserver() = runBlocking {822 // GIVEN823 val contentObserver = ContentObserverMock()824 val predicate = StorePredicate()825 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Unread)826 val store = createStoreDirector(827 predicate,828 Result.success(storePage)829 )830 // WHEN831 store.addContentObserver(contentObserver)832 store.removeContentObserver(contentObserver)833 storeRealTime.processMessage(RealTimeEventMock.SeenAllNotification)834 store.fetch().getOrThrow()835 // THEN836 contentObserver.didInsertCounter.shouldBeExactly(0)837 Unit838 }839 @Test840 fun test_notifyArchiveNotification_withDefaultStorePredicateAndExists_shouldDoNothing() = runBlocking {841 // GIVEN842 val predicate = StorePredicate()843 val storePage = givenPageStore(predicate, defaultEdgeArraySize, forceProperty = ForceProperty.Unarchived)844 val store = createStoreDirector(845 predicate,846 Result.success(storePage)847 )848 // WHEN849 store.fetch().getOrThrow()850 val initialCounter = InitialNotificationStoreCounts(store)851 val chosenIndex = anyIndexForDefaultEdgeArraySize852 storeRealTime.processMessage(853 RealTimeEventMock.ArchiveNotification(chosenIndex.toString())854 )855 // THEN856 coVerify(exactly = 1) { fetchStorePageInteractor.invoke(any(), any(), any()) }857 store.size.shouldBeExactly(defaultEdgeArraySize - 1)858 store.totalCount.shouldBeExactly(initialCounter.totalCount - 1)859 Unit860 }861}...

Full Screen

Full Screen

predef-test.kt

Source:predef-test.kt Github

copy

Full Screen

...102 }103}104fun Arb.Companion.throwable(): Arb<Throwable> =105 Arb.string().map(::RuntimeException)106fun <A> Arb.Companion.result(right: Arb<A>): Arb<Result<A>> {107 val failure: Arb<Result<A>> = Arb.throwable().map { e -> Result.failure<A>(e) }108 val success: Arb<Result<A>> = right.map { a -> Result.success(a) }109 return Arb.choice(failure, success)110}111fun <L, R> Arb.Companion.either(left: Arb<L>, right: Arb<R>): Arb<Either<L, R>> {112 val failure: Arb<Either<L, R>> = left.map { l -> l.left() }113 val success: Arb<Either<L, R>> = right.map { r -> r.right() }114 return Arb.choice(failure, success)115}116fun Arb.Companion.intRange(min: Int = Int.MIN_VALUE, max: Int = Int.MAX_VALUE): Arb<IntRange> =117 Arb.bind(Arb.int(min, max), Arb.int(min, max)) { a, b ->118 if (a < b) a..b else b..a119 }120fun Arb.Companion.longRange(min: Long = Long.MIN_VALUE, max: Long = Long.MAX_VALUE): Arb<LongRange> =...

Full Screen

Full Screen

shrink.kt

Source:shrink.kt Github

copy

Full Screen

...26 val tested = mutableSetOf<A>()27 val sb = StringBuilder()28 sb.append("Attempting to shrink arg ${initial.value().print().value}\n")29 val stepResult = doStep(initial, mode, tested, counter, test, sb)30 result(sb, stepResult, counter.count)31 return if (stepResult == null) {32 ShrinkResult(initial.value(), initial.value(), null)33 } else {34 ShrinkResult(initial.value(), stepResult.failed, stepResult.cause)35 }36}37class Counter {38 var count = 039 fun inc() = count++40}41/**42 * The result of shrinking a failed arg.43 * If no shrinking took place, shrink should be set to the same as iniital44 */45data class ShrinkResult<out A>(val initial: A, val shrink: A, val cause: Throwable?)46data class StepResult<A>(val failed: A, val cause: Throwable)47/**48 * Performs shrinking on the given RTree. Recurses into the tree for failing cases.49 * Returns the last candidate to fail as a [StepResult] or null if the initial passes.50 */51suspend fun <A> doStep(52 tree: RTree<A>,53 mode: ShrinkingMode,54 tested: MutableSet<A>,55 counter: Counter,56 test: suspend (A) -> Unit,57 sb: StringBuilder58): StepResult<A>? {59 // if no more shrinking return null (if we've hit the bounds)60 if (!mode.isShrinking(counter.count)) return null61 val candidates = tree.children.value62 candidates.asSequence()63 // shrinkers might generate duplicate candidates so we must filter them out to avoid infinite loops or slow shrinking64 .filter { tested.add(it.value()) }65 .forEach { a ->66 val candidate = a.value()67 counter.inc()68 try {69 test(candidate)70 if (PropertyTesting.shouldPrintShrinkSteps)71 sb.append("Shrink #${counter.count}: ${candidate.print().value} pass\n")72 } catch (t: Throwable) {73 if (PropertyTesting.shouldPrintShrinkSteps)74 sb.append("Shrink #${counter.count}: ${candidate.print().value} fail\n")75 // this result failed, so we'll recurse in to find further failures otherwise return this candidate76 return doStep(a, mode, tested, counter, test, sb) ?: StepResult(candidate, t)77 }78 }79 return null80}81/**82 * Returns true if we should continue shrinking given the count.83 */84private fun ShrinkingMode.isShrinking(count: Int): Boolean = when (this) {85 ShrinkingMode.Off -> false86 ShrinkingMode.Unbounded -> true87 is ShrinkingMode.Bounded -> count < bound88}89private fun <A> result(sb: StringBuilder, result: StepResult<A>?, count: Int) {90 if (count == 0 || result == null) {91 sb.append("Arg was not shunk\n")92 } else {93 sb.append("Shrink result (after $count shrinks) => ${result.failed.print().value}\n\n")94 when (val location = stacktraces.throwableLocation(result.cause, 4)) {95 null -> sb.append("Caused by ${result.cause}\n")96 else -> {97 sb.append("Caused by ${result.cause} at\n")98 location.forEach { sb.append("\t$it\n") }99 }100 }101 }102 if (PropertyTesting.shouldPrintShrinkSteps) {103 println(sb)104 }105}...

Full Screen

Full Screen

result

Using AI Code Generation

copy

Full Screen

1 val counter = Counter()2 val result = counter.result()3 println(result)4}5fun testCounter() {6 val counter = Counter()7 val result = counter.result()8 println(result)9}10fun testCounter() {11 val counter = Counter()12 val result = counter.result()13 println(result)14}15fun testCounter() {16 val counter = Counter()17 val result = counter.result()18 println(result)19}20fun testCounter() {21 val counter = Counter()22 val result = counter.result()23 println(result)24}25fun testCounter() {26 val counter = Counter()27 val result = counter.result()28 println(result)29}30fun testCounter() {31 val counter = Counter()32 val result = counter.result()33 println(result)34}35fun testCounter() {36 val counter = Counter()37 val result = counter.result()38 println(result)39}40fun testCounter() {41 val counter = Counter()42 val result = counter.result()43 println(result)44}45fun testCounter() {46 val counter = Counter()47 val result = counter.result()48 println(result)49}50fun testCounter() {51 val counter = Counter()52 val result = counter.result()53 println(result)54}55fun testCounter() {56 val counter = Counter()57 val result = counter.result()58 println(result)59}60fun testCounter() {61 val counter = Counter()62 val result = counter.result()63 println(result)64}

Full Screen

Full Screen

result

Using AI Code Generation

copy

Full Screen

1 val success = counter.result().success2 println("Success: $success")3 val failure = counter.result().failure4 println("Failure: $failure")5 val discarded = counter.result().discarded6 println("Discarded: $discarded")7 val total = counter.result().total8 println("Total: $total")9}

Full Screen

Full Screen

result

Using AI Code Generation

copy

Full Screen

1 val counter = Counter()2 val prop = forAll { a: Int, b: Int ->3 counter.increment()4 }5 prop.check()6 counter.result()7}

Full Screen

Full Screen

result

Using AI Code Generation

copy

Full Screen

1+fun main() {2+ val counter = Counter()3+ val prop = forAll(Gen.int()) { x ->4+ counter.increment()5+ }6+ prop.check(iterations = 1000, seed = 1)7+ println(counter.result())8+}9+fun main() {10+ val counter = Counter()11+ val prop = forAll(Gen.int()) { x ->12+ counter.increment()13+ }14+ prop.check(iterations = 1000, seed = 1)15+ println(counter.result())16+}17+fun main() {18+ val counter = Counter()19+ val prop = forAll(Gen.int()) { x ->20+ counter.increment()21+ }22+ prop.check(iterations = 1000, seed = 1)23+ println(counter.result())24+}25+fun main() {26+ val counter = Counter()27+ val prop = forAll(Gen.int()) { x ->28+ counter.increment()29+ }30+ prop.check(iterations = 1000, seed = 1)31+ println(counter.result())32+}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Kotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in Counter

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful