### Question:
KycInfoService { @Transactional public KycInfo saveKycInfo(long investorId, URI kycUri) throws KycInfoNotSavedException { Optional<KycInfo> kycInfoFromDb = kycInfoRepository.findOptionalByInvestorId(investorId); if(kycInfoFromDb.isPresent()) { LOG.info("KycInfo for investor {} was already saved to database.", investorId); } else { KycInfo kycInfo; if(kycUri != null) { kycInfo = new KycInfo(investorId, false, 0, false, kycUri.toASCIIString()); } else { kycInfo = new KycInfo(investorId, false, 0, false, null); } try { kycInfoFromDb = Optional.of(kycInfoRepository.save(kycInfo)); LOG.debug("Saved kycInfo in db: investorId: {}, kycUuid: {}, isKycComplete: {}", kycInfo.getInvestorId(), kycInfo.getKycUuid(), kycInfo.isKycComplete()); } catch (DataIntegrityViolationException e) { LOG.info("KycInfo for investor was already saved to database.", investorId); kycInfoFromDb = kycInfoRepository.findById(investorId); } catch (Exception e) { LOG.error("Could not save KycInfo to database.", e); } } return kycInfoFromDb.orElseThrow(KycInfoNotSavedException::new); } @Autowired  KycInfoService(KycInfoRepository kycInfoRepository); @Transactional KycInfo saveKycInfo(long investorId, URI kycUri); @Transactional KycInfo setKycComplete(long investorId, boolean isKycComplete); @Transactional KycInfo setKycCompleteByUuid(UUID uuid, boolean isKycComplete); @Transactional KycInfo setKycUri(long investorId, String kycUri); @Transactional KycInfo setKycStartEmailSent(long investorId); @Transactional KycInfo increaseNumberOfRemindersSent(long investorId); KycInfo getKycInfoByInvestorId(long investorId); KycInfo getKycInfoByKycUuid(UUID kycUuid); List<Long> getAllInvestorIdWhereStartKycEmailSent();  }### Answer:
@Test public void testSaveKycInfo() throws URISyntaxException { try { kycInfoService.saveKycInfo(1, kycUri); } catch(KycInfoNotSavedException e) { fail(e.getMessage()); } Optional<KycInfo> oKycInfo = kycInfoRepository.findOptionalByInvestorId(1); if(oKycInfo.isPresent()) { assertKycInfo(oKycInfo.get(), 1, false, 0, false, kycUri); } else { fail("KycInfo should be present but is not."); } URI newKycUri = new URI(KYC_LINK + "doNotSaveThis"); try { kycInfoService.saveKycInfo(1, newKycUri); } catch(KycInfoNotSavedException e) { fail(e.getMessage()); } oKycInfo = kycInfoRepository.findOptionalByInvestorId(1); if(oKycInfo.isPresent()) { assertKycInfo(oKycInfo.get(), 1, false, 0, false, kycUri); } else { fail("KycInfo should be present but is not."); } }