ImporterUtils { static void populateEntity(RevocableCertificate entity, CertificateDTO dto) { if (entity == null) { throw new IllegalArgumentException("the certificate model entity is null"); } if (dto == null) { throw new IllegalArgumentException("the certificate dto is null"); } entity.setKey(dto.getKey()); entity.setCert(dto.getCertificate()); entity.setUpdated(dto.getUpdated()); entity.setCreated(dto.getCreated()); if (dto.getSerial() != null) { CertificateSerialDTO dtoSerial = dto.getSerial(); CertificateSerial entitySerial = new CertificateSerial(); entitySerial.setCollected(dtoSerial.isCollected()); entitySerial.setExpiration(dtoSerial.getExpiration()); entitySerial.setRevoked(dtoSerial.isRevoked()); entitySerial.setCreated(dtoSerial.getCreated()); entitySerial.setUpdated(dtoSerial.getUpdated()); entity.setSerial(entitySerial); } } private  ImporterUtils();   }
@Test public void populateFullyPopulatedCertificate() { RevocableCertificate certEntity = new CdnCertificate(); CertificateSerialDTO serialDTO = new CertificateSerialDTO(); serialDTO.setUpdated(new Date()); serialDTO.setCreated(new Date()); serialDTO.setRevoked(false); serialDTO.setCollected(true); serialDTO.setExpiration(new Date()); certDTO.setSerial(serialDTO); ImporterUtils.populateEntity(certEntity, certDTO); assertEquals(certDTO.getCertificate(), certEntity.getCert()); assertEquals(certDTO.getKey(), certEntity.getKey()); assertEquals(certDTO.getUpdated(), certEntity.getUpdated()); assertEquals(certDTO.getCreated(), certEntity.getCreated()); CertificateSerial certSerialEntity = certEntity.getSerial(); assertNotNull(certSerialEntity); assertEquals(serialDTO.getExpiration(), certSerialEntity.getExpiration()); assertEquals(serialDTO.isCollected(), certSerialEntity.isCollected()); assertEquals(serialDTO.isRevoked(), certSerialEntity.isRevoked()); assertEquals(serialDTO.getCreated(), certSerialEntity.getCreated()); assertEquals(serialDTO.getUpdated(), certSerialEntity.getUpdated()); }