Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package mi.hdm.recipes;
import mi.hdm.exceptions.InvalidRecipeException;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
class RecipeTest {
private final static List<RecipeComponent> ingredients = ValidObjectsPool.getValidIngredientList();
private final static Map<RecipeComponent, Integer> recipeMap = new HashMap<>();
@BeforeAll
public static void setUpAll() {
ingredients.forEach(ingredient -> recipeMap.put(ingredient, 100));
}
@Test
@DisplayName("Test invalid name: Recipes with an invalid name (name is null or empty) should not be created")
void shouldNotCreateRecipeWithInvalidName() {
assertThrows(InvalidRecipeException.class, () -> new Recipe(null, recipeMap, "Description!", List.of("step 1"), null, 100));
assertThrows(InvalidRecipeException.class, () -> new Recipe("", recipeMap, "Description!", List.of("step 1"), null, 100));
}
@Test
@DisplayName("Test invalid ingredients: Recipes with an invalid ingredient map (map is null or empty) should not be created")
void shouldNotCreateRecipeWithInvalidIngredientMap() {
assertThrows(InvalidRecipeException.class, () -> new Recipe("Valid name", null, "Description!", List.of("step 1"), null, 100));
assertThrows(InvalidRecipeException.class, () -> new Recipe("Valid name", Map.of(), "Description!", List.of("step 1"), null, 100));
}
@Test
@DisplayName("Test invalid preparation: Recipes with an invalid preparation list (list is null or empty) should not be created")
void shouldNotCreateRecipeWithInvalidPrep() {
assertThrows(InvalidRecipeException.class, () -> new Recipe("Valid name", recipeMap, "Description!", null, null, 100));
assertThrows(InvalidRecipeException.class, () -> new Recipe("Valid name", recipeMap, "Description!", List.of(), null, 100));
}
@Test
@DisplayName("Test invalid prep time: Recipes with an invalid preparation time (number is negative) should not be created")
void shouldNotCreateRecipeWithInvalidPrepTime() {
assertThrows(InvalidRecipeException.class, () -> new Recipe("Valid name", recipeMap, "Description!", null, null, -1));
}
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
@Test
void getNutritionTableWhenSetManually() {
//given
NutritionTable nutritionTable = ValidObjectsPool.getValidNutritionTableOne();
//when
Recipe underTest = new Recipe("Valid name", recipeMap, "Valid description", List.of("Step 1"), null, 20, nutritionTable);
//then
assertEquals(nutritionTable, underTest.getNutritionTable());
}
@Test
void getNutritionTableWhenCalculated() {
//given
NutritionTable nutritionTable = ValidObjectsPool.getValidNutritionTableOne();
Ingredient ingredientOne = new Ingredient(Measurement.GRAM, "Zucker", nutritionTable);
//when
Recipe underTest = new Recipe("Valid name", Map.of(ingredientOne, 100), "Valid description", List.of("Step 1"), null, 20);
//then
assertEquals(nutritionTable, underTest.getNutritionTable());
}
@Test
void canAddCategory() {
//given
Category category = new Category("Category", 0xFF0000);
NutritionTable nutritionTable = ValidObjectsPool.getValidNutritionTableOne();
Ingredient ingredientOne = new Ingredient(Measurement.GRAM, "Zucker", nutritionTable);
Recipe underTest = new Recipe("Valid name", Map.of(ingredientOne, 100), "Valid description", List.of("Step 1"), new ArrayList<>(), 20);
//when
underTest.addCategory(category);
//then
assertEquals(
List.of(category),
underTest.getCategories()
);
}
@Test
void canAddCategoryWhenNull() {
//given
Category category = new Category("Category", 0xFF0000);
NutritionTable nutritionTable = ValidObjectsPool.getValidNutritionTableOne();
Ingredient ingredientOne = new Ingredient(Measurement.GRAM, "Zucker", nutritionTable);
Recipe underTest = new Recipe("Valid name", Map.of(ingredientOne, 100), "Valid description", List.of("Step 1"), null, 20);
//when
underTest.addCategory(category);
//then
assertEquals(
List.of(category),
underTest.getCategories()
);
}