@Test
public void pollNextWorkflowInstancesReturnInstancesInCorrectOrder() {

  long olderLowPrio = createInstance(2, (short) 1);
  long newerLowPrio = createInstance(1, (short) 1);
  long newerHighPrio = createInstance(1, (short) 2);
  // high priority comes first
  List<Long> ids = dao.pollNextWorkflowInstanceIds(1);
  assertThat(ids, is(asList(newerHighPrio)));
  // older comes first when same prio
  ids = dao.pollNextWorkflowInstanceIds(1);
  assertThat(ids, is(asList(olderLowPrio)));
  // newer comes last when same prio
  ids = dao.pollNextWorkflowInstanceIds(1);
  assertThat(ids, is(asList(newerLowPrio)));
}