diff --git a/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/screenplay/features/maintain_my_todo_list/FilteringTodos.java b/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/screenplay/features/maintain_my_todo_list/FilteringTodos.java index 0d221c4e1..5b0534c06 100644 --- a/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/screenplay/features/maintain_my_todo_list/FilteringTodos.java +++ b/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/screenplay/features/maintain_my_todo_list/FilteringTodos.java @@ -4,7 +4,6 @@ import net.serenitybdd.demos.todos.screenplay.model.TodoStatusFilter; import net.serenitybdd.demos.todos.screenplay.questions.CurrentFilter; import net.serenitybdd.demos.todos.screenplay.questions.TheItems; -import net.serenitybdd.demos.todos.screenplay.tasks.CompleteItem; import net.serenitybdd.demos.todos.screenplay.tasks.CompleteItems; import net.serenitybdd.demos.todos.screenplay.tasks.FilterItems; import net.serenitybdd.demos.todos.screenplay.tasks.Start; @@ -12,7 +11,6 @@ import net.serenitybdd.screenplay.Actor; import net.serenitybdd.screenplay.abilities.BrowseTheWeb; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; @@ -22,9 +20,9 @@ import java.util.Arrays; import java.util.List; -import static net.serenitybdd.demos.todos.screenplay.model.TodoStatusFilter.*; import static net.serenitybdd.screenplay.GivenWhenThen.*; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.hasItems; +import static org.hamcrest.Matchers.is; @ExtendWith(SerenityJUnit5Extension.class) public class FilteringTodos { @@ -41,59 +39,42 @@ public void jamesCanBrowseTheWeb() { @ParameterizedTest @CsvSource({ - // initialTodos, itemsToComplete, filtersToApply, expectedDisplayedItems, expectedNotDisplayedItems, expectedSelectedFilter - "'Walk the dog;Put out the garbage', 'Walk the dog', 'Completed', 'Walk the dog', 'Put out the garbage', 'Completed'", - "'Walk the dog;Put out the garbage', 'Walk the dog', 'Active', 'Put out the garbage', 'Walk the dog', 'Active'", - "'Walk the dog;Put out the garbage', 'Walk the dog', 'All', 'Walk the dog;Put out the garbage', '', 'All'" + // initialTodos, itemsToComplete, filtersToApply, expectedDisplayedItems, expectedSelectedFilter + "Walk the dog;Put out the garbage, Walk the dog, Completed, Walk the dog, Completed", + "Walk the dog;Put out the garbage, Walk the dog, Active, Put out the garbage, Active", + "Walk the dog;Put out the garbage, Walk the dog, All, Walk the dog;Put out the garbage, All" }) public void should_be_able_to_filter_todos( - String initialTodosStr, - String itemsToCompleteStr, + String initialTodos, + String itemsToComplete, String filterToApply, - String expectedDisplayedItemsStr, - String expectedNotDisplayedItemsStr, - String expectedSelectedFilterStr + String expectedDisplayedItems, + String expectedSelectedFilter ) { // Parse the CSV string parameters into lists - List initialTodos = parseStringToList(initialTodosStr); - List itemsToComplete = parseStringToList(itemsToCompleteStr); - List expectedDisplayedItems = parseStringToList(expectedDisplayedItemsStr); - List expectedNotDisplayedItems = parseStringToList(expectedNotDisplayedItemsStr); - TodoStatusFilter expectedSelectedFilter = TodoStatusFilter.valueOf(expectedSelectedFilterStr); + TodoStatusFilter expectedFilter = TodoStatusFilter.valueOf(expectedSelectedFilter); // Given - givenThat(james).wasAbleTo(Start.withATodoListContaining(initialTodos)); + givenThat(james).wasAbleTo(Start.withATodoListContaining(asList(initialTodos))); // When james.attemptsTo( - CompleteItems.called(itemsToComplete), + CompleteItems.called(asList(itemsToComplete)), FilterItems.toShow(TodoStatusFilter.valueOf(filterToApply)) ); // Then then(james).should( - seeThat(TheItems.displayed(), hasItems(expectedDisplayedItems.toArray(new String[0]))), - seeThat(CurrentFilter.selected(), is(expectedSelectedFilter)) + seeThat(TheItems.displayed(), hasItems(expectedDisplayedItems)), + seeThat(CurrentFilter.selected(), is(expectedFilter)) ); - if (!expectedNotDisplayedItems.isEmpty()) { - and(james).should(seeThat(TheItems.displayed(), not(hasItems(expectedNotDisplayedItems.toArray(new String[0]))))); - } } - // Helper method to parse semicolon-separated strings into lists - private List parseStringToList(String str) { + private List asList(String str) { if (str == null || str.trim().isEmpty()) { return new ArrayList<>(); } return Arrays.asList(str.split(";")); } - // Helper method to parse filter names into TodoStatusFilter enum instances - private List parseFilters(List filterNames) { - List filters = new ArrayList<>(); - for (String name : filterNames) { - filters.add(TodoStatusFilter.valueOf(name)); - } - return filters; - } }