From 9cbc796ae9573bfd26ae829ae11fe06cf8cda4b1 Mon Sep 17 00:00:00 2001 From: jaredb96 Date: Thu, 11 Jul 2024 09:44:41 -0400 Subject: [PATCH 1/3] Fix DataGenerator unit test. --- .../publisher/helper/DataGeneratorSpec.scala | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 hmda-data-publisher/src/test/scala/hmda/publisher/helper/DataGeneratorSpec.scala diff --git a/hmda-data-publisher/src/test/scala/hmda/publisher/helper/DataGeneratorSpec.scala b/hmda-data-publisher/src/test/scala/hmda/publisher/helper/DataGeneratorSpec.scala new file mode 100644 index 0000000000..d514884e64 --- /dev/null +++ b/hmda-data-publisher/src/test/scala/hmda/publisher/helper/DataGeneratorSpec.scala @@ -0,0 +1,27 @@ +package hmda.publisher.helper + +import org.scalatest.{Matchers, WordSpec} +import java.time.LocalDate +import java.time.format.DateTimeFormatter + + +class DateGeneratorSpec extends WordSpec with Matchers { + + val generator = DateGenerator + val currentDate: LocalDate = LocalDate.now().minusDays(1) + val formatter: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd") + val actualDateString: String = currentDate.format(formatter) + "-" + val actualQuarterlyDateString: String = currentDate.format(formatter) + "_" + + "date generator" should { + + "return correct current date" in { + assert(generator.currentDate == actualDateString) + } + + "return correct current quarterly date" in { + assert(generator.currentQuarterlyDate == actualQuarterlyDateString) + } + } + +} \ No newline at end of file From cc0be4d8793f97d5b9f6f3967ef38fc42cfe1951 Mon Sep 17 00:00:00 2001 From: jaredb96 Date: Fri, 12 Jul 2024 13:08:38 -0400 Subject: [PATCH 2/3] Test date format. --- .../publisher/helper/DataGeneratorSpec.scala | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/hmda-data-publisher/src/test/scala/hmda/publisher/helper/DataGeneratorSpec.scala b/hmda-data-publisher/src/test/scala/hmda/publisher/helper/DataGeneratorSpec.scala index d514884e64..d1ff58bed5 100644 --- a/hmda-data-publisher/src/test/scala/hmda/publisher/helper/DataGeneratorSpec.scala +++ b/hmda-data-publisher/src/test/scala/hmda/publisher/helper/DataGeneratorSpec.scala @@ -1,26 +1,26 @@ package hmda.publisher.helper import org.scalatest.{Matchers, WordSpec} -import java.time.LocalDate -import java.time.format.DateTimeFormatter +import scala.util.matching.Regex class DateGeneratorSpec extends WordSpec with Matchers { + val annualPattern: Regex = raw"\d{4}-\d{2}-\d{2}-".r + val quarterPattern: Regex = raw"\d{4}-\d{2}-\d{2}_".r val generator = DateGenerator - val currentDate: LocalDate = LocalDate.now().minusDays(1) - val formatter: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd") - val actualDateString: String = currentDate.format(formatter) + "-" - val actualQuarterlyDateString: String = currentDate.format(formatter) + "_" + "date generator" should { - "return correct current date" in { - assert(generator.currentDate == actualDateString) + "return a correctly formatted annual date string" in { + val annualMatch = annualPattern.findFirstIn(generator.currentDate) + assert(annualMatch.contains(generator.currentDate)) } - "return correct current quarterly date" in { - assert(generator.currentQuarterlyDate == actualQuarterlyDateString) + "return a correctly formatted quarterly date string" in { + val quarterMatch = quarterPattern.findFirstIn(generator.currentQuarterlyDate) + assert(quarterMatch.contains(generator.currentQuarterlyDate)) } } From 8a5872f024405545f8eefcd148f65c1a3120ce83 Mon Sep 17 00:00:00 2001 From: jaredb96 Date: Fri, 12 Jul 2024 13:42:58 -0400 Subject: [PATCH 3/3] Change variable scope. --- .../test/scala/hmda/publisher/helper/DataGeneratorSpec.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hmda-data-publisher/src/test/scala/hmda/publisher/helper/DataGeneratorSpec.scala b/hmda-data-publisher/src/test/scala/hmda/publisher/helper/DataGeneratorSpec.scala index d1ff58bed5..0e4e9ea608 100644 --- a/hmda-data-publisher/src/test/scala/hmda/publisher/helper/DataGeneratorSpec.scala +++ b/hmda-data-publisher/src/test/scala/hmda/publisher/helper/DataGeneratorSpec.scala @@ -6,19 +6,19 @@ import scala.util.matching.Regex class DateGeneratorSpec extends WordSpec with Matchers { - val annualPattern: Regex = raw"\d{4}-\d{2}-\d{2}-".r - val quarterPattern: Regex = raw"\d{4}-\d{2}-\d{2}_".r val generator = DateGenerator "date generator" should { "return a correctly formatted annual date string" in { + val annualPattern: Regex = raw"\d{4}-\d{2}-\d{2}-".r val annualMatch = annualPattern.findFirstIn(generator.currentDate) assert(annualMatch.contains(generator.currentDate)) } "return a correctly formatted quarterly date string" in { + val quarterPattern: Regex = raw"\d{4}-\d{2}-\d{2}_".r val quarterMatch = quarterPattern.findFirstIn(generator.currentQuarterlyDate) assert(quarterMatch.contains(generator.currentQuarterlyDate)) }