Skip to content

Commit

Permalink
Merge pull request #1358 from scireum/feature/mbo/OX-10357-4
Browse files Browse the repository at this point in the history
JUnit: Migrate MailsTest to Kotlin
  • Loading branch information
sabieber authored Jan 9, 2024
2 parents 5be4887 + 4772532 commit 8f2e545
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 56 deletions.
56 changes: 0 additions & 56 deletions src/test/java/sirius/web/mails/MailsSpec.groovy

This file was deleted.

72 changes: 72 additions & 0 deletions src/test/kotlin/sirius/web/mails/MailsTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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 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

@ExtendWith(SiriusExtension::class)
class MailsTest {

companion object {
@Part
@JvmStatic
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()

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 as MailsMock).let { mailsMock ->
mailsMock.sentMails.clear()

assertThrows<HandledException> {
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()

val mail = mailsMock.lastMail
assertEquals("Ceci est le test 1.", mail.getSubject())
}
}
}

0 comments on commit 8f2e545

Please sign in to comment.