Skip to content
Snippets Groups Projects
RecipeManagerTest.java 1.5 KiB
Newer Older
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"));
    }
}