diff --git a/src/test/java/catering/inventory/InventoryControllerIntegrationTests.java b/src/test/java/catering/inventory/InventoryControllerIntegrationTests.java index 5badb9c..24a9564 100644 --- a/src/test/java/catering/inventory/InventoryControllerIntegrationTests.java +++ b/src/test/java/catering/inventory/InventoryControllerIntegrationTests.java @@ -76,6 +76,10 @@ class InventoryControllerIntegrationTests { } } + private long countItems() { + return inventory.findAll().stream().count(); + } + @BeforeEach void populateAnyInventoryItem() { anyInventoryItem = inventory.findAll().stream().findAny().get(); @@ -107,7 +111,7 @@ class InventoryControllerIntegrationTests { .andExpect(status().isOk()) .andExpect(content().string(containsString("Produkt anlegen"))); - long itemCountBefore = inventory.findAll().stream().count(); + long itemCountBefore = countItems(); mvc.perform(post("/inventory/add?type=Consumable") .queryParam("type", Consumable.class.getSimpleName()) @@ -119,9 +123,7 @@ class InventoryControllerIntegrationTests { .param("promotionPrice", "6.66")) .andExpect(redirectedUrl("/inventory")); - long itemCountAfter = inventory.findAll().stream().count(); - - assertThat(itemCountAfter).isEqualTo(itemCountBefore + 1); + assertThat(countItems()).isEqualTo(itemCountBefore + 1); // extracting is not possible here, as the category sets are not equal assertThat(inventory.findAll().stream() @@ -140,14 +142,12 @@ class InventoryControllerIntegrationTests { @Test @WithMockUser(username = "admin", roles = "ADMIN") void adminCanDelete() throws Exception { - long itemCountBefore = inventory.findAll().stream().count(); + long itemCountBefore = countItems(); mvc.perform(get("/inventory/delete/" + anyPid)) .andExpect(redirectedUrl("/inventory")); - long itemCountAfter = inventory.findAll().stream().count(); - - assertThat(itemCountAfter).isEqualTo(itemCountBefore - 1); + assertThat(countItems()).isEqualTo(itemCountBefore - 1); assertThat(inventory.findAll().stream()) .extracting("product.name", "quantity")