Skip to content

Commit

Permalink
fix: failure to parse lack of supported protocols (#2167)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorhugods authored Oct 24, 2023
1 parent b6cfb79 commit 50fa995
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ import com.wire.kalium.persistence.dao.SupportedProtocolEntity

internal object SupportedProtocolSetAdapter : ColumnAdapter<Set<SupportedProtocolEntity>, String> {
override fun decode(databaseValue: String): Set<SupportedProtocolEntity> {
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<SupportedProtocolEntity>): String {
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 50fa995

Please sign in to comment.