@Test public void shouldNotSendEmailWhenValidationFailed() { // given final ShareService.ValidateShareIssueResult validationResult = getShareIssueValidationResult(user, shareBean, issue); final NotificationRecipient userRecipient = recipientFromUserName("username"); final NotificationRecipient mailRecipient = recipientFromEmail("*****@*****.**"); final List<NotificationRecipient> notificationRecipients = Lists.newArrayList(userRecipient, mailRecipient); when(notificationRecipientUtil.getRecipients(shareBean)).thenReturn(notificationRecipients); final AdhocNotificationService.ValidateNotificationResult userNotification = expectNotificationToRecipient(userRecipient); addSomeErrors(userNotification); final AdhocNotificationService.ValidateNotificationResult mailNotification = expectNotificationToRecipient(mailRecipient); addSomeErrors(mailNotification); // when shareIssueService.shareIssue(validationResult); // then verify(notificationService, times(0)) .sendNotification(any(AdhocNotificationService.ValidateNotificationResult.class)); }
@Test public void shouldPublishEventWhenShareIssueSent() throws Exception { // given final ShareService.ValidateShareIssueResult validationResult = getShareIssueValidationResult(user, shareBean, issue); // when shareIssueService.shareIssue(validationResult); // then verify(eventPublisher).publish(any(ShareIssueEvent.class)); }
@Test public void shouldSendMailToUsersAndEmailAddresses() { // given final ShareService.ValidateShareIssueResult validationResult = getShareIssueValidationResult(user, shareBean, issue); final NotificationRecipient userRecipient = recipientFromUserName("username"); final NotificationRecipient mailRecipient = recipientFromEmail("*****@*****.**"); final List<NotificationRecipient> notificationRecipients = Lists.newArrayList(userRecipient, mailRecipient); when(notificationRecipientUtil.getRecipients(shareBean)).thenReturn(notificationRecipients); final AdhocNotificationService.ValidateNotificationResult userNotification = expectNotificationToRecipient(userRecipient); final AdhocNotificationService.ValidateNotificationResult mailNotification = expectNotificationToRecipient(mailRecipient); // when shareIssueService.shareIssue(validationResult); // then verify(notificationService).sendNotification(userNotification); verify(notificationService).sendNotification(mailNotification); }