Add catalog unit tests with empty set up method

This commit is contained in:
Theo Reichert 2023-12-10 06:43:08 +01:00 committed by Denis Natusch
parent 20ea9e5869
commit e37c2506b8
No known key found for this signature in database
GPG key ID: 5E57BD8EDACFA985

View 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);
}
}