WorkItemSummaryMapper implements Function<WorkItemInstance, WorkItemSummary> { @Override public WorkItemSummary apply(final WorkItemInstance workItemInstance) { final Optional<WorkItemInstance> request = ofNullable(workItemInstance); if (request.isPresent() == false) { return null; } WorkItemSummary summary = WorkItemSummary.builder() .id(workItemInstance.getId()) .name(workItemInstance.getName()) .state(workItemInstance.getState()) .parameters(request.map(r -> r.getParameters()) .orElse(emptyMap()) .entrySet() .stream() .map(e -> new WorkItemParameterSummary(e.getKey(), String.valueOf(e.getValue()))) .collect(toList())) .build(); return summary; }  @Override WorkItemSummary apply(final WorkItemInstance workItemInstance);  }
@Test public void testWorkItemSummaryMapper_mapWorkItemSummary() { final WorkItemInstance workItemInstance = WorkItemInstance.builder() .id(1L) .name("Human Task") .parameters(singletonMap("initiator", "String")) .build(); assertWorkItemSummary(workItemInstance, new WorkItemSummaryMapper().apply(workItemInstance)); }
@Test public void testWorkItemSummaryMapper_mapNull() { assertNull(new WorkItemSummaryMapper().apply(null)); }