### Question:
ConsentServiceInternal implements ConsentService { @Override @Transactional public CmsResponse<ConsentStatus> getConsentStatusById(String consentId) { Optional<ConsentStatus> consentStatusOptional = consentJpaRepository.findByExternalId(consentId) .map(aisConsentConfirmationExpirationService::checkAndUpdateOnConfirmationExpiration) .map(this::checkAndUpdateOnExpiration) .map(ConsentEntity::getConsentStatus); if (consentStatusOptional.isPresent()) { return CmsResponse.<ConsentStatus>builder() .payload(consentStatusOptional.get()) .build(); } else { log.info("Consent ID: [{}]. Get consent status failed, because consent not found", consentId); return CmsResponse.<ConsentStatus>builder() .error(LOGICAL_ERROR) .build(); } }  @Override @Transactional(rollbackFor = WrongChecksumException.class) CmsResponse<CmsCreateConsentResponse> createConsent(CmsConsent cmsConsent); @Override @Transactional CmsResponse<ConsentStatus> getConsentStatusById(String consentId); @Override @Transactional(rollbackFor = WrongChecksumException.class) CmsResponse<Boolean> updateConsentStatusById(String consentId, ConsentStatus status); @Override @Transactional CmsResponse<CmsConsent> getConsentById(String consentId); @Override @Transactional CmsResponse<Boolean> findAndTerminateOldConsentsByNewConsentId(String newConsentId); @Override CmsResponse<List<PsuIdData>> getPsuDataByConsentId(String consentId); @Override @Transactional(rollbackFor = WrongChecksumException.class) CmsResponse<Boolean> updateMultilevelScaRequired(String consentId, boolean multilevelScaRequired);  }### Answer:
@Test void getConsentStatusById_withValidUsedNonRecurringConsent_shouldExpireConsent() { ConsentEntity consent = buildUsedNonRecurringConsent(); when(consentJpaRepository.findByExternalId(EXTERNAL_CONSENT_ID)) .thenReturn(Optional.of(consent)); when(aisConsentConfirmationExpirationService.checkAndUpdateOnConfirmationExpiration(consent)) .thenReturn(consent); when(aisConsentConfirmationExpirationService.expireConsent(consent)).thenReturn(consent); CmsResponse<ConsentStatus> consentStatusById = consentServiceInternal.getConsentStatusById(EXTERNAL_CONSENT_ID); assertTrue(consentStatusById.isSuccessful()); verify(aisConsentConfirmationExpirationService, atLeastOnce()).expireConsent(consent); }
@Test void getConsentStatusById_noEntity_shouldReturnLogicalError() { when(consentJpaRepository.findByExternalId(EXTERNAL_CONSENT_ID)) .thenReturn(Optional.empty()); CmsResponse<ConsentStatus> actual = consentServiceInternal.getConsentStatusById(EXTERNAL_CONSENT_ID); assertLogicalError(actual); }