orderDAO.save(order);
orderDAO.flush();
assertThat(order.getDeliveringDates().size(), equalTo(2));
DeadlineCommunication dcFirst = order.getDeliveringDates().first();
DeadlineCommunication dcLast = order.getDeliveringDates().last();
assertTrue(dcFirst.getSaveDate().after(dcLast.getSaveDate()));
//A new DeadlineCommunication is placed between the existing communications.
Date date = (new LocalDate(dcLast.getSaveDate()).plusDays(2)).toDateTimeAtStartOfDay().toDate();
DeadlineCommunication deadlineCommunication = DeadlineCommunication.create(date, null);
order.getDeliveringDates().add(deadlineCommunication);
orderDAO.save(order);
orderDAO.flush();
assertThat(order.getDeliveringDates().size(), equalTo(3));
dcFirst = order.getDeliveringDates().first();
dcLast = order.getDeliveringDates().last();
DeadlineCommunication new_dc = (DeadlineCommunication) order.getDeliveringDates().toArray()[1];
assertTrue(dcFirst.getSaveDate().after(dcLast.getSaveDate()));
assertTrue(dcFirst.getSaveDate().after(new_dc.getSaveDate()));
assertFalse(dcLast.equals(new_dc));
assertTrue(dcLast.getSaveDate().before(new_dc.getSaveDate()));
}