### Question:
NotificationManager { @Transactional(propagation = Propagation.REQUIRED) public List<PipelineRun> notifyLongPausedRunsBeforeStop(final List<PipelineRun> pausedRuns) { return createNotificationsForLongPausedRuns(pausedRuns, NotificationType.LONG_PAUSED_STOPPED); }  @Transactional(propagation = Propagation.REQUIRED) void notifyLongRunningTask(PipelineRun run, Long duration, NotificationSettings settings); @Transactional(propagation = Propagation.REQUIRED) void notifyIssue(Issue issue, AbstractSecuredEntity entity, String htmlText); @Transactional(propagation = Propagation.REQUIRED) void notifyIssueComment(IssueComment comment, Issue issue, String htmlText); @Transactional(propagation = Propagation.REQUIRED) void notifyRunStatusChanged(PipelineRun pipelineRun); @Transactional(propagation = Propagation.REQUIRED) void notifyIdleRuns(List<Pair<PipelineRun, Double>> pipelineCpuRatePairs,
                               NotificationType notificationType); @Transactional(propagation = Propagation.REQUIRED) void notifyHighResourceConsumingRuns(
            final List<Pair<PipelineRun, Map<ELKUsageMetric, Double>>> pipelinesMetrics,
            final NotificationType notificationType); @Transactional(propagation = Propagation.REQUIRED) void notifyStuckInStatusRuns(final List<PipelineRun> runs); @Transactional(propagation = Propagation.REQUIRED) void notifyLongPausedRuns(final List<PipelineRun> pausedRuns); @Transactional(propagation = Propagation.REQUIRED) List<PipelineRun> notifyLongPausedRunsBeforeStop(final List<PipelineRun> pausedRuns); @Transactional(propagation = Propagation.REQUIRED) NotificationMessage createNotification(final NotificationMessageVO messageVO); @Transactional(propagation = Propagation.REQUIRED) void removeNotificationTimestamps(final Long runId); @Transactional(propagation = Propagation.REQUIRED) void removeNotificationTimestampsByPipelineId(final Long id); Optional<NotificationTimestamp> loadLastNotificationTimestamp(final Long runId,
                                                                         final NotificationType type);  }### Answer:
@Test public void shouldCreateNotificationForStopLongPausedRuns() { final PipelineRun runningRun = createTestPipelineRun(); final PipelineRun pausedRun = buildPausedRun(DateUtils.nowUTC().minusSeconds(LONG_PAUSED_SECONDS)); notificationManager.notifyLongPausedRunsBeforeStop(Arrays.asList(runningRun, pausedRun)); final List<NotificationMessage> messages = monitoringNotificationDao.loadAllNotifications(); Assert.assertEquals(1, messages.size()); Assert.assertEquals(messages.get(0).getTemplate().getId(), stopLongPausedTemplate.getId()); }
@Test public void shouldNotCreateNotificationForStopLongPausedRunsIfNotTimeout() { final PipelineRun pausedRun = buildPausedRun(DateUtils.nowUTC().plusSeconds(LONG_PAUSED_SECONDS)); notificationManager.notifyLongPausedRunsBeforeStop(Collections.singletonList(pausedRun)); final List<NotificationMessage> messages = monitoringNotificationDao.loadAllNotifications(); Assert.assertEquals(0, messages.size()); }
@Test public void shouldNotNotifyIfInstanceTypeShouldExcluded() { final Preference preference = new Preference(); preference.setName(SystemPreferences.SYSTEM_NOTIFICATIONS_EXCLUDE_INSTANCE_TYPES.getKey()); preference.setValue("r5.*,m5.large"); preferenceManager.update(Collections.singletonList(preference)); final LocalDateTime statusUpdateTime = DateUtils.nowUTC().minusSeconds(LONG_PAUSED_SECONDS); final PipelineRun pausedRunToExclude1 = buildPausedRunWithNodeType(statusUpdateTime, "m5.large"); final PipelineRun pausedRunToExclude2 = buildPausedRunWithNodeType(statusUpdateTime, "r5.large"); final PipelineRun pausedRunToInclude = buildPausedRunWithNodeType(statusUpdateTime, "c5.xlarge"); final List<PipelineRun> filtered = notificationManager.notifyLongPausedRunsBeforeStop(Arrays.asList( pausedRunToExclude1, pausedRunToExclude2, pausedRunToInclude)); Assert.assertEquals(1, filtered.size()); Assert.assertEquals(pausedRunToInclude.getId(), filtered.get(0).getId()); }