### Question:
NotConfirmedPaymentExpirationScheduleTask { @Scheduled(cron = "${xs2a.cms.not-confirmed-payment-expiration.cron.expression}") @Transactional public void obsoleteNotConfirmedPaymentIfExpired() { log.info("Not confirmed payment expiration schedule task is run!"); List<PisCommonPaymentData> expiredNotConfirmedPaymentDatas = paymentDataRepository.findByTransactionStatusIn(EnumSet.of(TransactionStatus.RCVD, TransactionStatus.PATC)) .stream() .filter(pisCommonPaymentConfirmationExpirationService::isConfirmationExpired) .collect(Collectors.toList()); if (CollectionUtils.isNotEmpty(expiredNotConfirmedPaymentDatas)) { pisCommonPaymentConfirmationExpirationService.updatePaymentDataListOnConfirmationExpiration(expiredNotConfirmedPaymentDatas); } }  @Scheduled(cron = "${xs2a.cms.not-confirmed-payment-expiration.cron.expression}") @Transactional void obsoleteNotConfirmedPaymentIfExpired();  }### Answer:
@Test void obsoleteNotConfirmedPaymentIfExpired() { List<PisCommonPaymentData> pisCommonPaymentDataList = new ArrayList<>(); pisCommonPaymentDataList.add(new PisCommonPaymentData()); pisCommonPaymentDataList.add(new PisCommonPaymentData()); when(paymentDataRepository.findByTransactionStatusIn(EnumSet.of(TransactionStatus.RCVD, TransactionStatus.PATC))) .thenReturn(pisCommonPaymentDataList); when(pisCommonPaymentConfirmationExpirationService.isConfirmationExpired(any(PisCommonPaymentData.class))) .thenReturn(true, false); when(pisCommonPaymentConfirmationExpirationService.updatePaymentDataListOnConfirmationExpiration(commonPaymentDataCaptor.capture())) .thenReturn(Collections.emptyList()); scheduleTask.obsoleteNotConfirmedPaymentIfExpired(); verify(paymentDataRepository, times(1)).findByTransactionStatusIn(EnumSet.of(TransactionStatus.RCVD, TransactionStatus.PATC)); verify(pisCommonPaymentConfirmationExpirationService, times(2)).isConfirmationExpired(any(PisCommonPaymentData.class)); verify(pisCommonPaymentConfirmationExpirationService, times(1)).updatePaymentDataListOnConfirmationExpiration(anyList()); assertEquals(1, commonPaymentDataCaptor.getValue().size()); }
@Test void obsoleteNotConfirmedPaymentIfExpired_emptyList() { when(paymentDataRepository.findByTransactionStatusIn(EnumSet.of(TransactionStatus.RCVD, TransactionStatus.PATC))) .thenReturn(Collections.emptyList()); scheduleTask.obsoleteNotConfirmedPaymentIfExpired(); verify(paymentDataRepository, times(1)).findByTransactionStatusIn(EnumSet.of(TransactionStatus.RCVD, TransactionStatus.PATC)); verify(pisCommonPaymentConfirmationExpirationService, never()).isConfirmationExpired(any(PisCommonPaymentData.class)); verify(pisCommonPaymentConfirmationExpirationService, never()).updatePaymentDataListOnConfirmationExpiration(anyList()); }