### Question:
DefaultCustomCertificateAccessor implements CustomCertificateAccessor { @Override public CustomCertificateModel storeCertificate(CustomCertificateModel certificateModel) throws AlertDatabaseConstraintException { if (null == certificateModel) { throw new AlertDatabaseConstraintException("The certificate model cannot be null"); } String alias = certificateModel.getAlias(); if (StringUtils.isBlank(alias)) { throw new AlertDatabaseConstraintException("The field 'alias' cannot be blank"); } String certificateContent = certificateModel.getCertificateContent(); if (StringUtils.isBlank(certificateContent)) { throw new AlertDatabaseConstraintException("The field 'certificateContent' cannot be blank"); } CustomCertificateEntity entityToSave = new CustomCertificateEntity(alias, certificateContent, DateUtils.createCurrentDateTimestamp()); Long id = certificateModel.getNullableId(); if (null == id) { id = customCertificateRepository.findByAlias(alias).map(CustomCertificateEntity::getId).orElse(null); } else { if (!customCertificateRepository.existsById(id)) { throw new AlertDatabaseConstraintException("A custom certificate with that id did not exist"); } } entityToSave.setId(id); CustomCertificateEntity updatedEntity = customCertificateRepository.save(entityToSave); return createModel(updatedEntity); } @Autowired  DefaultCustomCertificateAccessor(CustomCertificateRepository customCertificateRepository); @Override List<CustomCertificateModel> getCertificates(); @Override Optional<CustomCertificateModel> getCertificate(Long id); @Override CustomCertificateModel storeCertificate(CustomCertificateModel certificateModel); @Override void deleteCertificate(String certificateAlias); @Override void deleteCertificate(Long certificateId);  }### Answer:
@Test public void storeCertificateTest() throws Exception { CustomCertificateModel certificateModel = new CustomCertificateModel(alias, content, testDate.toString()); CustomCertificateRepository customCertificateRepository = new MockCustomCertificateRepository(); DefaultCustomCertificateAccessor customCertificateAccessor = new DefaultCustomCertificateAccessor(customCertificateRepository); CustomCertificateModel customCertificateModel = customCertificateAccessor.storeCertificate(certificateModel); testCustomCertificateModel(expectedCustomCertificateModel, customCertificateModel); }
@Test public void storeCertificateNullTest() throws Exception { CustomCertificateRepository customCertificateRepository = new MockCustomCertificateRepository(); DefaultCustomCertificateAccessor customCertificateAccessor = new DefaultCustomCertificateAccessor(customCertificateRepository); try { customCertificateAccessor.storeCertificate(null); fail(); } catch (AlertDatabaseConstraintException e) { assertNotNull(e); } }
@Test public void storeCertificateBlankValuesTest() throws Exception { CustomCertificateRepository customCertificateRepository = new MockCustomCertificateRepository(); DefaultCustomCertificateAccessor customCertificateAccessor = new DefaultCustomCertificateAccessor(customCertificateRepository); try { CustomCertificateModel certificateModel = new CustomCertificateModel("", content, testDate.toString()); customCertificateAccessor.storeCertificate(certificateModel); fail(); } catch (AlertDatabaseConstraintException e) { assertNotNull(e); } try { CustomCertificateModel certificateModel = new CustomCertificateModel(alias, "", testDate.toString()); customCertificateAccessor.storeCertificate(certificateModel); fail(); } catch (AlertDatabaseConstraintException e) { assertNotNull(e); } }
@Test public void storeCertificateIdDoesNotExistTest() throws Exception { CustomCertificateRepository customCertificateRepository = new MockCustomCertificateRepository(); DefaultCustomCertificateAccessor customCertificateAccessor = new DefaultCustomCertificateAccessor(customCertificateRepository); try { CustomCertificateModel certificateModel = new CustomCertificateModel(9L, alias, content, testDate.toString()); customCertificateAccessor.storeCertificate(certificateModel); fail(); } catch (AlertDatabaseConstraintException e) { assertNotNull(e); } }