diff --git a/tests/shared/src/test/scala-2/zio/schema/SchemaGen.scala b/tests/shared/src/test/scala-2/zio/schema/SchemaGen.scala index fe97a5a0a..46405ce2c 100644 --- a/tests/shared/src/test/scala-2/zio/schema/SchemaGen.scala +++ b/tests/shared/src/test/scala-2/zio/schema/SchemaGen.scala @@ -1,6 +1,7 @@ package zio.schema import scala.collection.immutable.ListMap + import zio.Chunk import zio.schema.PlatformSpecificGen.platformSpecificSchemasAndGens import zio.test.{ Gen, Sized } diff --git a/tests/shared/src/test/scala-2/zio/schema/StandardTypeGen.scala b/tests/shared/src/test/scala-2/zio/schema/StandardTypeGen.scala index e6ce58575..98a5570be 100644 --- a/tests/shared/src/test/scala-2/zio/schema/StandardTypeGen.scala +++ b/tests/shared/src/test/scala-2/zio/schema/StandardTypeGen.scala @@ -1,10 +1,10 @@ package zio.schema +import java.math.{ BigDecimal => JBigDecimal, BigInteger => JBigInt } + import zio.schema.PlatformSpecificGen.{ platformSpecificStandardTypeAndGen, platformSpecificStandardTypes } import zio.test.{ Gen, Sized } -import java.math.{ BigDecimal => JBigDecimal, BigInteger => JBigInt } - object StandardTypeGen { //IMPORTANT! - Updating the following list without updating the schema primitive case set in zio.schema.DynamicValue.schema will trigger a set of very obscure test failures @@ -36,9 +36,8 @@ object StandardTypeGen { StandardType.YearType, StandardType.YearMonthType, StandardType.ZonedDateTimeType, - StandardType.ZoneIdType - //FIXME For some reason adding this causes other unrelated tests to break. -// StandardType.ZoneOffsetType + StandardType.ZoneIdType, + StandardType.ZoneOffsetType ) ) ++ platformSpecificStandardTypes diff --git a/zio-schema-avro/src/main/scala/zio/schema/codec/AvroCodec.scala b/zio-schema-avro/src/main/scala/zio/schema/codec/AvroCodec.scala index 521147e74..e1bca4ff5 100644 --- a/zio-schema-avro/src/main/scala/zio/schema/codec/AvroCodec.scala +++ b/zio-schema-avro/src/main/scala/zio/schema/codec/AvroCodec.scala @@ -937,7 +937,7 @@ object AvroCodec { val zonedDateTime = a.asInstanceOf[java.time.ZonedDateTime] zonedDateTime.toString case StandardType.CurrencyType => - a.asInstanceOf[java.util.Currency].getCurrencyCode() + a.asInstanceOf[java.util.Currency].getCurrencyCode } private def encodeSequence[A](schema: Schema[A], v: Chunk[A]): Any = { diff --git a/zio-schema-json/js/src/test/scala-2/zio/schema/codec/JsonPlatformSpecific.scala b/zio-schema-json/js/src/test/scala-2/zio/schema/codec/JsonPlatformSpecific.scala index 6b28decda..6916c349f 100644 --- a/zio-schema-json/js/src/test/scala-2/zio/schema/codec/JsonPlatformSpecific.scala +++ b/zio-schema-json/js/src/test/scala-2/zio/schema/codec/JsonPlatformSpecific.scala @@ -1,6 +1,12 @@ package zio.schema.codec object JsonPlatformSpecific { + @SuppressWarnings(Array( + "scalafix:ExplicitResultTypes" + )) val platformSpecificEncoderTests = Seq.empty + @SuppressWarnings(Array( + "scalafix:ExplicitResultTypes" + )) val platformSpecificDecoderTests = Seq.empty } diff --git a/zio-schema-json/jvm/src/test/scala-2/zio/schema/codec/JsonPlatformSpecific.scala b/zio-schema-json/jvm/src/test/scala-2/zio/schema/codec/JsonPlatformSpecific.scala index dc02d2381..6784395f0 100644 --- a/zio-schema-json/jvm/src/test/scala-2/zio/schema/codec/JsonPlatformSpecific.scala +++ b/zio-schema-json/jvm/src/test/scala-2/zio/schema/codec/JsonPlatformSpecific.scala @@ -1,11 +1,14 @@ package zio.schema.codec -import zio.schema.{ Schema, StandardType } import zio.schema.codec.JsonCodecSpec.{ assertDecodes, assertEncodesJson, stringify, test } +import zio.schema.{ Schema, StandardType } import zio.test.{ Gen, check } object JsonPlatformSpecific { + @SuppressWarnings(Array( + "scalafix:ExplicitResultTypes" + )) val platformSpecificEncoderTests = Seq( test("Currency") { assertEncodesJson( @@ -15,10 +18,13 @@ object JsonPlatformSpecific { } ) + @SuppressWarnings(Array( + "scalafix:ExplicitResultTypes" + )) val platformSpecificDecoderTests = Seq( test("Currency") { check(Gen.currency)( - currency => assertDecodes(Schema[java.util.Currency], currency, stringify(currency.getCurrencyCode())) + currency => assertDecodes(Schema[java.util.Currency], currency, stringify(currency.getCurrencyCode)) ) } ) diff --git a/zio-schema-json/native/src/test/scala-2/zio/schema/codec/JsonPlatformSpecific.scala b/zio-schema-json/native/src/test/scala-2/zio/schema/codec/JsonPlatformSpecific.scala index 6b28decda..6916c349f 100644 --- a/zio-schema-json/native/src/test/scala-2/zio/schema/codec/JsonPlatformSpecific.scala +++ b/zio-schema-json/native/src/test/scala-2/zio/schema/codec/JsonPlatformSpecific.scala @@ -1,6 +1,12 @@ package zio.schema.codec object JsonPlatformSpecific { + @SuppressWarnings(Array( + "scalafix:ExplicitResultTypes" + )) val platformSpecificEncoderTests = Seq.empty + @SuppressWarnings(Array( + "scalafix:ExplicitResultTypes" + )) val platformSpecificDecoderTests = Seq.empty } diff --git a/zio-schema-json/shared/src/test/scala-2/zio/schema/codec/JsonCodecSpec.scala b/zio-schema-json/shared/src/test/scala-2/zio/schema/codec/JsonCodecSpec.scala index ef8e956d0..6a4570c8c 100644 --- a/zio-schema-json/shared/src/test/scala-2/zio/schema/codec/JsonCodecSpec.scala +++ b/zio-schema-json/shared/src/test/scala-2/zio/schema/codec/JsonCodecSpec.scala @@ -1,15 +1,17 @@ package zio.schema.codec import java.time.{ ZoneId, ZoneOffset } + import scala.collection.immutable.ListMap + import zio.Console._ -import zio._ import zio.json.JsonDecoder.JsonError import zio.json.ast.Json import zio.json.{ DeriveJsonEncoder, JsonEncoder } import zio.schema.CaseSet._ import zio.schema._ import zio.schema.annotation._ +import zio.schema.codec.DecodeError import zio.schema.codec.DecodeError.ReadError import zio.schema.codec.JsonCodec.JsonEncoder.charSequenceToByteChunk import zio.schema.codec.JsonCodecSpec.PaymentMethod.{ CreditCard, PayPal, WireTransfer } @@ -19,7 +21,8 @@ import zio.schema.meta.MetaSchema import zio.stream.ZStream import zio.test.Assertion._ import zio.test.TestAspect._ -import zio.test._ +import zio.test.{ TestResult, _ } +import zio.{ ZIO, _ } object JsonCodecSpec extends ZIOSpecDefault { @@ -1413,7 +1416,7 @@ object JsonCodecSpec extends ZIOSpecDefault { assertZIO(stream)(equalTo(json)) } - def assertEncodesJson[A](schema: Schema[A], value: A)(implicit enc: JsonEncoder[A]) = { + def assertEncodesJson[A](schema: Schema[A], value: A)(implicit enc: JsonEncoder[A]): ZIO[Any, Nothing, TestResult] = { val stream = ZStream .succeed(value) .via(JsonCodec.schemaBasedBinaryCodec[A](schema).streamEncoder) @@ -1440,7 +1443,7 @@ object JsonCodecSpec extends ZIOSpecDefault { value: A, chunk: Chunk[Byte], cfg: JsonCodec.Config = JsonCodec.Config.default - ) = { + ): ZIO[Any, DecodeError, TestResult] = { val result = ZStream.fromChunk(chunk).via(JsonCodec.schemaBasedBinaryCodec[A](cfg)(schema).streamDecoder).runCollect assertZIO(result)(equalTo(Chunk(value))) } diff --git a/zio-schema-msg-pack/src/main/scala/zio/schema/codec/MessagePackEncoder.scala b/zio-schema-msg-pack/src/main/scala/zio/schema/codec/MessagePackEncoder.scala index 1b8bf151c..7c5e5ea64 100644 --- a/zio-schema-msg-pack/src/main/scala/zio/schema/codec/MessagePackEncoder.scala +++ b/zio-schema-msg-pack/src/main/scala/zio/schema/codec/MessagePackEncoder.scala @@ -261,7 +261,7 @@ private[codec] class MessagePackEncoder { packer.packString(v.toString) () case (StandardType.CurrencyType, v: java.util.Currency) => - packer.packString(v.getCurrencyCode()) + packer.packString(v.getCurrencyCode) () case (_, _) => throw new NotImplementedError(s"No encoder for $standardType") diff --git a/zio-schema-protobuf/js/src/test/scala-2/zio/schema/codec/ProtobufPlatformSpecific.scala b/zio-schema-protobuf/js/src/test/scala-2/zio/schema/codec/ProtobufPlatformSpecific.scala index b62c868f0..f8499fde2 100644 --- a/zio-schema-protobuf/js/src/test/scala-2/zio/schema/codec/ProtobufPlatformSpecific.scala +++ b/zio-schema-protobuf/js/src/test/scala-2/zio/schema/codec/ProtobufPlatformSpecific.scala @@ -1,5 +1,8 @@ package zio.schema.codec object ProtobufPlatformSpecific { + @SuppressWarnings(Array( + "scalafix:ExplicitResultTypes" + )) val platformSpecificEncodeAndDecode = Seq.empty } diff --git a/zio-schema-protobuf/jvm/src/test/scala-2/zio/schema/codec/ProtobufPlatformSpecific.scala b/zio-schema-protobuf/jvm/src/test/scala-2/zio/schema/codec/ProtobufPlatformSpecific.scala index f5823274a..3c6f15c1e 100644 --- a/zio-schema-protobuf/jvm/src/test/scala-2/zio/schema/codec/ProtobufPlatformSpecific.scala +++ b/zio-schema-protobuf/jvm/src/test/scala-2/zio/schema/codec/ProtobufPlatformSpecific.scala @@ -8,6 +8,9 @@ import zio.test.{ Gen, assert, check } object ProtobufPlatformSpecific { + @SuppressWarnings(Array( + "scalafix:ExplicitResultTypes" + )) val platformSpecificEncodeAndDecode = Seq( test("currencies") { check(Gen.currency) { value => diff --git a/zio-schema-protobuf/native/src/test/scala-2/zio/schema/codec/ProtobufPlatformSpecific.scala b/zio-schema-protobuf/native/src/test/scala-2/zio/schema/codec/ProtobufPlatformSpecific.scala index b62c868f0..f8499fde2 100644 --- a/zio-schema-protobuf/native/src/test/scala-2/zio/schema/codec/ProtobufPlatformSpecific.scala +++ b/zio-schema-protobuf/native/src/test/scala-2/zio/schema/codec/ProtobufPlatformSpecific.scala @@ -1,5 +1,8 @@ package zio.schema.codec object ProtobufPlatformSpecific { + @SuppressWarnings(Array( + "scalafix:ExplicitResultTypes" + )) val platformSpecificEncodeAndDecode = Seq.empty } diff --git a/zio-schema-protobuf/shared/src/main/scala/zio/schema/codec/ProtobufCodec.scala b/zio-schema-protobuf/shared/src/main/scala/zio/schema/codec/ProtobufCodec.scala index cc8ff2c84..77a87e90f 100644 --- a/zio-schema-protobuf/shared/src/main/scala/zio/schema/codec/ProtobufCodec.scala +++ b/zio-schema-protobuf/shared/src/main/scala/zio/schema/codec/ProtobufCodec.scala @@ -426,7 +426,7 @@ object ProtobufCodec { case (StandardType.ZonedDateTimeType, v: ZonedDateTime) => encodePrimitive(fieldNumber, StandardType.StringType, v.format(DateTimeFormatter.ISO_ZONED_DATE_TIME)) case (StandardType.CurrencyType, v: java.util.Currency) => - encodePrimitive(fieldNumber, StandardType.StringType, v.getCurrencyCode()) + encodePrimitive(fieldNumber, StandardType.StringType, v.getCurrencyCode) case (_, _) => throw new NotImplementedError(s"No encoder for $standardType") } diff --git a/zio-schema-protobuf/shared/src/test/scala-2/zio/schema/codec/ProtobufCodecSpec.scala b/zio-schema-protobuf/shared/src/test/scala-2/zio/schema/codec/ProtobufCodecSpec.scala index 454c0b6b3..1132a5b21 100644 --- a/zio-schema-protobuf/shared/src/test/scala-2/zio/schema/codec/ProtobufCodecSpec.scala +++ b/zio-schema-protobuf/shared/src/test/scala-2/zio/schema/codec/ProtobufCodecSpec.scala @@ -2,8 +2,10 @@ package zio.schema.codec import java.time._ import java.util.UUID + import scala.collection.immutable.ListMap import scala.util.Try + import zio.Console._ import zio._ import zio.schema.CaseSet._ diff --git a/zio-schema-thrift/src/main/scala/zio/schema/codec/ThriftCodec.scala b/zio-schema-thrift/src/main/scala/zio/schema/codec/ThriftCodec.scala index 2b7f47d71..bfc928d58 100644 --- a/zio-schema-thrift/src/main/scala/zio/schema/codec/ThriftCodec.scala +++ b/zio-schema-thrift/src/main/scala/zio/schema/codec/ThriftCodec.scala @@ -372,7 +372,7 @@ object ThriftCodec { case (StandardType.ZonedDateTimeType, v: ZonedDateTime) => p.writeString(v.toString) case (StandardType.CurrencyType, v: java.util.Currency) => - p.writeString(v.getCurrencyCode()) + p.writeString(v.getCurrencyCode) case (_, _) => fail(s"No encoder for $standardType") } diff --git a/zio-schema/js/src/main/scala/zio/schema/StandardType.scala b/zio-schema/js/src/main/scala/zio/schema/StandardType.scala index 4f6f60940..152609bdf 100644 --- a/zio-schema/js/src/main/scala/zio/schema/StandardType.scala +++ b/zio-schema/js/src/main/scala/zio/schema/StandardType.scala @@ -169,7 +169,7 @@ object StandardType { override def tag: String = Tags.CURRENCY override def defaultValue: Either[String, java.util.Currency] = Left("Currency generation not available in ScalaJS") override def compare(x: java.util.Currency, y: java.util.Currency): Int = - x.getCurrencyCode().compareTo(y.getCurrencyCode()) + x.getCurrencyCode.compareTo(y.getCurrencyCode) } implicit object BigDecimalType extends StandardType[java.math.BigDecimal] { diff --git a/zio-schema/jvm/src/main/scala/zio/schema/StandardType.scala b/zio-schema/jvm/src/main/scala/zio/schema/StandardType.scala index 7c15afb5b..933413d94 100644 --- a/zio-schema/jvm/src/main/scala/zio/schema/StandardType.scala +++ b/zio-schema/jvm/src/main/scala/zio/schema/StandardType.scala @@ -167,10 +167,17 @@ object StandardType { implicit object CurrencyType extends StandardType[java.util.Currency] { override def tag: String = Tags.CURRENCY - override def defaultValue: Either[String, java.util.Currency] = - Right(java.util.Currency.getInstance(java.util.Locale.getDefault())) + override def defaultValue: Either[String, java.util.Currency] = { + try { + Right(java.util.Currency.getInstance(java.util.Locale.getDefault())) + } catch { + case _: NullPointerException => throw new Exception("Could not get default currency. Default locale was null.") + case ex => throw new Exception(s"Could not get default currency. ${ex.getMessage}") + } + } + override def compare(x: java.util.Currency, y: java.util.Currency): Int = - x.getCurrencyCode.compareTo(y.getCurrencyCode()) + x.getCurrencyCode.compareTo(y.getCurrencyCode) } implicit object BigDecimalType extends StandardType[java.math.BigDecimal] { diff --git a/zio-schema/native/src/main/scala/zio/schema/StandardType.scala b/zio-schema/native/src/main/scala/zio/schema/StandardType.scala index 8d375b862..15dfe639f 100644 --- a/zio-schema/native/src/main/scala/zio/schema/StandardType.scala +++ b/zio-schema/native/src/main/scala/zio/schema/StandardType.scala @@ -173,7 +173,7 @@ object StandardType { Left("Currency generation not available in Scala Native") override def compare(x: java.util.Currency, y: java.util.Currency): Int = - x.getCurrencyCode().compareTo(y.getCurrencyCode()) + x.getCurrencyCode.compareTo(y.getCurrencyCode) } implicit object BigDecimalType extends StandardType[java.math.BigDecimal] {