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
46
47
48
49
50
51
52
53
package mi.hdm.recipes;
import mi.hdm.exceptions.InvalidRecipeException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
class RecipeManagerTest {
private RecipeManager underTest;
private final Recipe recipeOne = ValidObjectsPool.getValidRecipeOne();
private final Recipe recipeTwo = ValidObjectsPool.getValidRecipeTwo();
@BeforeEach
public void setup() {
underTest = new RecipeManager();
}
@Test
public void shouldAddRecipeWhenNotDuplicate() {
//when
underTest.addRecipe(recipeOne);
//expect
List<Recipe> expected = List.of(recipeOne);
assertEquals(expected, underTest.getRecipes());
}
@Test
public void shouldNotAddDuplicateRecipe() {
//given
underTest.addRecipe(recipeOne);
//expect
assertThrows(InvalidRecipeException.class, () -> underTest.addRecipe(recipeOne));
}
@Test
public void canDeleteRecipeByName() {
//given
underTest.addRecipe(recipeOne);
//when
underTest.deleteRecipe(recipeOne.getName());
//expect
assertEquals(List.of(), underTest.getRecipes());
}
@Test
public void removingInvalidRecipes() {
assertThrows(InvalidRecipeException.class, () -> underTest.deleteRecipe(recipeOne));
assertThrows(InvalidRecipeException.class, () -> underTest.deleteRecipe("This recipe does not exist"));
}
}