@Test public void should_map_form_to_entity() throws Exception { List<ReportParameter> parameters = Collections.singletonList( new ReportParameter("key", Collections.singleton("value"))); JobSource source = new JobSource.Builder() .withUri("/my/uri") .withParameters(parameters) .build(); JobFormEntity mappedEntity = formFactory.givenNewJobFormEntity(); JobForm preparedForm = formFactory.givenJobFormBuilderWithValues() .withJobSource(source) .build(); mapperUnderTest.mapFormOnEntity(preparedForm, mappedEntity); assertThat(mappedEntity.getSourceUri(), is("/my/uri")); Map<String, Set<String>> params = mappedEntity.getSourceParameters(); Collection<String> values = new ArrayList<>(); for (Map.Entry<String, Set<String>> entry : params.entrySet()) { values.addAll(entry.getValue()); } assertThat(params.keySet(), hasItem("key")); assertThat(values, hasItem("value")); }
@Override public void mapFormOnEntity(JobForm form, JobFormEntity entity) { JobSource source = form.getSource(); List<ReportParameter> params = source.getParameters(); Map<String, Set<String>> values = mapSourceParamValues(params); entity.setSourceUri(source.getUri()); entity.setSourceParameters(values); }
JobSourceMapper extends JobMapper { @Override public void mapFormOnEntity(JobForm form, JobFormEntity entity) { JobSource source = form.getSource(); List<ReportParameter> params = source.getParameters(); Map<String, Set<String>> values = mapSourceParamValues(params); entity.setSourceUri(source.getUri()); entity.setSourceParameters(values); } }
JobSourceMapper extends JobMapper { @Override public void mapFormOnEntity(JobForm form, JobFormEntity entity) { JobSource source = form.getSource(); List<ReportParameter> params = source.getParameters(); Map<String, Set<String>> values = mapSourceParamValues(params); entity.setSourceUri(source.getUri()); entity.setSourceParameters(values); }  }
JobSourceMapper extends JobMapper { @Override public void mapFormOnEntity(JobForm form, JobFormEntity entity) { JobSource source = form.getSource(); List<ReportParameter> params = source.getParameters(); Map<String, Set<String>> values = mapSourceParamValues(params); entity.setSourceUri(source.getUri()); entity.setSourceParameters(values); }  @Override void mapFormOnEntity(JobForm form, JobFormEntity entity); @Override void mapEntityOnForm(JobForm.Builder form, JobFormEntity entity); }
JobSourceMapper extends JobMapper { @Override public void mapFormOnEntity(JobForm form, JobFormEntity entity) { JobSource source = form.getSource(); List<ReportParameter> params = source.getParameters(); Map<String, Set<String>> values = mapSourceParamValues(params); entity.setSourceUri(source.getUri()); entity.setSourceParameters(values); }  @Override void mapFormOnEntity(JobForm form, JobFormEntity entity); @Override void mapEntityOnForm(JobForm.Builder form, JobFormEntity entity);  }