code: @Deployment public void testHistoricTaskInstance() throws Exception {
    Map<String,Object> varMap=new HashMap<String,Object>();
    varMap.put("formKeyVar","expressionFormKey");
    String processInstanceId=runtimeService.startProcessInstanceByKey("HistoricTaskInstanceTest",varMap).getId();
    SimpleDateFormat sdf=new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
    Task runtimeTask=taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();
    runtimeTask.setPriority(1234);
    Date dueDate=sdf.parse("01/02/2003 04:05:06");
    runtimeTask.setDueDate(dueDate);
    taskService.saveTask(runtimeTask);
    String taskId=runtimeTask.getId();
    String taskDefinitionKey=runtimeTask.getTaskDefinitionKey();
    assertEquals(1,historyService.createHistoricTaskInstanceQuery().count());
    HistoricTaskInstance historicTaskInstance=historyService.createHistoricTaskInstanceQuery().singleResult();
    assertEquals(taskId,historicTaskInstance.getId());
    assertEquals(1234,historicTaskInstance.getPriority());
    assertEquals("Clean up",historicTaskInstance.getName());
    assertEquals("Schedule an engineering meeting for next week with the new hire.",historicTaskInstance.getDescription());
    assertEquals(dueDate,historicTaskInstance.getDueDate());
    assertEquals("kermit",historicTaskInstance.getAssignee());
    assertEquals(taskDefinitionKey,historicTaskInstance.getTaskDefinitionKey());
    assertEquals("expressionFormKey",historicTaskInstance.getFormKey());
    assertNull(historicTaskInstance.getEndTime());
    assertNull(historicTaskInstance.getDurationInMillis());
    assertNull(historicTaskInstance.getWorkTimeInMillis());
    runtimeService.setVariable(processInstanceId,"deadline","yesterday");
    taskService.claim(taskId,"kermit");
    assertEquals(1,historyService.createHistoricTaskInstanceQuery().count());
    historicTaskInstance=historyService.createHistoricTaskInstanceQuery().singleResult();
    assertNotNull(historicTaskInstance.getClaimTime());
    assertNull(historicTaskInstance.getWorkTimeInMillis());
    assertEquals("expressionFormKey",historicTaskInstance.getFormKey());
    taskService.complete(taskId);
    assertEquals(1,historyService.createHistoricTaskInstanceQuery().count());
    historicTaskInstance=historyService.createHistoricTaskInstanceQuery().singleResult();
    assertEquals(taskId,historicTaskInstance.getId());
    assertEquals(1234,historicTaskInstance.getPriority());
    assertEquals("Clean up",historicTaskInstance.getName());
    assertEquals("Schedule an engineering meeting for next week with the new hire.",historicTaskInstance.getDescription());
    assertEquals(dueDate,historicTaskInstance.getDueDate());
    assertEquals("kermit",historicTaskInstance.getAssignee());
    assertNull(historicTaskInstance.getDeleteReason());
    assertEquals(taskDefinitionKey,historicTaskInstance.getTaskDefinitionKey());
    assertEquals("expressionFormKey",historicTaskInstance.getFormKey());
    assertNotNull(historicTaskInstance.getEndTime());
    assertNotNull(historicTaskInstance.getDurationInMillis());
    assertNotNull(historicTaskInstance.getClaimTime());
    assertNotNull(historicTaskInstance.getWorkTimeInMillis());
    historyService.deleteHistoricTaskInstance(taskId);
    assertEquals(0,historyService.createHistoricTaskInstanceQuery().count());
  }
  