This post originated from an RSS feed registered with Java Buzz
by Vinny Carpenter.
Original Post: I love The Dumbster :)
Feed Title: Vinny Carpenter's Blog
Feed URL: http://www.j2eegeek.com/error.html
Feed Description: Welcome to my blog. I am a total Java geek that lives in Milwaukee, making my living as an architect/developer, spending all my time with Java, J2EE, OO, Linux, and open source. In my spare time, when I am not in front of my computers, I spend every other minute with my other loves: My wife, books, music, guitars, Formula-1 racing and StarGate. Check out my blog @ http://www.j2eegeek.com/blog
Cobbie just turned me onto Dumbster, a really awesome tool for unit-testing applications or classes that send out email.
Dumbster is a very simple fake SMTP server designed specifically for unit and system testing applications that send email messages. It responds to all standard SMTP commands but does not actually deliver the email messages to the user. The messages are stored within Dumbster for later extraction and verification, further enhancing your unit tests, as you are able to validate sender, recipient, subject, and message content.
The Dumbster is written in Java and is open source and a must have in your testing toolbox. Thanks Cobbie and thanks Jason Kitchen for creating The Dumbster.
publicvoid testTextEmail() {
String smtpHost = "localhost"; String to = "you@yourdomain.com"; String from = "me@mydomain.com"; String subject = "Testing EMailUtil"; String message = "Writing Unit tests is fun - don't you agree?"; String replyTo = null; boolean debug = true; try { SimpleSmtpServer server = SimpleSmtpServer.start(); EmailUtil.sendTextMail(smtpHost, to, from, subject, message, replyTo, debug); server.stop(); assertTrue(server.getReceivedEmailSize() == 1); Iterator emailIter = server.getReceivedEmail(); SmtpMessage email = (SmtpMessage) emailIter.next(); assertTrue(email.getHeaderValue("Subject").equals(subject)); assertTrue(email.getBody().equals(message));
} catch (EmailUtilException e) { fail("Shouldn't get an exception"); } }