Skip to content

Commit

Permalink
add a test for Records with Option fields with defaults other than …
Browse files Browse the repository at this point in the history
…`None`
  • Loading branch information
mberndt123 committed Apr 19, 2024
1 parent 2beb8cb commit aa6714a
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.sksamuel.avro4s.record.decoder

import com.sksamuel.avro4s.{AvroSchema, Decoder, ImmutableRecord}
import com.sksamuel.avro4s.AvroSchema
import com.sksamuel.avro4s.Decoder
import com.sksamuel.avro4s.Encoder
import com.sksamuel.avro4s.ImmutableRecord
import org.apache.avro.Schema
import org.apache.avro.generic.GenericData
import org.apache.avro.util.Utf8
Expand Down Expand Up @@ -169,6 +172,17 @@ class OptionDecoderTest extends AnyWordSpec with Matchers {
Decoder[OptionDibble].decode(schema)(dabbleRecord) shouldBe OptionDibble(Some(Dabble))
Decoder[OptionDibble].decode(schema)(noneRecord) shouldBe OptionDibble(None)
}

"Option with non-None default" in {
case class Foo(
bar: Option[Int] = Some(42)
)
val schema = AvroSchema[Foo]
for (foo <- Seq(Foo(), Foo(Some(17)), Foo(None))) {
val encoded = Encoder[Foo].encode(schema).apply(foo)
val decoded = Decoder[Foo].decode(schema).apply(encoded)
decoded shouldBe foo
}
}
}
}

0 comments on commit aa6714a

Please sign in to comment.