Skip to content

Commit

Permalink
Added test for string decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
sksamuel committed Apr 29, 2024
1 parent ee2756d commit 580386d
Showing 1 changed file with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.sksamuel.centurion.avro.decoders

import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import org.apache.avro.SchemaBuilder
import org.apache.avro.generic.GenericData
import org.apache.avro.util.Utf8
import java.nio.ByteBuffer

class StringDecoderTest : FunSpec({

test("decode java strings") {
val schema = SchemaBuilder.builder().stringType()
StringDecoder.decode(schema).invoke("foo") shouldBe "foo"
}

test("decode UTF8") {
val schema = SchemaBuilder.builder().stringType()
StringDecoder.decode(schema).invoke(Utf8("foo")) shouldBe "foo"
}

test("decode byte buffer") {
val schema = SchemaBuilder.builder().stringType()
StringDecoder.decode(schema).invoke(ByteBuffer.wrap("foo".encodeToByteArray())) shouldBe "foo"
}

test("decode byte array") {
val schema = SchemaBuilder.builder().bytesType()
StringDecoder.decode(schema).invoke("foo".encodeToByteArray()) shouldBe "foo"
}

test("decode fixed") {
val schema = SchemaBuilder.fixed("name").size(3)
StringDecoder.decode(schema)
.invoke(GenericData.get().createFixed(null, "foo".encodeToByteArray(), schema)) shouldBe "foo"
}

})

0 comments on commit 580386d

Please sign in to comment.