From bba30d902b0abcef09b06e6393cfa6386adff506 Mon Sep 17 00:00:00 2001 From: Martin Kuhn Date: Fri, 18 Aug 2023 21:09:03 +0200 Subject: [PATCH 1/2] test: add failing test for multiple uses of generic types --- .../schema/MultipleGenericsSchemaTest.kt | 26 +++++++++++++++++++ src/test/resources/multiple_generics.json | 26 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 src/test/kotlin/com/github/avrokotlin/avro4k/schema/MultipleGenericsSchemaTest.kt create mode 100644 src/test/resources/multiple_generics.json diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/MultipleGenericsSchemaTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/MultipleGenericsSchemaTest.kt new file mode 100644 index 00000000..d591465f --- /dev/null +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/MultipleGenericsSchemaTest.kt @@ -0,0 +1,26 @@ +package com.github.avrokotlin.avro4k.schema + +import com.github.avrokotlin.avro4k.Avro +import com.github.avrokotlin.avro4k.AvroName +import io.kotest.matchers.shouldBe +import io.kotest.core.spec.style.FunSpec +import kotlinx.serialization.Serializable + +class MultipleGenericsSchemaTest : FunSpec({ + + test("encode different generics") { + + val schema = Avro.default.schema(WrapperTest.serializer()) + val expected = org.apache.avro.Schema.Parser().parse(javaClass.getResourceAsStream("/multiple_generics.json")) + schema.toString(true) shouldBe expected.toString(true) + } + + +}) { + @Serializable + data class GenericValue(val z: T) + + @Serializable + @AvroName("WrapperTest") + data class WrapperTest(val a: GenericValue, val b: GenericValue) +} diff --git a/src/test/resources/multiple_generics.json b/src/test/resources/multiple_generics.json new file mode 100644 index 00000000..742ea55a --- /dev/null +++ b/src/test/resources/multiple_generics.json @@ -0,0 +1,26 @@ +{ + "type" : "record", + "name" : "WrapperTest", + "namespace" : "com.github.avrokotlin.avro4k.schema.MultipleGenericsSchemaTest", + "fields" : [ { + "name" : "a", + "type" : { + "type" : "record", + "name" : "GenericValue", + "fields" : [ { + "name" : "z", + "type" : "string" + } ] + } + }, { + "name" : "b", + "type" : { + "type" : "record", + "name" : "GenericValue", + "fields" : [ { + "name" : "z", + "type" : "string" + } ] + } + } ] +} \ No newline at end of file From 579b7d8c9ea4ffce499f2a69e4f7f712c083f2a1 Mon Sep 17 00:00:00 2001 From: Martin Kuhn Date: Fri, 18 Aug 2023 21:12:24 +0200 Subject: [PATCH 2/2] test: fix expectation --- src/test/resources/multiple_generics.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/resources/multiple_generics.json b/src/test/resources/multiple_generics.json index 742ea55a..004bf141 100644 --- a/src/test/resources/multiple_generics.json +++ b/src/test/resources/multiple_generics.json @@ -19,7 +19,7 @@ "name" : "GenericValue", "fields" : [ { "name" : "z", - "type" : "string" + "type" : "double" } ] } } ]