+package net.jaekl.qd.util;
+
+import static org.junit.Assert.*;
+
+import java.nio.charset.Charset;
+
+import org.junit.Test;
+
+public class SendMailTest {
+
+ @Test
+ public void testRfc821Samples() throws MailException {
+ final String TYPICAL_INIT = "220 BBN-UNIX.ARPA Simple Mail Transfer Service Ready";
+ final String[][] TYPICAL = {
+ {
+ "HELO ",
+ "250 BBN-UNIX.ARPA"
+ },
+ {
+ "MAIL FROM:",
+ "250 OK"
+ },
+ {
+ "RCPT TO:",
+ "250 OK"
+ },
+ {
+ "DATA",
+ "354 Start mail input; end with <CRLF>.<CRLF>"
+ },
+ {
+ ".\r\n",
+ "250 OK"
+ },
+ {
+ "QUIT",
+ "221 BBN-UNIX.ARPA Service closing transmission channel"
+ }
+ };
+ final String TYPICAL_SENT =
+ "MAIL FROM: tarzan@jane.net\r\n"
+ + "RCPT TO: jane@jane.net\r\n"
+ + "DATA\r\n"
+ + "From: tarzan@jane.net\r\n"
+ + "To: jane@jane.net\r\n"
+ + "Subject: Me Tarzan, you Jane\r\n"
+ + "MIME-Version: 1.0\r\n"
+ + "Content-Type: multipart/mixed; boundary=snip_snip\r\n"
+ + "\r\n"
+ + "--snip_snip\r\n"
+ + "Content-Type: text/plain\r\n"
+ + "\r\n"
+ + "Tarzan like Jane\n"
+ + "Tarzan come see Jane soon\n"
+ + "\n"
+ + "Tarzan\r\n"
+ + "\r\n"
+ + "--snip_snip--\r\n"
+ + "\r\n.\r\n\r\n"
+ + "QUIT\r\n";
+
+ SmtpConversationMock conversat = new SmtpConversationMock(TYPICAL_INIT, TYPICAL);
+ SendMailMock smm = new SendMailMock(conversat);
+
+ smm.setFrom("tarzan@jane.net");
+ smm.addTo("jane@jane.net");
+ smm.setSubject("Me Tarzan, you Jane");
+
+ MimePart part = new MimePart("text/plain", "Tarzan like Jane\nTarzan come see Jane soon\n\nTarzan");
+ smm.addPart(part);
+
+ smm.send();
+
+ OutputStreamMock osm = conversat.getOutputStream();
+ String result = osm.mock_getContent(Charset.forName(FileMock.UTF_8));
+
+ int pos = result.indexOf("\r\n");
+ assertTrue(pos > 0);
+ String afterHELO = result.substring(pos + 2);
+
+ assertTrue(result.startsWith("HELO "));
+ assertEquals(TYPICAL_SENT, afterHELO);
+ }
+}