mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
Add catalog unit tests with empty set up method
This commit is contained in:
parent
20ea9e5869
commit
e37c2506b8
65
src/test/java/catering/catalog/CatalogUnitTests.java
Normal file
65
src/test/java/catering/catalog/CatalogUnitTests.java
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
// SPDX-FileCopyrightText: 2023 swt23w23
|
||||||
|
package catering.catalog;
|
||||||
|
import catering.order.OrderType;
|
||||||
|
import org.javamoney.moneta.Money;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
import static org.assertj.core.api.Assertions.*;
|
||||||
|
import static org.salespointframework.core.Currencies.EURO;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
class CatalogUnitTests {
|
||||||
|
@Autowired
|
||||||
|
CateringCatalog cateringCatalog;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void findByCategories() {
|
||||||
|
assertThat(cateringCatalog.findRentablesByCategoriesContains(OrderType.EVENT_CATERING.toString())).hasSize(2);
|
||||||
|
assertThat(cateringCatalog.findRentablesByCategoriesContains(OrderType.MOBILE_BREAKFAST.toString())).hasSize(2);
|
||||||
|
assertThat(cateringCatalog.findRentablesByCategoriesContains(OrderType.RENT_A_COOK.toString())).hasSize(0);
|
||||||
|
assertThat(cateringCatalog.findRentablesByCategoriesContains(OrderType.PARTY_SERVICE.toString())).hasSize(0);
|
||||||
|
|
||||||
|
assertThat(cateringCatalog.findConsumablesByCategoriesContains(OrderType.EVENT_CATERING.toString())).hasSize(1);
|
||||||
|
assertThat(cateringCatalog.findConsumablesByCategoriesContains(OrderType.MOBILE_BREAKFAST.toString())).hasSize(1);
|
||||||
|
assertThat(cateringCatalog.findConsumablesByCategoriesContains(OrderType.RENT_A_COOK.toString())).hasSize(0);
|
||||||
|
assertThat(cateringCatalog.findConsumablesByCategoriesContains(OrderType.PARTY_SERVICE.toString())).hasSize(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void findConsumables() {
|
||||||
|
assertThat(cateringCatalog.findConsumables()).hasSize(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void findRentables() {
|
||||||
|
assertThat(cateringCatalog.findRentables()).hasSize(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DirtiesContext
|
||||||
|
void addConsumableToOrder() {
|
||||||
|
|
||||||
|
// test if consumable was added
|
||||||
|
long countAllBefore = cateringCatalog.findAll().stream().count();
|
||||||
|
long countConsumablesBefore = cateringCatalog.findConsumables().stream().count();
|
||||||
|
Consumable addedConsumable = cateringCatalog.save(new Consumable(
|
||||||
|
"Rosinen Brötchen",
|
||||||
|
Money.of(1.5, EURO),
|
||||||
|
Money.of(0.7, EURO),
|
||||||
|
Optional.of(Money.of(0.90, EURO)),
|
||||||
|
Set.of(OrderType.MOBILE_BREAKFAST)));
|
||||||
|
assertThat(cateringCatalog.findAll().stream().count()).isEqualTo(1 + countAllBefore);
|
||||||
|
assertThat(cateringCatalog.findConsumables().stream().count()).isEqualTo(1 + countConsumablesBefore);
|
||||||
|
assertThat(cateringCatalog.findConsumables()).contains(addedConsumable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue