// Path: src/samples/journey-pattern-sample/src/main/java/net/serenitybdd/demos/todos/questions/DisplayedItems.java
// @Subject("the displayed todo items")
// public class DisplayedItems implements Question<List<String>> {
// 
//     @Override
//     public List<String> answeredBy(Actor actor) {
//         return Text.of(ToDoList.TODO_ITEMS).viewedBy(actor).asList();
//     }
// }
// 
// Path: src/samples/journey-pattern-sample/src/main/java/net/serenitybdd/demos/todos/questions/TheItemStatus.java
// public class TheItemStatus implements Question<TodoStatus> {
// 
//     private final String itemName;
// 
//     private final Map<Boolean, TodoStatus> CHECKED_STATUS = ImmutableMap.of(
//         FALSE, Active,
//         TRUE,  Completed
//     );
// 
//     public TheItemStatus(String itemName) {
//         this.itemName = itemName;
//     }
// 
//     @Override
//     public TodoStatus answeredBy(Actor actor) {
//         Target completeItemButton = TodoListItem.COMPLETE_ITEM_BUTTON.of(itemName);
// 
//         Boolean itemChecked = SelectedStatus.of(completeItemButton).viewedBy(actor).as(Boolean.class);
//         return statusFrom(itemChecked);
//     }
// 
//     private TodoStatus statusFrom(Boolean checked) {
//         return CHECKED_STATUS.get(checked);
//     }
// 
//     public static Question<?> forTheItemCalled(String itemName) {
//         return Instrumented.instanceOf(TheItemStatus.class).withProperties(itemName);
//     }
// }
// 
// Path: src/samples/journey-pattern-sample/src/main/java/net/serenitybdd/demos/todos/questions/TheRemainingItemCount.java
// public class TheRemainingItemCount implements Question<Integer> {
//     public static TheRemainingItemCount value() {
//         return new TheRemainingItemCount();
//     }
// 
//     @Override
//     public Integer answeredBy(Actor actor) {
//         return Text.of(TodoCounter.ITEM_COUNT)
//                    .viewedBy(actor)
//                    .asInteger();
//     }
// }


import net.serenitybdd.demos.todos.questions.DisplayedItems;
import net.serenitybdd.demos.todos.questions.TheItemStatus;
import net.serenitybdd.demos.todos.questions.TheRemainingItemCount;
import net.serenitybdd.demos.todos.tasks.*;
import net.serenitybdd.junit.runners.SerenityRunner;
import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.abilities.BrowseTheWeb;
import net.thucydides.core.annotations.Managed;
import net.thucydides.core.annotations.Steps;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.WebDriver;
import static net.serenitybdd.demos.todos.model.TodoStatus.Completed;
import static net.serenitybdd.demos.todos.model.TodoStatusFilter.Active;
import static net.serenitybdd.screenplay.GivenWhenThen.*;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.not;
package net.serenitybdd.demos.todos.features.completing_todos;



@RunWith(SerenityRunner.class)
public class CompleteATodo {

    @Managed
    private
    WebDriver hisBrowser;

    private Actor james = Actor.named("James");

    @Steps
    ClearCompletedItems clearTheCompletedItems;

    @Steps
    private
    DisplayedItems theDisplayedItems;

    @Before
    public void jamesCanBrowseTheWeb() {
        james.can(BrowseTheWeb.with(hisBrowser));
    }

