### Question:
NotConfirmedConsentExpirationScheduleTask { @Scheduled(cron = "${xs2a.cms.not-confirmed-consent-expiration.cron.expression}") @Transactional public void obsoleteNotConfirmedConsentIfExpired() { log.info("Not confirmed consent expiration schedule task is run!"); List<ConsentEntity> expiredNotConfirmedConsents = consentJpaRepository.findByConsentStatusIn(EnumSet.of(ConsentStatus.RECEIVED, ConsentStatus.PARTIALLY_AUTHORISED)) .stream() .filter(aisConsentConfirmationExpirationService::isConfirmationExpired) .collect(Collectors.toList()); if (CollectionUtils.isNotEmpty(expiredNotConfirmedConsents)) { aisConsentConfirmationExpirationService.updateConsentListOnConfirmationExpiration(expiredNotConfirmedConsents); } }  @Scheduled(cron = "${xs2a.cms.not-confirmed-consent-expiration.cron.expression}") @Transactional void obsoleteNotConfirmedConsentIfExpired();  }### Answer:
@Test void obsoleteNotConfirmedConsentIfExpired() { List<ConsentEntity> aisConsents = new ArrayList<>(); aisConsents.add(new ConsentEntity()); aisConsents.add(new ConsentEntity()); when(consentJpaRepository.findByConsentStatusIn(EnumSet.of(ConsentStatus.RECEIVED, ConsentStatus.PARTIALLY_AUTHORISED))) .thenReturn(aisConsents); when(aisConsentConfirmationExpirationService.isConfirmationExpired(any(ConsentEntity.class))) .thenReturn(true, false); when(aisConsentConfirmationExpirationService.updateConsentListOnConfirmationExpiration(consentsCaptor.capture())) .thenReturn(Collections.emptyList()); scheduleTask.obsoleteNotConfirmedConsentIfExpired(); verify(consentJpaRepository, times(1)).findByConsentStatusIn(EnumSet.of(ConsentStatus.RECEIVED, ConsentStatus.PARTIALLY_AUTHORISED)); verify(aisConsentConfirmationExpirationService, times(2)).isConfirmationExpired(any(ConsentEntity.class)); verify(aisConsentConfirmationExpirationService, times(1)).updateConsentListOnConfirmationExpiration(anyList()); assertEquals(1, consentsCaptor.getValue().size()); }
@Test void obsoleteNotConfirmedConsentIfExpired_emptyList() { when(consentJpaRepository.findByConsentStatusIn(EnumSet.of(ConsentStatus.RECEIVED, ConsentStatus.PARTIALLY_AUTHORISED))) .thenReturn(Collections.emptyList()); scheduleTask.obsoleteNotConfirmedConsentIfExpired(); verify(consentJpaRepository, times(1)).findByConsentStatusIn(EnumSet.of(ConsentStatus.RECEIVED, ConsentStatus.PARTIALLY_AUTHORISED)); verify(aisConsentConfirmationExpirationService, never()).isConfirmationExpired(any(ConsentEntity.class)); verify(aisConsentConfirmationExpirationService, never()).updateConsentListOnConfirmationExpiration(anyList()); }