From 86ac0eb8908c803ab91da9c5a3053bb6b9b6caf0 Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Thu, 9 Nov 2023 20:09:12 +0100 Subject: [PATCH] tests: split adding new event tests in `InMemoryBuffer` --- .../parselyandroid/InMemoryBufferTest.kt | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/parsely/src/test/java/com/parsely/parselyandroid/InMemoryBufferTest.kt b/parsely/src/test/java/com/parsely/parselyandroid/InMemoryBufferTest.kt index 1925627e..384ab195 100644 --- a/parsely/src/test/java/com/parsely/parselyandroid/InMemoryBufferTest.kt +++ b/parsely/src/test/java/com/parsely/parselyandroid/InMemoryBufferTest.kt @@ -21,6 +21,22 @@ internal class InMemoryBufferTest { @Test fun `when adding a new event, then save it to local storage and run onEventAdded listener`() = runTest { + // given + val event = mapOf("test" to 123) + sut = InMemoryBuffer(backgroundScope, repository) { } + + // when + sut.add(event) + advanceTimeBy(1.seconds) + runCurrent() + backgroundScope.cancel() + + // then + assertThat(repository.getStoredQueue()).containsOnlyOnce(event) + } + + @Test + fun `given an onEventAdded listener, when adding a new event, then run the onEventAdded listener`() = runTest { // given val event = mapOf("test" to 123) var onEventAddedExecuted = false @@ -33,8 +49,7 @@ internal class InMemoryBufferTest { backgroundScope.cancel() // then - assertThat(repository.getStoredQueue()).containsOnlyOnce(event) - assertThat(onEventAddedExecuted).isTrue() + assertThat(onEventAddedExecuted).isTrue } @Test