@Deployment public void testRepeatWithEnd() throws Throwable {
  Calendar calendar=Calendar.getInstance();
  Date baseTime=calendar.getTime();
  DateTimeFormatter fmt=ISODateTimeFormat.dateTime();
  calendar.setTime(baseTime);
  calendar.add(Calendar.HOUR,2);
  DateTime dt=new DateTime(calendar.getTime());
  String endDateForIntermediate1=fmt.print(dt);
  calendar.setTime(baseTime);
  calendar.add(Calendar.HOUR,1);
  calendar.add(Calendar.MINUTE,30);
  dt=new DateTime(calendar.getTime());
  String endDateForIntermediate2=fmt.print(dt);
  Calendar nextTimeCal=Calendar.getInstance();
  nextTimeCal.setTime(baseTime);
  processEngineConfiguration.getClock().setCurrentTime(nextTimeCal.getTime());
  ProcessInstance processInstance=runtimeService.startProcessInstanceByKey("repeatWithEnd");
  runtimeService.setVariable(processInstance.getId(),"EndDateForCatch1",endDateForIntermediate1);
  runtimeService.setVariable(processInstance.getId(),"EndDateForCatch2",endDateForIntermediate2);
  List<Task> tasks=taskService.createTaskQuery().list();
  assertEquals(1,tasks.size());
  tasks=taskService.createTaskQuery().list();
  assertEquals(1,tasks.size());
  Task task=tasks.get(0);
  assertEquals("Task A",task.getName());
  taskService.complete(task.getId());
  waitForJobExecutorToProcessAllJobs(2000,500);
  assertNotNull(managementService.createTimerJobQuery().processInstanceId(processInstance.getId()).singleResult());
  nextTimeCal.add(Calendar.HOUR,1);
  processEngineConfiguration.getClock().setCurrentTime(nextTimeCal.getTime());
  waitForJobExecutorToProcessAllJobs(2000,500);
  List<Job> jobs=managementService.createJobQuery().list();
  assertEquals(0,jobs.size());
  tasks=taskService.createTaskQuery().list();
  assertEquals(1,tasks.size());
  task=tasks.get(0);
  assertEquals("Task C",task.getName());
  taskService.complete(task.getId());
  nextTimeCal.add(Calendar.HOUR,1);
  processEngineConfiguration.getClock().setCurrentTime(nextTimeCal.getTime());
  waitForJobExecutorToProcessAllJobs(2000,500);
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
    HistoricProcessInstance historicInstance=historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(historicInstance.getEndTime());
  }
  List<ProcessInstance> processInstances=runtimeService.createProcessInstanceQuery().list();
  assertEquals(0,processInstances.size());
  jobs=managementService.createJobQuery().list();
  assertEquals(0,jobs.size());
  jobs=managementService.createTimerJobQuery().list();
  assertEquals(0,jobs.size());
  tasks=taskService.createTaskQuery().list();
  assertEquals(0,tasks.size());
}