    @Test
    public void completed_items_should_be_marked_as_completed_in_the_main_list() {

        givenThat(james).wasAbleTo(OpenTheApplication.onTheHomePage());
        andThat(james).wasAbleTo(AddTodoItems.called("Walk the dog", "Put out the garbage"));

        when(james).attemptsTo(
                Complete.itemCalled("Walk the dog")
        );

        then(james).should(
// Path: src/samples/journey-pattern-sample/src/main/java/net/serenitybdd/demos/todos/questions/DisplayedItems.java
// @Subject("the displayed todo items")
// public class DisplayedItems implements Question<List<String>> {
// 
//     @Override
//     public List<String> answeredBy(Actor actor) {
//         return Text.of(ToDoList.TODO_ITEMS).viewedBy(actor).asList();
//     }
// }
// 
// Path: src/samples/journey-pattern-sample/src/main/java/net/serenitybdd/demos/todos/questions/TheItemStatus.java
// public class TheItemStatus implements Question<TodoStatus> {
// 
//     private final String itemName;
// 
//     private final Map<Boolean, TodoStatus> CHECKED_STATUS = ImmutableMap.of(
//         FALSE, Active,
//         TRUE,  Completed
//     );
// 
//     public TheItemStatus(String itemName) {
//         this.itemName = itemName;
//     }
// 
//     @Override
//     public TodoStatus answeredBy(Actor actor) {
//         Target completeItemButton = TodoListItem.COMPLETE_ITEM_BUTTON.of(itemName);
// 
//         Boolean itemChecked = SelectedStatus.of(completeItemButton).viewedBy(actor).as(Boolean.class);
//         return statusFrom(itemChecked);
//     }
// 
//     private TodoStatus statusFrom(Boolean checked) {
//         return CHECKED_STATUS.get(checked);
//     }
// 
//     public static Question<?> forTheItemCalled(String itemName) {
//         return Instrumented.instanceOf(TheItemStatus.class).withProperties(itemName);
//     }
// }
// 
// Path: src/samples/journey-pattern-sample/src/main/java/net/serenitybdd/demos/todos/questions/TheRemainingItemCount.java
// public class TheRemainingItemCount implements Question<Integer> {
//     public static TheRemainingItemCount value() {
//         return new TheRemainingItemCount();
//     }
// 
//     @Override
//     public Integer answeredBy(Actor actor) {
//         return Text.of(TodoCounter.ITEM_COUNT)
//                    .viewedBy(actor)
//                    .asInteger();
//     }
// }


// Path: src/samples/journey-pattern-sample/src/test/java/net/serenitybdd/demos/todos/features/completing_todos/CompleteATodo.java
import net.serenitybdd.demos.todos.questions.DisplayedItems;
import net.serenitybdd.demos.todos.questions.TheItemStatus;
import net.serenitybdd.demos.todos.questions.TheRemainingItemCount;
import net.serenitybdd.demos.todos.tasks.*;
import net.serenitybdd.junit.runners.SerenityRunner;
import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.abilities.BrowseTheWeb;
import net.thucydides.core.annotations.Managed;
import net.thucydides.core.annotations.Steps;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.WebDriver;
import static net.serenitybdd.demos.todos.model.TodoStatus.Completed;
import static net.serenitybdd.demos.todos.model.TodoStatusFilter.Active;
import static net.serenitybdd.screenplay.GivenWhenThen.*;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.not;

package net.serenitybdd.demos.todos.features.completing_todos;



@RunWith(SerenityRunner.class)
public class CompleteATodo {

    @Managed
    private
    WebDriver hisBrowser;

    private Actor james = Actor.named("James");

    @Steps
    ClearCompletedItems clearTheCompletedItems;

    @Steps
    private
    DisplayedItems theDisplayedItems;

    @Before
    public void jamesCanBrowseTheWeb() {
        james.can(BrowseTheWeb.with(hisBrowser));
    }

    @Test
    public void completed_items_should_be_marked_as_completed_in_the_main_list() {

        givenThat(james).wasAbleTo(OpenTheApplication.onTheHomePage());
        andThat(james).wasAbleTo(AddTodoItems.called("Walk the dog", "Put out the garbage"));

        when(james).attemptsTo(
                Complete.itemCalled("Walk the dog")
        );

        then(james).should(
                seeThat(TheItemStatus.forTheItemCalled("Walk the dog"), is(Completed)),