diff --git a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/adapter/SupportedProtocolSetAdapter.kt b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/adapter/SupportedProtocolSetAdapter.kt index afeaf818de2..2bf23ac7f05 100644 --- a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/adapter/SupportedProtocolSetAdapter.kt +++ b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/adapter/SupportedProtocolSetAdapter.kt @@ -22,7 +22,11 @@ import com.wire.kalium.persistence.dao.SupportedProtocolEntity internal object SupportedProtocolSetAdapter : ColumnAdapter, String> { override fun decode(databaseValue: String): Set { - return databaseValue.split(SEPARATOR).map { SupportedProtocolEntity.valueOf(it) }.toSet() + return if (databaseValue.isBlank()) { + emptySet() + } else { + databaseValue.split(SEPARATOR).map { SupportedProtocolEntity.valueOf(it) }.toSet() + } } override fun encode(value: Set): String { diff --git a/persistence/src/commonTest/kotlin/com/wire/kalium/persistence/adapter/SupportedProtocolSetAdapterTest.kt b/persistence/src/commonTest/kotlin/com/wire/kalium/persistence/adapter/SupportedProtocolSetAdapterTest.kt new file mode 100644 index 00000000000..3a1f12b0822 --- /dev/null +++ b/persistence/src/commonTest/kotlin/com/wire/kalium/persistence/adapter/SupportedProtocolSetAdapterTest.kt @@ -0,0 +1,64 @@ +/* + * Wire + * Copyright (C) 2023 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.persistence.adapter + +import com.wire.kalium.persistence.dao.SupportedProtocolEntity +import kotlin.test.Test +import kotlin.test.assertContains +import kotlin.test.assertEquals +import kotlin.test.assertTrue + +class SupportedProtocolSetAdapterTest { + + private val adapter = SupportedProtocolSetAdapter + + @Test + fun givenEmptySet_whenEncodingAndDecoding_thenShouldReturnEmptySet() { + val encoded = adapter.encode(emptySet()) + val decoded = adapter.decode(encoded) + + assertTrue(decoded.isEmpty()) + } + + @Test + fun givenEmptyString_whenDecodingAndEncoding_thenShouldReturnEmptyString() { + val decoded = adapter.decode("") + val encoded = adapter.encode(decoded) + + assertTrue(encoded.isEmpty()) + } + + @Test + fun givenProteus_whenEncodingAndDecoding_thenShouldReturnProteus() { + val encoded = adapter.encode(setOf(SupportedProtocolEntity.PROTEUS)) + val decoded = adapter.decode(encoded) + + assertEquals(1, decoded.size) + assertContains(decoded, SupportedProtocolEntity.PROTEUS) + } + + @Test + fun givenMLSAndProteus_whenEncodingAndDecoding_thenShouldReturnMLSAndProteus() { + val encoded = adapter.encode(setOf(SupportedProtocolEntity.MLS, SupportedProtocolEntity.PROTEUS)) + val decoded = adapter.decode(encoded) + + assertEquals(2, decoded.size) + assertContains(decoded, SupportedProtocolEntity.MLS) + assertContains(decoded, SupportedProtocolEntity.PROTEUS) + } +}