Introduce JsonProvider.
It will ensure that classes are using the correct Json instances in the unit tests.
This commit is contained in:
parent
fa8ddba1f5
commit
df48ed5a2d
21 changed files with 103 additions and 52 deletions
|
|
@ -39,6 +39,7 @@ data class PushDataUnifiedPushNotification(
|
|||
@SerialName("event_id") val eventId: String? = null,
|
||||
@SerialName("room_id") val roomId: String? = null,
|
||||
@SerialName("counts") val counts: PushDataUnifiedPushCounts? = null,
|
||||
@SerialName("prio") val prio: String? = null,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
|
|
|
|||
|
|
@ -8,15 +8,15 @@
|
|||
package io.element.android.libraries.pushproviders.unifiedpush
|
||||
|
||||
import dev.zacsweers.metro.Inject
|
||||
import io.element.android.libraries.androidutils.json.JsonProvider
|
||||
import io.element.android.libraries.core.data.tryOrNull
|
||||
import io.element.android.libraries.pushproviders.api.PushData
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
@Inject
|
||||
class UnifiedPushParser(
|
||||
private val json: Json,
|
||||
private val json: JsonProvider,
|
||||
) {
|
||||
fun parse(message: ByteArray, clientSecret: String): PushData? {
|
||||
return tryOrNull { json.decodeFromString<PushDataUnifiedPush>(String(message)) }?.toPushData(clientSecret)
|
||||
return tryOrNull { json().decodeFromString<PushDataUnifiedPush>(String(message)) }?.toPushData(clientSecret)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,11 +8,11 @@
|
|||
package io.element.android.libraries.pushproviders.unifiedpush
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import io.element.android.libraries.androidutils.json.DefaultJsonProvider
|
||||
import io.element.android.libraries.matrix.test.AN_EVENT_ID
|
||||
import io.element.android.libraries.matrix.test.A_ROOM_ID
|
||||
import io.element.android.libraries.pushproviders.api.PushData
|
||||
import io.element.android.tests.testutils.assertThrowsInDebug
|
||||
import kotlinx.serialization.json.Json
|
||||
import org.junit.Test
|
||||
|
||||
class UnifiedPushParserTest {
|
||||
|
|
@ -83,8 +83,6 @@ private fun String.mutate(oldValue: String, newValue: String): ByteArray {
|
|||
return replace(oldValue, newValue).toByteArray()
|
||||
}
|
||||
|
||||
fun createUnifiedPushParser(
|
||||
json: Json = Json { ignoreUnknownKeys = true },
|
||||
) = UnifiedPushParser(
|
||||
json = json,
|
||||
fun createUnifiedPushParser() = UnifiedPushParser(
|
||||
json = DefaultJsonProvider(),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue