forked from github/wulkanowy-mirror
Fix string pair list type converter (#971)
This commit is contained in:
parent
11487e77ca
commit
1f0f6b3e51
@ -127,7 +127,7 @@ configurations.all {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "io.github.wulkanowy:sdk:0.21.1"
|
||||
implementation "io.github.wulkanowy:sdk:7577fc9"
|
||||
|
||||
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.10'
|
||||
|
||||
|
@ -56,11 +56,11 @@ object PairAdapterFactory : JsonAdapter.Factory {
|
||||
private fun deserializeGsonPair(reader: JsonReader): List<Pair<String, String>>? {
|
||||
val list = listAdapter.fromJson(reader) ?: return null
|
||||
|
||||
require(list.size == 2 || list.isEmpty()) {
|
||||
"pair with more or less than two elements: $list"
|
||||
}
|
||||
|
||||
return list.map {
|
||||
require(it.size == 2) {
|
||||
"pair with more or less than two elements: $list"
|
||||
}
|
||||
|
||||
it["first"].orEmpty() to it["second"].orEmpty()
|
||||
}
|
||||
}
|
||||
|
@ -7,19 +7,24 @@ class ConvertersTest {
|
||||
|
||||
@Test
|
||||
fun stringPairListToJson() {
|
||||
assertEquals(Converters().stringPairListToJson(listOf("aaa" to "bbb", "ccc" to "ddd", "eee" to "fff")), "[{\"first\":\"aaa\",\"second\":\"bbb\"},{\"first\":\"ccc\",\"second\":\"ddd\"},{\"first\":\"eee\",\"second\":\"fff\"}]")
|
||||
assertEquals(Converters().stringPairListToJson(listOf("aaa" to "bbb", "ccc" to "ddd")), "[{\"first\":\"aaa\",\"second\":\"bbb\"},{\"first\":\"ccc\",\"second\":\"ddd\"}]")
|
||||
assertEquals(Converters().stringPairListToJson(listOf("aaa" to "bbb")), "[{\"first\":\"aaa\",\"second\":\"bbb\"}]")
|
||||
assertEquals(Converters().stringPairListToJson(listOf()), "[]")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun jsonToStringPairList() {
|
||||
assertEquals(Converters().jsonToStringPairList("[{\"first\":\"aaa\",\"second\":\"bbb\"},{\"first\":\"ccc\",\"second\":\"ddd\"},{\"first\":\"eee\",\"second\":\"fff\"}]"), listOf("aaa" to "bbb", "ccc" to "ddd", "eee" to "fff"))
|
||||
assertEquals(Converters().jsonToStringPairList("[{\"first\":\"aaa\",\"second\":\"bbb\"},{\"first\":\"ccc\",\"second\":\"ddd\"}]"), listOf("aaa" to "bbb", "ccc" to "ddd"))
|
||||
assertEquals(Converters().jsonToStringPairList("[{\"first\":\"aaa\",\"second\":\"bbb\"}]"), listOf("aaa" to "bbb"))
|
||||
assertEquals(Converters().jsonToStringPairList("[]"), listOf<Pair<String, String>>())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun jsonToStringPairList_0210() {
|
||||
assertEquals(Converters().jsonToStringPairList("{\"aaa\":\"bbb\",\"ccc\":\"ddd\"}"), listOf("aaa" to "bbb", "ccc" to "ddd"))
|
||||
assertEquals(Converters().jsonToStringPairList("{\"aaa\":\"bbb\"}"), listOf("aaa" to "bbb"))
|
||||
assertEquals(Converters().jsonToStringPairList("{}"), listOf<Pair<String, String>>())
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user