mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
Extract item counting in InventoryControllerIntegrationTests
This commit is contained in:
parent
9ec41df27f
commit
8b2fe0cb40
|
@ -76,6 +76,10 @@ class InventoryControllerIntegrationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private long countItems() {
|
||||||
|
return inventory.findAll().stream().count();
|
||||||
|
}
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void populateAnyInventoryItem() {
|
void populateAnyInventoryItem() {
|
||||||
anyInventoryItem = inventory.findAll().stream().findAny().get();
|
anyInventoryItem = inventory.findAll().stream().findAny().get();
|
||||||
|
@ -107,7 +111,7 @@ class InventoryControllerIntegrationTests {
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
.andExpect(content().string(containsString("Produkt anlegen")));
|
.andExpect(content().string(containsString("Produkt anlegen")));
|
||||||
|
|
||||||
long itemCountBefore = inventory.findAll().stream().count();
|
long itemCountBefore = countItems();
|
||||||
|
|
||||||
mvc.perform(post("/inventory/add?type=Consumable")
|
mvc.perform(post("/inventory/add?type=Consumable")
|
||||||
.queryParam("type", Consumable.class.getSimpleName())
|
.queryParam("type", Consumable.class.getSimpleName())
|
||||||
|
@ -119,9 +123,7 @@ class InventoryControllerIntegrationTests {
|
||||||
.param("promotionPrice", "6.66"))
|
.param("promotionPrice", "6.66"))
|
||||||
.andExpect(redirectedUrl("/inventory"));
|
.andExpect(redirectedUrl("/inventory"));
|
||||||
|
|
||||||
long itemCountAfter = inventory.findAll().stream().count();
|
assertThat(countItems()).isEqualTo(itemCountBefore + 1);
|
||||||
|
|
||||||
assertThat(itemCountAfter).isEqualTo(itemCountBefore + 1);
|
|
||||||
|
|
||||||
// extracting is not possible here, as the category sets are not equal
|
// extracting is not possible here, as the category sets are not equal
|
||||||
assertThat(inventory.findAll().stream()
|
assertThat(inventory.findAll().stream()
|
||||||
|
@ -140,14 +142,12 @@ class InventoryControllerIntegrationTests {
|
||||||
@Test
|
@Test
|
||||||
@WithMockUser(username = "admin", roles = "ADMIN")
|
@WithMockUser(username = "admin", roles = "ADMIN")
|
||||||
void adminCanDelete() throws Exception {
|
void adminCanDelete() throws Exception {
|
||||||
long itemCountBefore = inventory.findAll().stream().count();
|
long itemCountBefore = countItems();
|
||||||
|
|
||||||
mvc.perform(get("/inventory/delete/" + anyPid))
|
mvc.perform(get("/inventory/delete/" + anyPid))
|
||||||
.andExpect(redirectedUrl("/inventory"));
|
.andExpect(redirectedUrl("/inventory"));
|
||||||
|
|
||||||
long itemCountAfter = inventory.findAll().stream().count();
|
assertThat(countItems()).isEqualTo(itemCountBefore - 1);
|
||||||
|
|
||||||
assertThat(itemCountAfter).isEqualTo(itemCountBefore - 1);
|
|
||||||
|
|
||||||
assertThat(inventory.findAll().stream())
|
assertThat(inventory.findAll().stream())
|
||||||
.extracting("product.name", "quantity")
|
.extracting("product.name", "quantity")
|
||||||
|
|
Loading…
Reference in a new issue