@@ -9,18 +9,18 @@ import kotlinx.coroutines.CoroutineScope
99import kotlinx.coroutines.Dispatchers
1010import kotlinx.coroutines.SupervisorJob
1111import kotlinx.coroutines.runBlocking
12- import org.hamcrest.Matchers.*
1312import org.junit.After
14- import org.junit.Assert.assertThat
1513import org.junit.Before
1614import org.junit.Test
15+ import kotlin.test.assertContains
16+ import kotlin.test.assertEquals
17+ import kotlin.test.assertTrue
1718
1819
1920class EmailTest {
20-
21- private var server : SimpleSmtpServer ? = null
21+ private lateinit var server : SimpleSmtpServer
22+ private lateinit var mailerService : MailerService
2223 private val scope = CoroutineScope (Dispatchers .IO + SupervisorJob ())
23- private var mailerService: MailerService ? = null
2424
2525 @Before
2626 fun setUp () {
@@ -29,22 +29,22 @@ class EmailTest {
2929 scope,
3030 SMTPConfig (
3131 host = " localhost" ,
32- port = server!! .port
32+ port = server.port
3333 )
3434 )
3535 }
3636
3737 @After
3838 @Throws(Exception ::class )
3939 fun tearDown () {
40- server? .stop()
40+ server.stop()
4141 }
4242
4343 @Test
4444 fun testSend () {
4545
4646 runBlocking {
47- mailerService!! .compose().apply {
47+ mailerService.compose().apply {
4848 fromEmail = " from@icerockdev.com"
4949 fromName = " From Person"
5050 subject = " TEST EMAIL"
@@ -54,16 +54,16 @@ class EmailTest {
5454 .join()
5555 }
5656
57- val emails = server!! .receivedEmails
58- assertThat(emails, hasSize( 1 ) )
57+ val emails = server.receivedEmails
58+ assertEquals(expected = 1 , actual = emails.size )
5959 val email = emails[0 ]
60- assertThat(email.getHeaderValue( " Subject " ), ` is `( " TEST EMAIL " ))
61- assertThat(email.body, containsString( " <h1>Test test test</h1> " ))
62- assertThat (email.headerNames, hasItem( " Date " ) )
63- assertThat( email.headerNames, hasItem( " From " ))
64- assertThat( email.headerNames, hasItem( " To " ))
65- assertThat( email.headerNames, hasItem( " Subject " ))
66- assertThat( email.getHeaderValues(" To" ), contains( " Test Person <to@icerockdev.com> " ) )
67- assertThat( email.getHeaderValue (" To" ), ` is ` (" Test Person <to@icerockdev.com>" ))
60+
61+ assertEquals(expected = " TEST EMAIL " , actual = email.getHeaderValue( " Subject " ))
62+ assertContains (email.body, " <h1>Test test test</h1> " )
63+ assertTrue { email.headerNames.contains( " Date " ) }
64+ assertTrue { email.headerNames.contains( " From " ) }
65+ assertTrue { email.headerNames.contains( " To " ) }
66+ assertEquals(expected = 1 , email.getHeaderValues(" To" ).size )
67+ assertTrue { email.getHeaderValues (" To" ).contains (" Test Person <to@icerockdev.com>" ) }
6868 }
69- }
69+ }
0 commit comments