Methods Summary |
---|
private void | setMailAttributeName(java.lang.String mailAttributeName)
this.mailAttributeName = mailAttributeName;
|
private void | setMailAttributeValue(java.lang.String mailAttributeValue)
this.mailAttributeValue = mailAttributeValue;
|
private void | setRegex(java.lang.String regex)
this.regex = regex;
|
private void | setupMatcher()
setupMockedMimeMessage();
matcher = new HasMailAttributeWithValueRegex();
MockMatcherConfig mci = new MockMatcherConfig("HasMailAttribute="
+ MAIL_ATTRIBUTE_NAME + ", " + regex, new MockMailContext());
matcher.init(mci);
|
private void | setupMockedMail(javax.mail.internet.MimeMessage m)
mockedMail = new MockMail();
mockedMail.setMessage(m);
mockedMail.setRecipients(Arrays.asList(new MailAddress[] {
new MailAddress("test@james.apache.org"),
new MailAddress("test2@james.apache.org") }));
mockedMail.setAttribute(mailAttributeName,
(Serializable) mailAttributeValue);
|
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 | testAttributeIsMatched()
setMailAttributeName(MAIL_ATTRIBUTE_NAME);
setMailAttributeValue(MAIL_ATTRIBUTE_VALUE);
setRegex(".*");
setupMockedMimeMessage();
setupMockedMail(mockedMimeMessage);
setupMatcher();
Collection matchedRecipients = matcher.match(mockedMail);
assertNotNull(matchedRecipients);
assertEquals(matchedRecipients.size(), mockedMail.getRecipients()
.size());
|
public void | testHeaderIsNotMatched()
setRegex("\\d");
setupMockedMimeMessage();
setupMockedMail(mockedMimeMessage);
setupMatcher();
Collection matchedRecipients = matcher.match(mockedMail);
assertNull(matchedRecipients);
|
public void | testHeaderIsNotMatchedCauseValue()
String invalidRegex = "(!(";
String regexException = null;
String exception = "Malformed pattern: " + invalidRegex;
setRegex(invalidRegex);
setupMockedMimeMessage();
setupMockedMail(mockedMimeMessage);
try {
setupMatcher();
} catch (MessagingException m) {
regexException = m.getMessage();
}
Collection matchedRecipients = matcher.match(mockedMail);
assertNull(matchedRecipients);
assertEquals(regexException, exception);
|