@Test public void testGetTokenNoReply() throws MessagingException { mockery.checking(new Expectations() { { allowing(message).getRecipients(RecipientType.TO); will(returnValue(new Address[] { new InternetAddress(OTHER_ADDRESS), new InternetAddress(SYSTEM_ADDRESS), new InternetAddress("system+ABC" + AT_DOMAIN) })); allowing(tokenEncoder).couldBeToken("ABC"); will(returnValue(false)); } }); String result = sut.getToken(message); mockery.assertIsSatisfied(); assertNull(result); }
String getToken(final Message message) throws MessagingException { Address[] addresses = message.getRecipients(RecipientType.TO); if (addresses != null) { boolean noReplyFound = false; for (int i = 0; i < addresses.length; i++) { String addr = ((InternetAddress) addresses[i]).getAddress(); if (requiredToAddress.equals(addr)) { noReplyFound = true; } else if (addr.startsWith(toEmailRequiredStart) && addr.endsWith(toEmailRequiredEnd)) { String middle = addr.substring(toEmailRequiredStart.length(), addr.length() - toEmailRequiredEnd.length()); if (tokenEncoder.couldBeToken(middle)) { return middle; } } } if (noReplyFound) { return null; } } throw new ValidationException("Cannot find To address for the system with an address tag."); }
MessageProcessor { String getToken(final Message message) throws MessagingException { Address[] addresses = message.getRecipients(RecipientType.TO); if (addresses != null) { boolean noReplyFound = false; for (int i = 0; i < addresses.length; i++) { String addr = ((InternetAddress) addresses[i]).getAddress(); if (requiredToAddress.equals(addr)) { noReplyFound = true; } else if (addr.startsWith(toEmailRequiredStart) && addr.endsWith(toEmailRequiredEnd)) { String middle = addr.substring(toEmailRequiredStart.length(), addr.length() - toEmailRequiredEnd.length()); if (tokenEncoder.couldBeToken(middle)) { return middle; } } } if (noReplyFound) { return null; } } throw new ValidationException("Cannot find To address for the system with an address tag."); } }
MessageProcessor { String getToken(final Message message) throws MessagingException { Address[] addresses = message.getRecipients(RecipientType.TO); if (addresses != null) { boolean noReplyFound = false; for (int i = 0; i < addresses.length; i++) { String addr = ((InternetAddress) addresses[i]).getAddress(); if (requiredToAddress.equals(addr)) { noReplyFound = true; } else if (addr.startsWith(toEmailRequiredStart) && addr.endsWith(toEmailRequiredEnd)) { String middle = addr.substring(toEmailRequiredStart.length(), addr.length() - toEmailRequiredEnd.length()); if (tokenEncoder.couldBeToken(middle)) { return middle; } } } if (noReplyFound) { return null; } } throw new ValidationException("Cannot find To address for the system with an address tag."); } MessageProcessor(final MessageContentExtractor inMessageContentExtractor,
            final ActionSelectorFactory inActionSelector, final ActionController inServiceActionController,
            final BeanFactory inBeanFactory, final TokenEncoder inTokenEncoder,
            final TokenContentFormatter inTokenContentFormatter, final PlatformTransactionManager inTransactionMgr,
            final DomainMapper<String, Long> inPersonIdByEmailDao, final DomainMapper<Long, byte[]> inUserKeyByIdDao,
            final DomainMapper<Long, PersonModelView> inPersonDao, final MessageReplier inMessageReplier,
            final String inRequiredToAddress); }
MessageProcessor { String getToken(final Message message) throws MessagingException { Address[] addresses = message.getRecipients(RecipientType.TO); if (addresses != null) { boolean noReplyFound = false; for (int i = 0; i < addresses.length; i++) { String addr = ((InternetAddress) addresses[i]).getAddress(); if (requiredToAddress.equals(addr)) { noReplyFound = true; } else if (addr.startsWith(toEmailRequiredStart) && addr.endsWith(toEmailRequiredEnd)) { String middle = addr.substring(toEmailRequiredStart.length(), addr.length() - toEmailRequiredEnd.length()); if (tokenEncoder.couldBeToken(middle)) { return middle; } } } if (noReplyFound) { return null; } } throw new ValidationException("Cannot find To address for the system with an address tag."); } MessageProcessor(final MessageContentExtractor inMessageContentExtractor,
            final ActionSelectorFactory inActionSelector, final ActionController inServiceActionController,
            final BeanFactory inBeanFactory, final TokenEncoder inTokenEncoder,
            final TokenContentFormatter inTokenContentFormatter, final PlatformTransactionManager inTransactionMgr,
            final DomainMapper<String, Long> inPersonIdByEmailDao, final DomainMapper<Long, byte[]> inUserKeyByIdDao,
            final DomainMapper<Long, PersonModelView> inPersonDao, final MessageReplier inMessageReplier,
            final String inRequiredToAddress); boolean execute(final Message message, final List<Message> inResponseMessages); }
MessageProcessor { String getToken(final Message message) throws MessagingException { Address[] addresses = message.getRecipients(RecipientType.TO); if (addresses != null) { boolean noReplyFound = false; for (int i = 0; i < addresses.length; i++) { String addr = ((InternetAddress) addresses[i]).getAddress(); if (requiredToAddress.equals(addr)) { noReplyFound = true; } else if (addr.startsWith(toEmailRequiredStart) && addr.endsWith(toEmailRequiredEnd)) { String middle = addr.substring(toEmailRequiredStart.length(), addr.length() - toEmailRequiredEnd.length()); if (tokenEncoder.couldBeToken(middle)) { return middle; } } } if (noReplyFound) { return null; } } throw new ValidationException("Cannot find To address for the system with an address tag."); } MessageProcessor(final MessageContentExtractor inMessageContentExtractor,
            final ActionSelectorFactory inActionSelector, final ActionController inServiceActionController,
            final BeanFactory inBeanFactory, final TokenEncoder inTokenEncoder,
            final TokenContentFormatter inTokenContentFormatter, final PlatformTransactionManager inTransactionMgr,
            final DomainMapper<String, Long> inPersonIdByEmailDao, final DomainMapper<Long, byte[]> inUserKeyByIdDao,
            final DomainMapper<Long, PersonModelView> inPersonDao, final MessageReplier inMessageReplier,
            final String inRequiredToAddress); boolean execute(final Message message, final List<Message> inResponseMessages);  }