final ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", "myBusinessKey");
assertEquals(1, historyService.createHistoricProcessInstanceQuery().unfinished().count());
assertEquals(0, historyService.createHistoricProcessInstanceQuery().finished().count());
HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
assertEquals(now, historicProcessInstance.getStartTime());
List<Task> tasks = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
assertEquals(1, tasks.size());
// in this test scenario we assume that one year after the process start, the
// user completes the task (incredible speedy!)
cal.add(Calendar.YEAR, 1);
Date oneYearLater = cal.getTime();
ClockUtil.setCurrentTime(oneYearLater);
taskService.complete(tasks.get(0).getId());
historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
assertEquals(now, historicProcessInstance.getStartTime());
assertEquals(oneYearLater, historicProcessInstance.getEndTime());
assertTrue(historicProcessInstance.getDurationInMillis() >= ONE_YEAR);
assertTrue(((HistoricProcessInstanceEventEntity)historicProcessInstance).getDurationRaw() >= ONE_YEAR);
assertEquals(0, historyService.createHistoricProcessInstanceQuery().unfinished().count());
assertEquals(1, historyService.createHistoricProcessInstanceQuery().finished().count());
}