CommentNotificationEventListener implements CaseEventListener, Cacheable { protected List<String> extractMentionedRoles(String commentText) { List<String> foundMentions = new ArrayList<>(); Matcher matcher = mentionPattern.matcher(commentText); while (matcher.find()) { String mention = matcher.group(0).substring(1); foundMentions.add(mention); } return foundMentions; } CommentNotificationEventListener();  CommentNotificationEventListener(String sender, String template, String subject); @Override void afterCaseCommentAdded(CaseCommentEvent event); @Override void afterCaseCommentUpdated(CaseCommentEvent event); void addPublisher(NotificationPublisher publisher); @Override void close(); static final String DEFAULT_SENDER; static final String DEFAULT_TEMPLATE; static final String DEFAULT_SUBJECT; static final String CASE_ID_PARAM; static final String AUTHOR_PARAM; static final String COMMENT_PARAM; static final String COMMENT_ID_PARAM; static final String CREATED_AT_PARAM; }
@Test public void testFindMentionsNoMentionsInComment() { String commentText = "just a plain text without mentioning any role"; CommentNotificationEventListener listener = new CommentNotificationEventListener(); List<String> found = listener.extractMentionedRoles(commentText); assertThat(found).isEmpty(); }
@Test public void testFindMentionsSingleMentionsInComment() { String commentText = "just a plain text mentioning @owner only"; CommentNotificationEventListener listener = new CommentNotificationEventListener(); List<String> found = listener.extractMentionedRoles(commentText); assertThat(found).hasSize(1); assertThat(found).contains("owner"); }
@Test public void testFindMentionsMultipleMentionsInComment() { String commentText = "@owner could you please get in touch with @manager regarding your vacation?"; CommentNotificationEventListener listener = new CommentNotificationEventListener(); List<String> found = listener.extractMentionedRoles(commentText); assertThat(found).hasSize(2); assertThat(found).contains("owner"); assertThat(found).contains("manager"); }