Created
August 3, 2012 11:15
Revisions
-
jcsirot renamed this gist
Aug 3, 2012 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
jcsirot created this gist
Aug 3, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,65 @@ package com.chelonix.selenium; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import com.dumbster.smtp.SimpleSmtpServer; import com.dumbster.smtp.SmtpMessage; import com.google.common.collect.Lists; import org.junit.rules.ExternalResource; /** * A JUnit Rule which runs a mock SMTP server * * @see org.junit.rules.TestRule */ public class MockSMTPRule extends ExternalResource { private int port = SimpleSmtpServer.DEFAULT_SMTP_PORT; private SimpleSmtpServer smtp; /** * Creates a SMTP server listening on port 25. */ public MockSMTPRule() { } /** * Creates a SMTP server listening on the given port. * @param port the SMTP port */ public MockSMTPRule(int port) { this.port = port; } public synchronized int getReceivedEmailSize() { return smtp.getReceivedEmailSize(); } public synchronized Iterator getReceivedEmail() { return smtp.getReceivedEmail(); } public List<SmtpMessage> getReceivedEmailAsList() { return Lists.newArrayList((Iterator<SmtpMessage>)getReceivedEmail()); } @Override protected void after() { smtp.stop(); super.after(); } @Override protected void before() throws Throwable { super.before(); smtp = SimpleSmtpServer.start(port); } }