package mi.hdm.recipes; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.NullAndEmptySource; import org.junit.jupiter.params.provider.ValueSource; import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; class RecipeSearchTest { private final static Recipe r1 = ValidObjectsPool.getValidRecipeOne(); private final static Recipe r2 = ValidObjectsPool.getValidRecipeTwo(); private final static Category c1 = ValidObjectsPool.getValidCategoryOne(); private final static Category c2 = ValidObjectsPool.getValidCategoryTwo(); private List<Recipe> recipes; //private RecipeSearch underTest; //not needed when methods are static @BeforeEach public void setup() { recipes = List.of(r1, r2); //underTest = new RecipeSearch(recipes); //not needed when methods are static } @ParameterizedTest @NullAndEmptySource @ValueSource(strings = {" \n", ".", "!", "..."}) public void testSearchByEmptyQuery(String input) { assertEquals(recipes, RecipeSearch.searchByQuery(recipes, input)); } @ParameterizedTest @ValueSource(strings = {"valid", "valid!", "...valid"}) public void testSearchByNameQuery(String query) { //given List<Recipe> expected = List.of(r1); //when List<Recipe> result = RecipeSearch.searchByQuery(recipes, query); //expected assertEquals(expected, result); } @Test public void testSearchByIngredientsQuery() { //given List<Recipe> expected = List.of(r1); String query = "Apple "; //when List<Recipe> result = RecipeSearch.searchByQuery(recipes, query); //expected assertEquals(expected, result); } @ParameterizedTest @NullAndEmptySource public void testSearchByEmptyCategories(List<Category> input) { assertEquals(recipes, RecipeSearch.searchByCategory(recipes, input)); } @Test public void testSearchByCategories() { assertEquals(List.of(r1, r2), RecipeSearch.searchByCategory(recipes, List.of(c1))); assertEquals(List.of(r2), RecipeSearch.searchByCategory(recipes, List.of(c1, c2))); assertEquals(List.of(r2), RecipeSearch.searchByCategory(recipes, List.of(c2))); } }