### Question:
PisCommonPaymentServiceInternal implements PisCommonPaymentService { @Override @Transactional public CmsResponse<Boolean> updateCommonPaymentStatusById(String paymentId, TransactionStatus status) { Optional<Boolean> isUpdatedOptional = pisCommonPaymentDataRepository.findByPaymentId(paymentId) .map(pisCommonPaymentConfirmationExpirationService::checkAndUpdateOnConfirmationExpiration) .filter(pm -> !pm.getTransactionStatus().isFinalisedStatus()) .map(pmt -> setStatusAndSaveCommonPaymentData(pmt, status)) .map(con -> con.getTransactionStatus() == status); if (isUpdatedOptional.isPresent()) { return CmsResponse.<Boolean>builder() .payload(isUpdatedOptional.get()) .build(); } log.info("Payment ID: [{}]. Update common payment by ID failed, because payment was not found by the ID", paymentId); return CmsResponse.<Boolean>builder() .payload(false) .build(); }  @Override @Transactional CmsResponse<CreatePisCommonPaymentResponse> createCommonPayment(PisPaymentInfo request); @Override @Transactional CmsResponse<TransactionStatus> getPisCommonPaymentStatusById(String paymentId); @Override @Transactional CmsResponse<PisCommonPaymentResponse> getCommonPaymentById(String paymentId); @Override @Transactional CmsResponse<Boolean> updateCommonPaymentStatusById(String paymentId, TransactionStatus status); @Override @Transactional CmsResponse<Boolean> updateMultilevelSca(String paymentId, boolean multilevelScaRequired); @Override CmsResponse<List<PsuIdData>> getPsuDataListByPaymentId(String paymentId);  }### Answer:
@Test void updateCommonPaymentStatusById_success() { when(pisCommonPaymentDataRepository.findByPaymentId(PAYMENT_ID)).thenReturn(Optional.of(pisCommonPaymentData)); when(pisCommonPaymentConfirmationExpirationService.checkAndUpdateOnConfirmationExpiration(pisCommonPaymentData)) .thenReturn(pisCommonPaymentData); CmsResponse<Boolean> actual = pisCommonPaymentService.updateCommonPaymentStatusById(PAYMENT_ID, TransactionStatus.RCVD); assertTrue(actual.isSuccessful()); assertEquals(TransactionStatus.RCVD, pisCommonPaymentData.getTransactionStatus()); verify(pisCommonPaymentDataRepository).save(pisCommonPaymentData); }
@Test void updateCommonPaymentStatusById_transactionStatusIsFinalised() { pisCommonPaymentData.setTransactionStatus(TransactionStatus.ACCC); when(pisCommonPaymentDataRepository.findByPaymentId(PAYMENT_ID)).thenReturn(Optional.of(pisCommonPaymentData)); when(pisCommonPaymentConfirmationExpirationService.checkAndUpdateOnConfirmationExpiration(pisCommonPaymentData)) .thenReturn(pisCommonPaymentData); CmsResponse<Boolean> actual = pisCommonPaymentService.updateCommonPaymentStatusById(PAYMENT_ID, TransactionStatus.RCVD); assertTrue(actual.isSuccessful()); assertFalse(actual.getPayload()); assertEquals(TransactionStatus.ACCC, pisCommonPaymentData.getTransactionStatus()); verify(pisCommonPaymentDataRepository, never()).save(any()); }