Extract item counting in InventoryControllerIntegrationTests

This commit is contained in:
Simon Bruder 2024-01-14 15:36:45 +01:00
parent 9ec41df27f
commit 8b2fe0cb40
Signed by: simon
GPG key ID: 8D3C82F9F309F8EC

View file

@ -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")