diff --git a/plugin/src/main/scala/com/github/sbt/avro/SbtAvro.scala b/plugin/src/main/scala/com/github/sbt/avro/SbtAvro.scala index 5d922ef..54363f6 100644 --- a/plugin/src/main/scala/com/github/sbt/avro/SbtAvro.scala +++ b/plugin/src/main/scala/com/github/sbt/avro/SbtAvro.scala @@ -239,8 +239,8 @@ object SbtAvro extends AutoPlugin { compiler.setFieldVisibility(avroFieldVisibility.value.toUpperCase) compiler.setUseNamespace(avroUseNamespace.value) compiler.setEnableDecimalLogicalType(avroEnableDecimalLogicalType.value) - compiler.setCreateSetters(avroOptionalGetters.value) - compiler.setOptionalGetters(avroCreateSetters.value) + compiler.setCreateSetters(avroCreateSetters.value) + compiler.setOptionalGetters(avroOptionalGetters.value) try { val recs = records.map(avroClassLoader.loadClass) diff --git a/plugin/src/sbt-test/sbt-avro/settings/build.sbt b/plugin/src/sbt-test/sbt-avro/settings/build.sbt index 5164008..bf23d25 100644 --- a/plugin/src/sbt-test/sbt-avro/settings/build.sbt +++ b/plugin/src/sbt-test/sbt-avro/settings/build.sbt @@ -10,6 +10,7 @@ libraryDependencies ++= Seq( avroStringType := "String" avroFieldVisibility := "public" +avroCreateSetters := false avroOptionalGetters := true avroEnableDecimalLogicalType := false Compile / avroSpecificRecords += "org.apache.avro.specific.TestRecordWithLogicalTypes" diff --git a/plugin/src/sbt-test/sbt-avro/settings/src/test/scala/com/github/sbt/avro/test/settings/SettingsSpec.scala b/plugin/src/sbt-test/sbt-avro/settings/src/test/scala/com/github/sbt/avro/test/settings/SettingsSpec.scala index c5c931e..046db58 100644 --- a/plugin/src/sbt-test/sbt-avro/settings/src/test/scala/com/github/sbt/avro/test/settings/SettingsSpec.scala +++ b/plugin/src/sbt-test/sbt-avro/settings/src/test/scala/com/github/sbt/avro/test/settings/SettingsSpec.scala @@ -14,19 +14,19 @@ class SettingsSpec extends Specification { // avroStringType "avroStringType setting should be respected for *.avsc compilation" >> { - classOf[Avsc].getDeclaredField("stringField").getType == classOf[String] + classOf[Avsc].getDeclaredField("stringField").getType === classOf[String] } "avroStringType setting should be respected for *.avdl compilation" >> { - classOf[Avdl].getDeclaredField("stringField").getType == classOf[String] + classOf[Avdl].getDeclaredField("stringField").getType === classOf[String] } "avroStringType setting should be respected for *.avpr compilation" >> { - classOf[Avpr].getDeclaredField("stringField").getType == classOf[String] + classOf[Avpr].getDeclaredField("stringField").getType === classOf[String] } "stringField setting should be respected for recompiled record" >> { - classOf[TestRecordWithLogicalTypes].getDeclaredField("s").getType == classOf[String] + classOf[TestRecordWithLogicalTypes].getDeclaredField("s").getType === classOf[String] } // avroFieldVisibility @@ -46,25 +46,42 @@ class SettingsSpec extends Specification { !classOf[TestRecordWithLogicalTypes].getDeclaredField("s").isAnnotationPresent(classOf[Deprecated]) } + // avroCreateSetters + "avroCreateSetters setting should be respected for *.avsc compilation" >> { + classOf[Avsc].getDeclaredMethod("setStringField") must throwA[NoSuchMethodException] + } + + "avroCreateSetters setting should be respected for *.avdl compilation" >> { + classOf[Avdl].getDeclaredMethod("setStringField") must throwA[NoSuchMethodException] + } + + "avroCreateSetters setting should be respected for *.avpr compilation" >> { + classOf[Avpr].getDeclaredMethod("stringField") must throwA[NoSuchMethodException] + } + + "avroCreateSetters setting should be respected for recompiled record" >> { + classOf[TestRecordWithLogicalTypes].getDeclaredMethod("setS") must throwA[NoSuchMethodException] + } + // avroOptionalGetters "avroOptionalGetters setting should be respected for *.avsc compilation" >> { - classOf[Avsc].getDeclaredMethod("getStringField").getReturnType == classOf[Optional[String]] + classOf[Avsc].getDeclaredMethod("getStringField").getReturnType === classOf[Optional[String]] } "avroOptionalGetters setting should be respected for *.avdl compilation" >> { - classOf[Avdl].getDeclaredMethod("getStringField").getReturnType == classOf[Optional[String]] + classOf[Avdl].getDeclaredMethod("getStringField").getReturnType === classOf[Optional[String]] } "avroOptionalGetters setting should be respected for *.avpr compilation" >> { - classOf[Avpr].getDeclaredMethod("getStringField").getReturnType == classOf[Optional[String]] + classOf[Avpr].getDeclaredMethod("getStringField").getReturnType === classOf[Optional[String]] } "avroOptionalGetters setting should be respected for recompiled record" >> { - classOf[TestRecordWithLogicalTypes].getDeclaredMethod("getS").getReturnType == classOf[Optional[String]] + classOf[TestRecordWithLogicalTypes].getDeclaredMethod("getS").getReturnType === classOf[Optional[String]] } // avroEnableDecimalLogicalType "avroEnableDecimalLogicalType setting should be respected for recompiled record" >> { - classOf[TestRecordWithLogicalTypes].getDeclaredField("bd").getType == classOf[ByteBuffer] + classOf[TestRecordWithLogicalTypes].getDeclaredField("bd").getType === classOf[ByteBuffer] } }