Convert 'MessageIdGeneratorTest' to Kotlin

This commit is contained in:
cketti 2020-03-29 22:24:11 +02:00
parent 576696e87e
commit f1b73a11b9
2 changed files with 48 additions and 48 deletions

View file

@ -1,48 +0,0 @@
package com.fsck.k9.mail.internet;
import com.fsck.k9.mail.Address;
import com.fsck.k9.mail.K9LibRobolectricTestRunner;
import com.fsck.k9.mail.Message;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.assertEquals;
@RunWith(K9LibRobolectricTestRunner.class)
public class MessageIdGeneratorTest {
private MessageIdGenerator messageIdGenerator = new MessageIdGenerator(() -> "00000000-0000-4000-0000-000000000000");
@Test
public void generateMessageId_withFromAndReplyToAddress() throws Exception {
Message message = new MimeMessage();
message.setFrom(new Address("alice@example.org"));
message.setReplyTo(Address.parse("bob@example.com"));
String result = messageIdGenerator.generateMessageId(message);
assertEquals("<00000000-0000-4000-0000-000000000000@example.org>", result);
}
@Test
public void generateMessageId_withReplyToAddress() throws Exception {
Message message = new MimeMessage();
message.setReplyTo(Address.parse("bob@example.com"));
String result = messageIdGenerator.generateMessageId(message);
assertEquals("<00000000-0000-4000-0000-000000000000@example.com>", result);
}
@Test
public void generateMessageId_withoutRelevantHeaders() throws Exception {
Message message = new MimeMessage();
String result = messageIdGenerator.generateMessageId(message);
assertEquals("<00000000-0000-4000-0000-000000000000@fallback.k9mail.app>", result);
}
}

View file

@ -0,0 +1,48 @@
package com.fsck.k9.mail.internet
import com.fsck.k9.mail.Address
import com.fsck.k9.mail.K9LibRobolectricTestRunner
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(K9LibRobolectricTestRunner::class)
class MessageIdGeneratorTest {
private val messageIdGenerator = MessageIdGenerator(
object : UuidGenerator {
override fun randomUuid() = "00000000-0000-4000-0000-000000000000"
}
)
@Test
fun generateMessageId_withFromAndReplyToAddress() {
val message = MimeMessage().apply {
setFrom(Address("alice@example.org"))
replyTo = Address.parse("bob@example.com")
}
val result = messageIdGenerator.generateMessageId(message)
assertEquals("<00000000-0000-4000-0000-000000000000@example.org>", result)
}
@Test
fun generateMessageId_withReplyToAddress() {
val message = MimeMessage().apply {
replyTo = Address.parse("bob@example.com")
}
val result = messageIdGenerator.generateMessageId(message)
assertEquals("<00000000-0000-4000-0000-000000000000@example.com>", result)
}
@Test
fun generateMessageId_withoutRelevantHeaders() {
val message = MimeMessage()
val result = messageIdGenerator.generateMessageId(message)
assertEquals("<00000000-0000-4000-0000-000000000000@fallback.k9mail.app>", result)
}
}