~jan0sch/smederee

Showing details for patch 40cc63cd99410e09dc6b0d1037e96d09e2279432.
2023-11-27 (Mon), 9:52 AM - Jens Grassel - 40cc63cd99410e09dc6b0d1037e96d09e2279432

email: Add basic tests for generators.

- provide `Arbitrary` givens within `Generators`
Summary of changes
3 files modified with 12 lines added and 8 lines removed
  • modules/email/src/test/scala/de/smederee/email/EmailMiddlewareTest.scala with 1 added and 5 removed lines
  • modules/email/src/test/scala/de/smederee/email/Generators.scala with 10 added and 0 removed lines
  • modules/email/src/test/scala/de/smederee/email/SimpleJavaMailMiddlewareHelpersTest.scala with 1 added and 3 removed lines
diff -rN -u old-smederee/modules/email/src/test/scala/de/smederee/email/EmailMiddlewareTest.scala new-smederee/modules/email/src/test/scala/de/smederee/email/EmailMiddlewareTest.scala
--- old-smederee/modules/email/src/test/scala/de/smederee/email/EmailMiddlewareTest.scala	2025-01-13 12:01:51.067841312 +0000
+++ new-smederee/modules/email/src/test/scala/de/smederee/email/EmailMiddlewareTest.scala	2025-01-13 12:01:51.067841312 +0000
@@ -19,17 +19,13 @@
 
 import java.nio.charset.StandardCharsets
 
-import de.smederee.email.Generators.*
+import de.smederee.email.Generators.given
 
 import munit.*
 
 import org.scalacheck.Prop.*
-import org.scalacheck.*
 
 final class EmailMiddlewareTest extends ScalaCheckSuite {
-    given Arbitrary[FromAddress] = Arbitrary(genValidFromAddress)
-    given Arbitrary[ToAddress]   = Arbitrary(genValidToAddress)
-
     property("EmailServerPassword.apply and .toArray must be reversible") {
         forAll { (randomBytes: Array[Byte]) =>
             val password = EmailServerPassword(randomBytes)
diff -rN -u old-smederee/modules/email/src/test/scala/de/smederee/email/Generators.scala new-smederee/modules/email/src/test/scala/de/smederee/email/Generators.scala
--- old-smederee/modules/email/src/test/scala/de/smederee/email/Generators.scala	2025-01-13 12:01:51.067841312 +0000
+++ new-smederee/modules/email/src/test/scala/de/smederee/email/Generators.scala	2025-01-13 12:01:51.067841312 +0000
@@ -38,11 +38,17 @@
         suffix = s"$domain.$topLevelDomain"
     } yield FromAddress(s"$prefix@$suffix")
 
+    given Arbitrary[FromAddress] = Arbitrary(genValidFromAddress)
+
     val genValidSubjectLine: Gen[SubjectLine] =
         Gen.nonEmptyListOf(Gen.alphaNumChar).map(_.take(78).mkString).map(SubjectLine.apply)
 
+    given Arbitrary[SubjectLine] = Arbitrary(genValidSubjectLine)
+
     val genValidTextBody: Gen[TextBody] = Gen.nonEmptyListOf(Gen.alphaNumChar).map(_.mkString).map(TextBody.apply)
 
+    given Arbitrary[TextBody] = Arbitrary(genValidTextBody)
+
     val genValidToAddress: Gen[ToAddress] = for {
         prefix <- Gen.nonEmptyListOf(Gen.oneOf(validEmailAddressPrefixChars)).map(_.take(64).mkString)
         domain <- Gen.nonEmptyListOf(Gen.oneOf(validDomainNameChars)).map(_.take(32).mkString)
@@ -53,6 +59,8 @@
         suffix = s"$domain.$topLevelDomain"
     } yield ToAddress(s"$prefix@$suffix")
 
+    given Arbitrary[ToAddress] = Arbitrary(genValidToAddress)
+
     val genEmailMessage: Gen[EmailMessage] = for {
         from     <- genValidFromAddress
         to       <- genValidToAddress
@@ -69,4 +77,6 @@
         subject,
         textBody
     )
+
+    given Arbitrary[EmailMessage] = Arbitrary(genEmailMessage)
 }
diff -rN -u old-smederee/modules/email/src/test/scala/de/smederee/email/SimpleJavaMailMiddlewareHelpersTest.scala new-smederee/modules/email/src/test/scala/de/smederee/email/SimpleJavaMailMiddlewareHelpersTest.scala
--- old-smederee/modules/email/src/test/scala/de/smederee/email/SimpleJavaMailMiddlewareHelpersTest.scala	2025-01-13 12:01:51.067841312 +0000
+++ new-smederee/modules/email/src/test/scala/de/smederee/email/SimpleJavaMailMiddlewareHelpersTest.scala	2025-01-13 12:01:51.067841312 +0000
@@ -19,7 +19,7 @@
 
 import cats.kernel.Eq
 import cats.syntax.all.*
-import de.smederee.email.Generators.*
+import de.smederee.email.Generators.given
 import jakarta.mail.Message.RecipientType
 
 import munit.*
@@ -34,8 +34,6 @@
 
     given Eq[RecipientType] = Eq.fromUniversalEquals
 
-    given Arbitrary[EmailMessage] = Arbitrary(genEmailMessage)
-
     property("EmailMessage.toEmail must create correct Email instances") {
         forAll { (message: EmailMessage) =>
             val email = message.toEmail