Methods Summary |
---|
private void | setRecipients(org.apache.mailet.MailAddress[] recipients)
this.recipients = recipients;
|
private void | setRegex(java.lang.String regex)
this.regex = regex;
|
private void | setupMatcher()
setupMockedMimeMessage();
matcher = new RecipientIsRegex();
MockMatcherConfig mci = new MockMatcherConfig("RecipientIsRegex="
+ regex, new MockMailContext());
matcher.init(mci);
|
private void | setupMockedMail(javax.mail.internet.MimeMessage m)
mockedMail = new MockMail();
mockedMail.setMessage(m);
mockedMail.setRecipients(Arrays.asList(recipients));
|
private void | setupMockedMimeMessage()
String sender = "test@james.apache.org";
String rcpt = "test2@james.apache.org";
mockedMimeMessage = new MockMimeMessage();
mockedMimeMessage.setFrom(new InternetAddress(sender));
mockedMimeMessage.setRecipients(RecipientType.TO, rcpt);
mockedMimeMessage.setSubject("testmail");
mockedMimeMessage.setText("testtext");
mockedMimeMessage.saveChanges();
|
public void | testRegexIsMatchedAllRecipients()
setRecipients(new MailAddress[] { new MailAddress(
"test@james.apache.org") });
setRegex(".*@.*");
setupMockedMimeMessage();
setupMockedMail(mockedMimeMessage);
setupMatcher();
Collection matchedRecipients = matcher.match(mockedMail);
assertNotNull(matchedRecipients);
assertEquals(matchedRecipients.size(), mockedMail.getRecipients()
.size());
|
public void | testRegexIsMatchedOneRecipient()
setRecipients(new MailAddress[] {
new MailAddress("test@james.apache.org"),
new MailAddress("test2@james.apache.org") });
setRegex("^test@.*");
setupMockedMimeMessage();
setupMockedMail(mockedMimeMessage);
setupMatcher();
Collection matchedRecipients = matcher.match(mockedMail);
assertNotNull(matchedRecipients);
assertEquals(matchedRecipients.size(), 1);
|
public void | testRegexIsNotMatch()
setRecipients(new MailAddress[] {
new MailAddress("test@james2.apache.org"),
new MailAddress("test2@james2.apache.org") });
setRegex(".*\\+");
setupMockedMimeMessage();
setupMockedMail(mockedMimeMessage);
setupMatcher();
Collection matchedRecipients = matcher.match(mockedMail);
assertEquals(matchedRecipients.size(), 0);
|
public void | testRegexIsNotMatchedCauseError()
Collection matchedRecipients = null;
String invalidRegex = "(!(";
String regexException = null;
String exception = "Malformed pattern: " + invalidRegex;
setRecipients(new MailAddress[] {
new MailAddress("test@james2.apache.org"),
new MailAddress("test2@james2.apache.org") });
setRegex(invalidRegex);
setupMockedMimeMessage();
setupMockedMail(mockedMimeMessage);
try {
setupMatcher();
matchedRecipients = matcher.match(mockedMail);
} catch (MessagingException m) {
m.printStackTrace();
regexException = m.getMessage();
}
assertNull(matchedRecipients);
assertEquals(regexException, exception);
|