### Question:
CommonPaymentDataService { public Optional<PisCommonPaymentData> getPisCommonPaymentData(String paymentId, @Nullable String instanceId) { Specification<PisCommonPaymentData> specification = Optional.ofNullable(instanceId) .map(i -> pisCommonPaymentDataSpecification.byPaymentIdAndInstanceId(paymentId, i)) .orElseGet(() -> pisCommonPaymentDataSpecification.byPaymentId(paymentId)); return pisCommonPaymentDataRepository.findOne(specification); }  Optional<PisCommonPaymentData> getPisCommonPaymentData(String paymentId, @Nullable String instanceId); @Transactional boolean updateStatusInPaymentData(PisCommonPaymentData paymentData, TransactionStatus status); @Transactional boolean updateCancelTppRedirectURIs(PisCommonPaymentData paymentData, @NotNull TppRedirectUri tppRedirectUri); @Transactional boolean updatePaymentCancellationInternalRequestId(PisCommonPaymentData paymentData, @NotNull String internalRequestId);  }### Answer:
@Test void getPisCommonPaymentData() { when(pisCommonPaymentDataSpecification.byPaymentIdAndInstanceId("payment_id", "instance_id")).thenReturn((root, criteriaQuery, criteriaBuilder) -> null); when(pisCommonPaymentDataRepository.findOne(any(Specification.class))).thenReturn(Optional.of(new PisCommonPaymentData())); Optional<PisCommonPaymentData> pisCommonPaymentData = commonPaymentDataService.getPisCommonPaymentData("payment_id", "instance_id"); assertTrue(pisCommonPaymentData.isPresent()); }
@Test void getPisCommonPaymentData_instanceIdNotPassed() { when(pisCommonPaymentDataSpecification.byPaymentId("payment_id")).thenReturn((root, criteriaQuery, criteriaBuilder) -> null); when(pisCommonPaymentDataRepository.findOne(any(Specification.class))).thenReturn(Optional.of(new PisCommonPaymentData())); Optional<PisCommonPaymentData> pisCommonPaymentData = commonPaymentDataService.getPisCommonPaymentData("payment_id", null); assertTrue(pisCommonPaymentData.isPresent()); }