From e99e2e2daf32670cf9f48f2a81f2eea861b808a1 Mon Sep 17 00:00:00 2001 From: Mauricio Muler Bodemann Date: Mon, 8 Jan 2024 16:18:02 +0100 Subject: [PATCH 1/4] Moves MailsTest to new file Fixes: OX-10357 --- src/test/kotlin/sirius/web/mails/MailsTest.kt | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/test/kotlin/sirius/web/mails/MailsTest.kt diff --git a/src/test/kotlin/sirius/web/mails/MailsTest.kt b/src/test/kotlin/sirius/web/mails/MailsTest.kt new file mode 100644 index 000000000..1741b53ac --- /dev/null +++ b/src/test/kotlin/sirius/web/mails/MailsTest.kt @@ -0,0 +1,56 @@ +/* + * Made with all the love in the world + * by scireum in Remshalden, Germany + * + * Copyright by scireum GmbH + * http://www.scireum.de - info@scireum.de + */ + +package sirius.web.mails + +import sirius.kernel.BaseSpecification +import sirius.kernel.commons.Context +import sirius.kernel.di.std.Part +import sirius.kernel.health.HandledException + +class MailsSpec extends BaseSpecification { + + @Part + static Mails mails + + def "Mails sends a simple mail"() { + when: + ((MailsMock) mails).getSentMails().clear() + mails.createEmail().to("test@scireum.de", "Test").subject("Test eMail").textContent("This is a Test.").send() + then: + MailsMock.MailSenderMock mail = ((MailsMock) mails).getLastMail() + mail.getReceiverEmail() == "test@scireum.de" + mail.getReceiverName() == "Test" + mail.getSubject() == "Test eMail" + mail.getText() == "This is a Test." + mail.getHtml() == null + } + + def "Mails rejects an invalid receiver"() { + when: + ((MailsMock) mails).getSentMails().clear() + mails.createEmail().to("test@", "Invalid").subject("Test eMail").textContent("This is a Test.").send() + then: + thrown(HandledException) + } + + def "Mails translates subject to correct language"() { + when: + ((MailsMock) mails).getSentMails().clear() + mails.createEmail() + .to("test@scireum.de", "Test") + .nlsSubject("mail.subject", Context.create().set("nr", "1")) + .setLanguage("fr") + .textContent("This is a Test.") + .send() + then: + MailsMock.MailSenderMock mail = ((MailsMock) mails).getLastMail() + mail.getSubject() == "Ceci est le test 1." + } + +} From 27eeabc95d1d926de2698c8575c029be1a4a4b1d Mon Sep 17 00:00:00 2001 From: Mauricio Muler Bodemann Date: Mon, 8 Jan 2024 16:38:33 +0100 Subject: [PATCH 2/4] Adapts to kotlin syntax Fixes: OX-10357 --- src/test/kotlin/sirius/web/mails/MailsTest.kt | 64 +++++++++++-------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/src/test/kotlin/sirius/web/mails/MailsTest.kt b/src/test/kotlin/sirius/web/mails/MailsTest.kt index 1741b53ac..f0d44dfef 100644 --- a/src/test/kotlin/sirius/web/mails/MailsTest.kt +++ b/src/test/kotlin/sirius/web/mails/MailsTest.kt @@ -8,49 +8,61 @@ package sirius.web.mails -import sirius.kernel.BaseSpecification +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows +import org.junit.jupiter.api.extension.ExtendWith +import sirius.kernel.SiriusExtension import sirius.kernel.commons.Context import sirius.kernel.di.std.Part import sirius.kernel.health.HandledException +import kotlin.test.assertEquals -class MailsSpec extends BaseSpecification { +@ExtendWith(SiriusExtension::class) +class MailsTest { - @Part - static Mails mails + companion object { + @Part + @JvmStatic + private lateinit var mails: MailsMock + } + + @Test + fun `Mails sends a simple mail`() { - def "Mails sends a simple mail"() { - when: - ((MailsMock) mails).getSentMails().clear() + mails.sentMails.clear() mails.createEmail().to("test@scireum.de", "Test").subject("Test eMail").textContent("This is a Test.").send() - then: - MailsMock.MailSenderMock mail = ((MailsMock) mails).getLastMail() - mail.getReceiverEmail() == "test@scireum.de" - mail.getReceiverName() == "Test" - mail.getSubject() == "Test eMail" - mail.getText() == "This is a Test." - mail.getHtml() == null + println(mails.lastMail.receiverName) + + val mail = mails.lastMail + assertEquals("test@scireum.de", mail.getReceiverEmail()) + assertEquals("Test", mail.getReceiverName()) + assertEquals("Test eMail", mail.getSubject()) + assertEquals("This is a Test.", mail.getText()) + assertEquals(null, mail.getHtml()) } - def "Mails rejects an invalid receiver"() { - when: - ((MailsMock) mails).getSentMails().clear() - mails.createEmail().to("test@", "Invalid").subject("Test eMail").textContent("This is a Test.").send() - then: - thrown(HandledException) + @Test + fun `Mails rejects an invalid receiver`() { + mails.sentMails.clear() + + assertThrows { + mails.createEmail().to("test@", "Invalid").subject("Test eMail").textContent("This is a Test.").send() + } } - def "Mails translates subject to correct language"() { - when: - ((MailsMock) mails).getSentMails().clear() + @Test + fun `Mails translates subject to correct language`() { + + mails.sentMails.clear() mails.createEmail() .to("test@scireum.de", "Test") .nlsSubject("mail.subject", Context.create().set("nr", "1")) .setLanguage("fr") .textContent("This is a Test.") .send() - then: - MailsMock.MailSenderMock mail = ((MailsMock) mails).getLastMail() - mail.getSubject() == "Ceci est le test 1." + + val mail = mails.lastMail + assertEquals("Ceci est le test 1.", mail.getSubject()) } } From c992c4a97f7f75c7d262b327ab23dd04c5572078 Mon Sep 17 00:00:00 2001 From: Mauricio Muler Bodemann Date: Mon, 8 Jan 2024 17:01:43 +0100 Subject: [PATCH 3/4] Fixes mocking of mails Fixes: OX-10357 --- src/test/kotlin/sirius/web/mails/MailsTest.kt | 54 ++++++++++--------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/src/test/kotlin/sirius/web/mails/MailsTest.kt b/src/test/kotlin/sirius/web/mails/MailsTest.kt index f0d44dfef..890621537 100644 --- a/src/test/kotlin/sirius/web/mails/MailsTest.kt +++ b/src/test/kotlin/sirius/web/mails/MailsTest.kt @@ -23,46 +23,50 @@ class MailsTest { companion object { @Part @JvmStatic - private lateinit var mails: MailsMock + private lateinit var mails: Mails } @Test fun `Mails sends a simple mail`() { + (mails as MailsMock).let { mailsMock -> + mailsMock.sentMails.clear() + mailsMock.createEmail().to("test@scireum.de", "Test").subject("Test eMail").textContent("This is a Test.") + .send() - mails.sentMails.clear() - mails.createEmail().to("test@scireum.de", "Test").subject("Test eMail").textContent("This is a Test.").send() - println(mails.lastMail.receiverName) - - val mail = mails.lastMail - assertEquals("test@scireum.de", mail.getReceiverEmail()) - assertEquals("Test", mail.getReceiverName()) - assertEquals("Test eMail", mail.getSubject()) - assertEquals("This is a Test.", mail.getText()) - assertEquals(null, mail.getHtml()) + val mail = mailsMock.lastMail + assertEquals("test@scireum.de", mail.getReceiverEmail()) + assertEquals("Test", mail.getReceiverName()) + assertEquals("Test eMail", mail.getSubject()) + assertEquals("This is a Test.", mail.getText()) + assertEquals(null, mail.getHtml()) + } } @Test fun `Mails rejects an invalid receiver`() { - mails.sentMails.clear() + (mails as MailsMock).let { mailsMock -> + mailsMock.sentMails.clear() - assertThrows { - mails.createEmail().to("test@", "Invalid").subject("Test eMail").textContent("This is a Test.").send() + assertThrows { + mailsMock.createEmail().to("test@", "Invalid").subject("Test eMail").textContent("This is a Test.") + .send() + } } } @Test fun `Mails translates subject to correct language`() { + (mails as MailsMock).let { mailsMock -> + mailsMock.sentMails.clear() + mailsMock.createEmail() + .to("test@scireum.de", "Test") + .nlsSubject("mail.subject", Context.create().set("nr", "1")) + .setLanguage("fr") + .textContent("This is a Test.") + .send() - mails.sentMails.clear() - mails.createEmail() - .to("test@scireum.de", "Test") - .nlsSubject("mail.subject", Context.create().set("nr", "1")) - .setLanguage("fr") - .textContent("This is a Test.") - .send() - - val mail = mails.lastMail - assertEquals("Ceci est le test 1.", mail.getSubject()) + val mail = mailsMock.lastMail + assertEquals("Ceci est le test 1.", mail.getSubject()) + } } - } From 4772532e438272b314b872878feb5dc4e19bfb49 Mon Sep 17 00:00:00 2001 From: Mauricio Muler Bodemann Date: Mon, 8 Jan 2024 17:02:05 +0100 Subject: [PATCH 4/4] Deleted old file Fixes: OX-10357 --- .../java/sirius/web/mails/MailsSpec.groovy | 56 ------------------- 1 file changed, 56 deletions(-) delete mode 100644 src/test/java/sirius/web/mails/MailsSpec.groovy diff --git a/src/test/java/sirius/web/mails/MailsSpec.groovy b/src/test/java/sirius/web/mails/MailsSpec.groovy deleted file mode 100644 index ae7b2c885..000000000 --- a/src/test/java/sirius/web/mails/MailsSpec.groovy +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Made with all the love in the world - * by scireum in Remshalden, Germany - * - * Copyright by scireum GmbH - * http://www.scireum.de - info@scireum.de - */ - -package sirius.web.mails - -import sirius.kernel.BaseSpecification -import sirius.kernel.commons.Context -import sirius.kernel.di.std.Part -import sirius.kernel.health.HandledException - -class MailsSpec extends BaseSpecification { - - @Part - static Mails mails - - def "Mails sends a simple mail"() { - when: - ((MailsMock) mails).getSentMails().clear() - mails.createEmail().to("test@scireum.de", "Test").subject("Test eMail").textContent("This is a Test.").send() - then: - MailsMock.MailSenderMock mail = ((MailsMock) mails).getLastMail() - mail.getReceiverEmail() == "test@scireum.de" - mail.getReceiverName() == "Test" - mail.getSubject() == "Test eMail" - mail.getText() == "This is a Test." - mail.getHtml() == null - } - - def "Mails rejects an invalid receiver"() { - when: - ((MailsMock) mails).getSentMails().clear() - mails.createEmail().to("test@", "Invalid").subject("Test eMail").textContent("This is a Test.").send() - then: - thrown(HandledException) - } - - def "Mails translates subject to correct language"() { - when: - ((MailsMock) mails).getSentMails().clear() - mails.createEmail() - .to("test@scireum.de", "Test") - .nlsSubject("mail.subject", Context.create().set("nr", "1")) - .setLanguage("fr") - .textContent("This is a Test.") - .send() - then: - MailsMock.MailSenderMock mail = ((MailsMock) mails).getLastMail() - mail.getSubject() == "Ceci est le test 1." - } - -}