@Test public void testTransform() throws Exception { long creationTime = DATE_FORMAT.parse("2013-10-03 16:32:05").getTime(); JobData jobData = jobDataMapper.transform(mJobDescriptor, DATE_FORMAT); assertThat("Should map id", jobData.getId(), is(20)); assertThat("Should map version", jobData.getVersion(), is(2)); assertThat("Should map username", jobData.getUsername(), is("user")); assertThat("Should map label", jobData.getLabel(), is("label")); assertThat("Should map description", jobData.getDescription(), is("description")); assertThat("Should map creation date", jobData.getCreationDate().getTime(), is(creationTime)); assertThat("Should map description", jobData.getOutputFormats(), hasItem(JobOutputFormat.HTML)); }
public JobData transform(JobDescriptor jobDescriptor, SimpleDateFormat dateTimeFormat) { JobData.Builder builder = new JobData.Builder(); builder.withId(jobDescriptor.getId()); builder.withLabel(jobDescriptor.getLabel()); builder.withDescription(jobDescriptor.getDescription()); builder.withVersion(jobDescriptor.getVersion()); builder.withLabel(jobDescriptor.getLabel()); builder.withUsername(jobDescriptor.getUsername()); Date creationDate; try { creationDate = dateTimeFormat.parse(jobDescriptor.getCreationDate()); } catch (ParseException e) { creationDate = null; } builder.withCreationDate(creationDate); Collection<String> outputFormat = jobDescriptor.getOutputFormats().getOutputFormat(); List<JobOutputFormat> formats = new ArrayList<>(outputFormat.size()); for (String format : outputFormat) { formats.add(JobOutputFormat.valueOf(format)); } builder.withOutputFormats(formats); return builder.build(); }
JobDataMapper { public JobData transform(JobDescriptor jobDescriptor, SimpleDateFormat dateTimeFormat) { JobData.Builder builder = new JobData.Builder(); builder.withId(jobDescriptor.getId()); builder.withLabel(jobDescriptor.getLabel()); builder.withDescription(jobDescriptor.getDescription()); builder.withVersion(jobDescriptor.getVersion()); builder.withLabel(jobDescriptor.getLabel()); builder.withUsername(jobDescriptor.getUsername()); Date creationDate; try { creationDate = dateTimeFormat.parse(jobDescriptor.getCreationDate()); } catch (ParseException e) { creationDate = null; } builder.withCreationDate(creationDate); Collection<String> outputFormat = jobDescriptor.getOutputFormats().getOutputFormat(); List<JobOutputFormat> formats = new ArrayList<>(outputFormat.size()); for (String format : outputFormat) { formats.add(JobOutputFormat.valueOf(format)); } builder.withOutputFormats(formats); return builder.build(); } }
JobDataMapper { public JobData transform(JobDescriptor jobDescriptor, SimpleDateFormat dateTimeFormat) { JobData.Builder builder = new JobData.Builder(); builder.withId(jobDescriptor.getId()); builder.withLabel(jobDescriptor.getLabel()); builder.withDescription(jobDescriptor.getDescription()); builder.withVersion(jobDescriptor.getVersion()); builder.withLabel(jobDescriptor.getLabel()); builder.withUsername(jobDescriptor.getUsername()); Date creationDate; try { creationDate = dateTimeFormat.parse(jobDescriptor.getCreationDate()); } catch (ParseException e) { creationDate = null; } builder.withCreationDate(creationDate); Collection<String> outputFormat = jobDescriptor.getOutputFormats().getOutputFormat(); List<JobOutputFormat> formats = new ArrayList<>(outputFormat.size()); for (String format : outputFormat) { formats.add(JobOutputFormat.valueOf(format)); } builder.withOutputFormats(formats); return builder.build(); }  }
JobDataMapper { public JobData transform(JobDescriptor jobDescriptor, SimpleDateFormat dateTimeFormat) { JobData.Builder builder = new JobData.Builder(); builder.withId(jobDescriptor.getId()); builder.withLabel(jobDescriptor.getLabel()); builder.withDescription(jobDescriptor.getDescription()); builder.withVersion(jobDescriptor.getVersion()); builder.withLabel(jobDescriptor.getLabel()); builder.withUsername(jobDescriptor.getUsername()); Date creationDate; try { creationDate = dateTimeFormat.parse(jobDescriptor.getCreationDate()); } catch (ParseException e) { creationDate = null; } builder.withCreationDate(creationDate); Collection<String> outputFormat = jobDescriptor.getOutputFormats().getOutputFormat(); List<JobOutputFormat> formats = new ArrayList<>(outputFormat.size()); for (String format : outputFormat) { formats.add(JobOutputFormat.valueOf(format)); } builder.withOutputFormats(formats); return builder.build(); }  JobData transform(JobDescriptor jobDescriptor, SimpleDateFormat dateTimeFormat); }
JobDataMapper { public JobData transform(JobDescriptor jobDescriptor, SimpleDateFormat dateTimeFormat) { JobData.Builder builder = new JobData.Builder(); builder.withId(jobDescriptor.getId()); builder.withLabel(jobDescriptor.getLabel()); builder.withDescription(jobDescriptor.getDescription()); builder.withVersion(jobDescriptor.getVersion()); builder.withLabel(jobDescriptor.getLabel()); builder.withUsername(jobDescriptor.getUsername()); Date creationDate; try { creationDate = dateTimeFormat.parse(jobDescriptor.getCreationDate()); } catch (ParseException e) { creationDate = null; } builder.withCreationDate(creationDate); Collection<String> outputFormat = jobDescriptor.getOutputFormats().getOutputFormat(); List<JobOutputFormat> formats = new ArrayList<>(outputFormat.size()); for (String format : outputFormat) { formats.add(JobOutputFormat.valueOf(format)); } builder.withOutputFormats(formats); return builder.build(); }  JobData transform(JobDescriptor jobDescriptor, SimpleDateFormat dateTimeFormat);  }