@Test
public void listPreparationsShouldBeOrderedByLastModificationDate() throws Exception {

    // given
    when().get("/preparations/details").then().statusCode(HttpStatus.OK.value()).body(sameJSONAs("[]"));
    List<String> preparationIds = new ArrayList<>(5);
    for (int i = 0; i < 5; i++) {
        final long now = new Date().getTime();
        Preparation preparation = new Preparation(UUID.randomUUID().toString(), "12345", Step.ROOT_STEP.id(),
                versionService.version().getVersionId());
        preparation.setName("prep-" + i);
        preparation.setLastModificationDate(now);
        repository.add(preparation);
        preparationIds.add(0, preparation.id()); // last modified preparation is first
        Thread.sleep(100); // to make sure the last modification date is older
    }
    // when
    final InputStream responseContent = when().get("/preparations/details").asInputStream();
    final List<Preparation> actual = mapper.readValue(responseContent, new TypeReference<List<Preparation>>() {
    });
    // then
    assertEquals(preparationIds.size(), actual.size());
    for (int i = 0; i < actual.size(); i++) {
        assertEquals(preparationIds.get(i), actual.get(i).getId());
    }
}