diff --git a/app/src/main/java/se/ajpanton/notificationlog/settings/LoggingRuleStore.kt b/app/src/main/java/se/ajpanton/notificationlog/settings/LoggingRuleStore.kt index f23841e..e616791 100644 --- a/app/src/main/java/se/ajpanton/notificationlog/settings/LoggingRuleStore.kt +++ b/app/src/main/java/se/ajpanton/notificationlog/settings/LoggingRuleStore.kt @@ -27,7 +27,7 @@ class LoggingRuleStore(context: Context) { } fun copy(from: LoggingType, targets: Set) { - val source = ruleFor(from) + val source = ruleFor(from).copyForTarget() preferences.edit { targets.filterNot { it == from }.forEach { target -> write(target, source.copy(selectedPackages = source.selectedPackages.toSet())) @@ -50,3 +50,5 @@ class LoggingRuleStore(context: Context) { const val FILE_NAME = "logging-rules" } } + +internal fun LoggingRule.copyForTarget(): LoggingRule = copy(selectedPackages = selectedPackages.toSet()) diff --git a/app/src/test/java/se/ajpanton/notificationlog/settings/LoggingRuleCopyTest.kt b/app/src/test/java/se/ajpanton/notificationlog/settings/LoggingRuleCopyTest.kt new file mode 100644 index 0000000..b27d6d7 --- /dev/null +++ b/app/src/test/java/se/ajpanton/notificationlog/settings/LoggingRuleCopyTest.kt @@ -0,0 +1,15 @@ +package se.ajpanton.notificationlog.settings + +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNotSame +import org.junit.Test + +class LoggingRuleCopyTest { + @Test fun `copy retains every rule field and owns its selected-package set`() { + val source = LoggingRule(false, AppRuleMode.WHITELIST, setOf("example.app"), true, false, false) + val target = source.copyForTarget() + + assertEquals(source, target) + assertNotSame(source.selectedPackages, target.selectedPackages) + } +}