CaseInstanceMapper implements Function<CaseInstance, CaseInstanceSummary> { @Override public CaseInstanceSummary apply(final CaseInstance ci) { if (ci == null) { return null; } return CaseInstanceSummary.builder(). caseId(ci.getCaseId()). description(ci.getCaseDescription()). status(CaseStatus.fromId(ci.getCaseStatus())). containerId(ci.getContainerId()). owner(ci.getCaseOwner()). startedAt(ci.getStartedAt()). completedAt(ci.getCompletedAt()). caseDefinitionId(ci.getCaseDefinitionId()). roleAssignments( ofNullable(ci.getRoleAssignments()).orElse(emptyList()) .stream() .map(new RoleAssignmentsMapper()) .collect(toList())). stages( ofNullable(ci.getStages()).orElse(emptyList()) .stream() .map(new CaseStageMapper()) .collect(toList())). build(); }  @Override CaseInstanceSummary apply(final CaseInstance ci);  }
@Test public void testCaseInstanceMapper_mapCaseInstance() { final CaseInstance ci = createCaseInstance(); final List<CaseStage> stagesList = new ArrayList(); final List<CaseAdHocFragment> stageAdHocFragments = new ArrayList(); stageAdHocFragments.add(CaseAdHocFragment.builder().name("ad_hoc_stage_f1_name").build()); stageAdHocFragments.add(CaseAdHocFragment.builder().name("ad_hoc_stage_f2_name").build()); stagesList.add(CaseStage.builder().name("stage1").status("Available").id("stage1").adHocFragments(stageAdHocFragments).build()); stagesList.add(CaseStage.builder().name("stage2").status("Completed").id("stage2").build()); ci.setStages(stagesList); final CaseInstanceSummary cis = new CaseInstanceMapper().apply(ci); assertCaseInstance(ci, cis); }
@Test public void testCaseInstanceMapper_mapNull() { final CaseInstance ci = null; final CaseInstanceSummary cis = new CaseInstanceMapper().apply(ci); assertNull(cis); }