void () { /////////////////// try order: parent,child ///////////////////////// List<Integer> executedTasks = new ArrayList<>(); ParentTask parent = new ParentTask(1, executedTasks); ChildTask child = new ChildTask(2, executedTasks); myQueue.addTask(parent); myQueue.addTask(child); runAllTasks(); // Parent should not be merged with child (for safety reasons) because they have different types assertSameElements(executedTasks, 1, 2); /////////////////// try reverse order: child,parent ///////////////////////// executedTasks.clear(); parent = new ParentTask(1, executedTasks); child = new ChildTask(2, executedTasks); myQueue.addTask(child); myQueue.addTask(parent); runAllTasks(); // Parent should not be merged with child (for safety reasons) because they have different types assertSameElements(executedTasks, 1, 2); }