Skip to content

Commit

Permalink
Fixed a issue with strings not getting cleared in the LocalizedResour…
Browse files Browse the repository at this point in the history
…cesPersistentMap
  • Loading branch information
B3nedikt committed Jun 29, 2024
1 parent 4f99cd9 commit 774fc07
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.b3nedikt.restring.internal.repository.persistent

import java.util.*
import java.util.Locale

/**
* A [PersistentMap] which used [Locale]s as key and maps of resource name, resource value pairs
Expand Down Expand Up @@ -43,6 +43,7 @@ internal class LocalizedResourcesPersistentMap<V>(

override fun delete(key: Locale) {
locales.remove(key)
delegateMaps[key]?.clear()
delegateMaps.remove(key)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package dev.b3nedikt.restring.repository

import dev.b3nedikt.restring.MutableStringRepository
import dev.b3nedikt.restring.internal.repository.observable.observableMap
import java.util.*
import java.util.Locale
import kotlin.properties.ReadWriteProperty

/**
Expand Down
16 changes: 15 additions & 1 deletion restring/src/test/java/dev/b3nedikt/restring/RestringTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import dev.b3nedikt.restring.activity.TestActivity
import dev.b3nedikt.restring.internal.DefaultLocaleProvider
import dev.b3nedikt.reword.RewordInterceptor
import dev.b3nedikt.viewpump.ViewPump
import org.amshove.kluent.shouldContainSame
import org.amshove.kluent.shouldStartWith
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.Robolectric
import org.robolectric.RobolectricTestRunner
import java.util.*
import java.util.Locale

@RunWith(RobolectricTestRunner::class)
class RestringTest {
Expand Down Expand Up @@ -82,6 +83,19 @@ class RestringTest {
activityController.pause().stop().destroy()
}

@Test
fun removingALocalShouldDeleteAllOfItsStrings() {

val strings = mapOf("key1" to "value1", "key2" to "value2")
val strings2 = mapOf("key3" to "value3", "key4" to "value4")

Restring.stringRepository.toMutableRepository().strings[Locale.ENGLISH]?.putAll(strings)
Restring.stringRepository.toMutableRepository().strings.remove(Locale.ENGLISH)
Restring.stringRepository.toMutableRepository().strings[Locale.ENGLISH]?.putAll(strings2)

Restring.stringRepository.toMutableRepository().strings[Locale.ENGLISH]!! shouldContainSame strings2
}

private fun getStrings(locale: Locale) = mapOf(
"header" to locale.language + "_" + "header",
"header_hint" to locale.language + "_" + "hint",
Expand Down

0 comments on commit 774fc07

Please sign in to comment.