Skip to content

Commit

Permalink
fix JDK 8 and JDK 11 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
lion7 authored and gklijs committed Jun 15, 2024
1 parent 55ffddf commit 1acba0d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import kotlinx.serialization.cbor.Cbor
import org.axonframework.extensions.kotlin.serialization.KotlinSerializer
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import java.util.HexFormat

class KotlinSerializerCborTest {
@OptIn(ExperimentalSerializationApi::class)
private val sut = KotlinSerializer(Cbor)
private val format = HexFormat.of()

@Test
fun testStandardList() {
Expand All @@ -21,7 +19,7 @@ class KotlinSerializerCborTest {
val actual = sut.serialize(items, ByteArray::class.java)
val expected = "9fbf646e616d65616163666f6f01ffbf646e616d65616263666f6f02ffff"
assertEquals("List:org.axonframework.extensions.kotlin.serializer.TypeOne", actual.type.name)
assertEquals(expected, format.formatHex(actual.data))
assertEquals(expected, actual.data.toHex())
}

@Test
Expand All @@ -35,6 +33,6 @@ class KotlinSerializerCborTest {
val actual = sut.serialize(items, ByteArray::class.java)
val expected = "9f9f636f6e65bf646e616d65616163666f6f01ffff9f636f6e65bf646e616d65616263666f6f02ffff9f6374776fbf646e616d656163636261729f0304ffffff9f636f6e65bf646e616d65616463666f6f05ffffff"
assertEquals("List:org.axonframework.extensions.kotlin.serializer.SuperType", actual.type.name)
assertEquals(expected, format.formatHex(actual.data))
assertEquals(expected, actual.data.toHex())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import kotlinx.serialization.protobuf.ProtoBuf
import org.axonframework.extensions.kotlin.serialization.KotlinSerializer
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import java.util.HexFormat

class KotlinSerializerProtobufTest {
@OptIn(ExperimentalSerializationApi::class)
private val sut = KotlinSerializer(ProtoBuf)
private val format = HexFormat.of()

@Test
fun testStandardList() {
Expand All @@ -21,7 +19,7 @@ class KotlinSerializerProtobufTest {
val actual = sut.serialize(items, ByteArray::class.java)
val expected = "02050a01611001050a01621002"
assertEquals("List:org.axonframework.extensions.kotlin.serializer.TypeOne", actual.type.name)
assertEquals(expected, format.formatHex(actual.data))
assertEquals(expected, actual.data.toHex())
}

@Test
Expand All @@ -35,6 +33,6 @@ class KotlinSerializerProtobufTest {
val actual = sut.serialize(items, ByteArray::class.java)
val expected = "040c0a036f6e6512050a016110010c0a036f6e6512050a016210020e0a0374776f12070a0163100310040c0a036f6e6512050a01641005"
assertEquals("List:org.axonframework.extensions.kotlin.serializer.SuperType", actual.type.name)
assertEquals(expected, format.formatHex(actual.data))
assertEquals(expected, actual.data.toHex())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.axonframework.extensions.kotlin.serializer

// copied from https://www.baeldung.com/kotlin/byte-arrays-to-hex-strings#1-formatter
fun ByteArray.toHex(): String =
joinToString("") { eachByte -> "%02x".format(eachByte) }

0 comments on commit 1acba0d

Please sign in to comment.