ViolationEntityToDtoConverter implements Converter<ViolationEntity, Violation> { @Override public Violation convert(final ViolationEntity source) { final Violation violation = new Violation(); violation.setId(source.getId()); violation.setVersion(source.getVersion()); violation.setCreated(source.getCreated()); violation.setCreatedBy(source.getCreatedBy()); violation.setLastModified(source.getLastModified()); violation.setLastModifiedBy(source.getLastModifiedBy()); violation.setAccountId(source.getAccountId()); violation.setEventId(source.getEventId()); violation.setPluginFullyQualifiedClassName(source.getPluginFullyQualifiedClassName()); violation.setRegion(source.getRegion()); violation.setInstanceId(source.getInstanceId()); violation.setComment(source.getComment()); violation.setMetaInfo(source.getMetaInfo()); violation.setUsername(source.getUsername()); if (source.getApplication() != null) { violation.setApplicationId(source.getApplication().getName()); } if (source.getApplicationVersion() != null) { violation.setApplicationVersionId(source.getApplicationVersion().getName()); } if (source.getRuleEntity() != null) { violation.setRuleID(source.getRuleEntity().getId()); } Optional.ofNullable(source.getViolationTypeEntity()) .map(violationTypeConverter::convert) .ifPresent(violation::setViolationType); return violation; } @Autowired  ViolationEntityToDtoConverter(final Converter<ViolationTypeEntity, ViolationType> violationTypeConverter); @Override Violation convert(final ViolationEntity source);  }
@Test public void testConvertNullPointer() throws Exception { final Violation dto = entityToDto.convert(violationEntity); }
@Test public void testConvert() throws Exception { final RuleEntity ruleEntity = new RuleEntity(); ruleEntity.setId(1L); violationEntity.setRuleEntity(ruleEntity); final Violation dto = entityToDto.convert(violationEntity); assertThat(dto.getAccountId()).isEqualTo(ACCOUNT_ID); assertThat(dto.getComment()).isEqualTo(COMMENT); assertThat(dto.getRuleID()).isEqualTo(1L); }