@Test
public void testGetNextTask() {

    WorkflowDef def = createNestedWorkflow();
    WorkflowTask firstTask = def.getTasks().get(0);
    assertNotNull(firstTask);
    assertEquals("fork1", firstTask.getTaskReferenceName());
    WorkflowTask nextAfterFirst = def.getNextTask(firstTask.getTaskReferenceName());
    assertNotNull(nextAfterFirst);
    assertEquals("join1", nextAfterFirst.getTaskReferenceName());
    WorkflowTask fork2 = def.getTaskByRefName("fork2");
    assertNotNull(fork2);
    assertEquals("fork2", fork2.getTaskReferenceName());
    WorkflowTask taskAfterFork2 = def.getNextTask("fork2");
    assertNotNull(taskAfterFork2);
    assertEquals("join2", taskAfterFork2.getTaskReferenceName());
    WorkflowTask t2 = def.getTaskByRefName("t2");
    assertNotNull(t2);
    assertEquals("t2", t2.getTaskReferenceName());
    WorkflowTask taskAfterT2 = def.getNextTask("t2");
    assertNotNull(taskAfterT2);
    assertEquals("t4", taskAfterT2.getTaskReferenceName());
    WorkflowTask taskAfterT3 = def.getNextTask("t3");
    assertNotNull(taskAfterT3);
    assertEquals(TaskType.DECISION.name(), taskAfterT3.getType());
    assertEquals("d1", taskAfterT3.getTaskReferenceName());
    WorkflowTask taskAfterT4 = def.getNextTask("t4");
    assertNotNull(taskAfterT4);
    assertEquals("join2", taskAfterT4.getTaskReferenceName());
    WorkflowTask taskAfterT6 = def.getNextTask("t6");
    assertNotNull(taskAfterT6);
    assertEquals("t9", taskAfterT6.getTaskReferenceName());
    WorkflowTask taskAfterJoin2 = def.getNextTask("join2");
    assertNotNull(taskAfterJoin2);
    assertEquals("join1", taskAfterJoin2.getTaskReferenceName());
    WorkflowTask taskAfterJoin1 = def.getNextTask("join1");
    assertNotNull(taskAfterJoin1);
    assertEquals("t5", taskAfterJoin1.getTaskReferenceName());
    WorkflowTask taskAfterSubWF = def.getNextTask("sw1");
    assertNotNull(taskAfterSubWF);
    assertEquals("join1", taskAfterSubWF.getTaskReferenceName());
    WorkflowTask taskAfterT9 = def.getNextTask("t9");
    assertNotNull(taskAfterT9);
    assertEquals("join2", taskAfterT9.getTaskReferenceName());
}