Skip to content

Commit

Permalink
style: make getStoredQueue a method
Browse files Browse the repository at this point in the history
  • Loading branch information
wzieba committed Nov 3, 2023
1 parent 5fb5f35 commit 5822eb4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@ internal open class LocalStorageRepository(private val context: Context) {
persistObject(ArrayList<Map<String, Any>>())
}

open val storedQueue: ArrayList<Map<String, Any?>?>
/**
* Get the stored event queue from persistent storage.
*
* @return The stored queue of events.
*/
get() {
/**
* Get the stored event queue from persistent storage.
*
* @return The stored queue of events.
*/
open fun getStoredQueue(): ArrayList<Map<String, Any?>?> {
var storedQueue: ArrayList<Map<String, Any?>?>? = null
try {
val fis = context.applicationContext.openFileInput(STORAGE_KEY)
Expand All @@ -66,7 +65,7 @@ internal open class LocalStorageRepository(private val context: Context) {
* Delete an event from the stored queue.
*/
open fun expelStoredEvent() {
val storedQueue = storedQueue
val storedQueue = getStoredQueue()
storedQueue.removeAt(0)
}

Expand All @@ -76,7 +75,7 @@ internal open class LocalStorageRepository(private val context: Context) {
@Synchronized
open fun persistQueue(inMemoryQueue: List<Map<String, Any?>?>) {
ParselyTracker.PLog("Persisting event queue")
val storedQueue = storedQueue
val storedQueue = getStoredQueue()
val hs = HashSet<Map<String, Any?>?>()
hs.addAll(storedQueue)
hs.addAll(inMemoryQueue)
Expand All @@ -88,4 +87,4 @@ internal open class LocalStorageRepository(private val context: Context) {
companion object {
private const val STORAGE_KEY = "parsely-events.ser"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class LocalStorageRepositoryTest {
sut.expelStoredEvent()

// then
assertThat(sut.storedQueue).hasSize(100)
assertThat(sut.getStoredQueue()).hasSize(100)
}

@Test
Expand All @@ -41,12 +41,12 @@ class LocalStorageRepositoryTest {
sut.persistQueue(eventsList)

// then
assertThat(sut.storedQueue).hasSize(10).containsExactlyInAnyOrderElementsOf(eventsList)
assertThat(sut.getStoredQueue()).hasSize(10).containsExactlyInAnyOrderElementsOf(eventsList)
}

@Test
fun `given no locally stored list, when requesting stored queue, then return an empty list`() {
assertThat(sut.storedQueue).isEmpty()
assertThat(sut.getStoredQueue()).isEmpty()
}

@Test
Expand All @@ -61,7 +61,7 @@ class LocalStorageRepositoryTest {

// then
val expectedQueue = (1..10).map { mapOf("index" to it) }
assertThat(sut.storedQueue).hasSize(10).containsExactlyInAnyOrderElementsOf(expectedQueue)
assertThat(sut.getStoredQueue()).hasSize(10).containsExactlyInAnyOrderElementsOf(expectedQueue)
}

@Test
Expand All @@ -74,7 +74,7 @@ class LocalStorageRepositoryTest {
sut.purgeStoredQueue()

// then
assertThat(sut.storedQueue).isEmpty()
assertThat(sut.getStoredQueue()).isEmpty()
}

@Test
Expand All @@ -84,7 +84,7 @@ class LocalStorageRepositoryTest {
File(ClassLoader.getSystemResource("valid-java-parsely-events.ser")?.path!!).copyTo(file)

// when
val queue = sut.storedQueue
val queue = sut.getStoredQueue()

// then
assertThat(queue).isEqualTo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal class QueueManagerTest {

// then
assertThat(tracker.inMemoryQueue).isEqualTo(initialInMemoryQueue)
assertThat(repository.storedQueue).isEmpty()
assertThat(repository.getStoredQueue()).isEmpty()
}

@Test
Expand All @@ -51,7 +51,7 @@ internal class QueueManagerTest {
shadowMainLooper().idle();

// then
assertThat(repository.storedQueue).isEqualTo(initialInMemoryQueue)
assertThat(repository.getStoredQueue()).isEqualTo(initialInMemoryQueue)
assertThat(tracker.inMemoryQueue).hasSize(QUEUE_SIZE_LIMIT)
}

Expand Down Expand Up @@ -84,7 +84,7 @@ internal class QueueManagerTest {
}

override fun storedEventsCount(): Int {
return repository.storedQueue.size
return repository.getStoredQueue().size
}
}

Expand All @@ -98,9 +98,7 @@ internal class QueueManagerTest {
this.localFileQueue += inMemoryQueue
}

override val storedQueue: ArrayList<Map<String, Any?>?>
get() = ArrayList(localFileQueue)

override fun getStoredQueue() = ArrayList(localFileQueue)

override fun expelStoredEvent() {
wasEventExpelled = true
Expand Down

0 comments on commit 5822eb4

Please sign in to comment.