### Question:
PisCommonPaymentServiceInternal implements PisCommonPaymentService { @Override @Transactional public CmsResponse<PisCommonPaymentResponse> getCommonPaymentById(String paymentId) { Optional<PisCommonPaymentData> paymentOptional = pisCommonPaymentDataRepository.findByPaymentId(paymentId); if (paymentOptional.isPresent()) { List<AuthorisationEntity> authorisations = authorisationRepository.findAllByParentExternalIdAndTypeIn(paymentId, EnumSet.of(AuthorisationType.PIS_CREATION, AuthorisationType.PIS_CANCELLATION)); Optional<PisCommonPaymentResponse> responseOptional = paymentOptional .map(pisCommonPaymentConfirmationExpirationService::checkAndUpdateOnConfirmationExpiration) .flatMap(p -> pisCommonPaymentMapper.mapToPisCommonPaymentResponse(p, authorisations)); if (responseOptional.isPresent()) { PisCommonPaymentResponse pisCommonPaymentResponse = responseOptional.get(); transferCorePaymentToCommonPayment(pisCommonPaymentResponse, paymentOptional.get()); return CmsResponse.<PisCommonPaymentResponse>builder() .payload(pisCommonPaymentResponse) .build(); } } log.info("Payment ID: [{}]. Get common payment by ID failed, because payment was not found by the ID", paymentId); return CmsResponse.<PisCommonPaymentResponse>builder() .error(LOGICAL_ERROR) .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 getCommonPaymentById_success() { when(pisCommonPaymentDataRepository.findByPaymentId(PAYMENT_ID)).thenReturn(Optional.of(pisCommonPaymentData)); when(pisCommonPaymentConfirmationExpirationService.checkAndUpdateOnConfirmationExpiration(pisCommonPaymentData)) .thenReturn(pisCommonPaymentData); PisCommonPaymentResponse pisCommonPaymentResponse = new PisCommonPaymentResponse(); List<AuthorisationEntity> authorisations = buildAuthorisations(); when(authorisationRepository.findAllByParentExternalIdAndTypeIn(PAYMENT_ID, EnumSet.of(AuthorisationType.PIS_CREATION, AuthorisationType.PIS_CANCELLATION))) .thenReturn(authorisations); when(pisCommonPaymentMapper.mapToPisCommonPaymentResponse(pisCommonPaymentData, authorisations)) .thenReturn(Optional.of(pisCommonPaymentResponse)); CmsResponse<PisCommonPaymentResponse> actual = pisCommonPaymentService.getCommonPaymentById(PAYMENT_ID); assertTrue(actual.isSuccessful()); assertEquals(pisCommonPaymentResponse, actual.getPayload()); }
@Test void getCommonPaymentById_logicalError() { when(pisCommonPaymentDataRepository.findByPaymentId(PAYMENT_ID)).thenReturn(Optional.of(pisCommonPaymentData)); when(pisCommonPaymentConfirmationExpirationService.checkAndUpdateOnConfirmationExpiration(pisCommonPaymentData)) .thenReturn(pisCommonPaymentData); CmsResponse<PisCommonPaymentResponse> actual = pisCommonPaymentService.getCommonPaymentById(PAYMENT_ID); assertTrue(actual.hasError()); assertEquals(CmsError.LOGICAL_ERROR, actual.getError()); }