1 package net.jaekl.qd.util;
3 import static org.junit.Assert.*;
5 import java.nio.charset.Charset;
9 public class SendMailTest {
12 public void testRfc821Samples() throws MailException {
13 final String TYPICAL_INIT = "220 BBN-UNIX.ARPA Simple Mail Transfer Service Ready";
14 final String[][] TYPICAL = {
29 "354 Start mail input; end with <CRLF>.<CRLF>"
37 "221 BBN-UNIX.ARPA Service closing transmission channel"
40 final String TYPICAL_SENT =
41 "MAIL FROM: tarzan@jane.net\r\n"
42 + "RCPT TO: jane@jane.net\r\n"
44 + "From: tarzan@jane.net\r\n"
45 + "To: jane@jane.net\r\n"
46 + "Subject: Me Tarzan, you Jane\r\n"
47 + "MIME-Version: 1.0\r\n"
48 + "Content-Type: multipart/mixed; boundary=snip_snip\r\n"
51 + "Content-Type: text/plain\r\n"
53 + "Tarzan like Jane\n"
54 + "Tarzan come see Jane soon\n"
62 SmtpConversationMock conversat = new SmtpConversationMock(TYPICAL_INIT, TYPICAL);
63 SendMailMock smm = new SendMailMock(conversat);
65 smm.setFrom("tarzan@jane.net");
66 smm.addTo("jane@jane.net");
67 smm.setSubject("Me Tarzan, you Jane");
69 MimePart part = new MimePart("text/plain", "Tarzan like Jane\nTarzan come see Jane soon\n\nTarzan");
74 OutputStreamMock osm = conversat.getOutputStream();
75 String result = osm.mock_getContent(Charset.forName(FileMock.UTF_8));
77 int pos = result.indexOf("\r\n");
79 String afterHELO = result.substring(pos + 2);
81 assertTrue(result.startsWith("HELO "));
82 assertEquals(TYPICAL_SENT, afterHELO);