//@@author A0139925U
package guitests;

import static org.junit.Assert.assertTrue;

import java.util.ArrayList;

import org.junit.Test;

import seedu.tache.commons.core.Messages;
import seedu.tache.commons.exceptions.IllegalValueException;
import seedu.tache.testutil.TaskBuilder;
import seedu.tache.testutil.TestTask;

public class ListCommandTest extends TaskManagerGuiTest {

    @Test
    public void listAllTasks() {
        assertListResult("list all", "All", td.getTypicalTasks());

        //list after deleting one result
        commandBox.runCommand("delete 1");
        TestTask[] tempTasksList = td.getTypicalTasks();
        ArrayList<TestTask> expectedTasksList = new ArrayList<TestTask>();
        for (int i = 0; i < tempTasksList.length - 1; i++) {
            expectedTasksList.add(tempTasksList[i + 1]);
        }
        assertListResult("list all", "All", expectedTasksList.toArray(new TestTask[0]));
    }

    @Test
    public void listUncompletedTasks() {
        assertListResult("list uncompleted", "Uncompleted", td.getTypicalTasks());
        commandBox.runCommand("list");
        commandBox.runCommand("complete 1");
        TestTask[] tempTasksList = td.getTypicalTasks();
        ArrayList<TestTask> expectedTasksList = new ArrayList<TestTask>();
        for (int i = 0; i < tempTasksList.length - 1; i++) {
            expectedTasksList.add(tempTasksList[i + 1]);
        }
        assertListResult("list uncompleted", "Uncompleted", expectedTasksList.toArray(new TestTask[0]));
    }

    @Test
    public void listCompletedTasks() {
        assertListResult("list completed", "Completed");
        commandBox.runCommand("list");
        commandBox.runCommand("complete 1,2,3");
        TestTask[] tempTasksList = td.getTypicalTasks();
        ArrayList<TestTask> expectedTasksList = new ArrayList<TestTask>();
        for (int i = 0; i < 3; i++) {
            expectedTasksList.add(tempTasksList[i]);
        }
        assertListResult("list completed", "Completed", expectedTasksList.toArray(new TestTask[0]));
    }

    //@@author A0142255M
    @Test
    public void listTimedTasks() {
        assertListResult("list timed", "Timed", td.eggsAndBread, td.visitFriend, td.readBook);
        commandBox.runCommand("list");
        commandBox.runCommand("edit 2 change sd to 5 jun and change st to 9am");
        TestTask[] tempTasksList = td.getTypicalTasks();
        ArrayList<TestTask> expectedTasksList = new ArrayList<TestTask>();
        for (int i = 1; i < 5; i++) {
            expectedTasksList.add(tempTasksList[i]);
        }
        assertListResult("list timed", "Timed", expectedTasksList.toArray(new TestTask[0]));
    }

    @Test
    public void listFloatingTasks() throws IllegalValueException {
        assertListResult("list floating", "Floating", td.payDavid, td.visitSarah);
        commandBox.runCommand("list");
        commandBox.runCommand("add watch tv");
        TestTask[] tempTasksList = td.getTypicalTasks();
        ArrayList<TestTask> expectedTasksList = new ArrayList<TestTask>();
        for (int i = 0; i < 2; i++) {
            expectedTasksList.add(tempTasksList[i]);
        }
        expectedTasksList.add(new TaskBuilder().withName("watch tv").build());
        assertListResult("list floating", "Floating", expectedTasksList.toArray(new TestTask[0]));
    }
    //@@author

    @Test
    public void listNoEvent() {
        commandBox.runCommand("clear");
        assertListResult("list", "Uncompleted");
    }

    @Test
    public void listInvalidCommandFail() {
        commandBox.runCommand("listkkjksjkds");
        assertResultMessage(Messages.MESSAGE_UNKNOWN_COMMAND);
    }

    private void assertListResult(String command, String expectedMessage, TestTask... expectedHits) {
        commandBox.runCommand(command);
        assertResultMessage(expectedMessage + " tasks listed");
        assertListSize(expectedHits.length);
        assertTrue(taskListPanel.isListMatching(expectedHits));
    }
}

@@ -233,16 +233,56 @@
 eption;%0A
+import seedu.tache.model.task.DateTime;%0A
 import s
@@ -3690,24 +3690,871 @@
 ND);%0A    %7D%0A%0A
+    //@@author A0139961U%0A    @Test%0A    public void listTodayTasks() throws IllegalValueException %7B%0A        assertListResult(%22list today%22, %22Today%22);%0A        commandBox.runCommand(%22list%22);%0A        commandBox.runCommand(%22edit 1 change ed to today change et to 23:59%22);%0A        commandBox.runCommand(%22edit 1 change ed to today change et to 23:59%22);%0A        commandBox.runCommand(%22edit 1 change ed to today change et to 23:59%22);%0A        TestTask%5B%5D tempTasksList = td.getTypicalTasks();%0A        ArrayList%3CTestTask%3E expectedTasksList = new ArrayList%3CTestTask%3E();%0A        for (int i = 0; i %3C 3; i++) %7B%0A            tempTasksList%5Bi%5D.setEndDateTime(new DateTime(%22today 23:59%22));%0A            expectedTasksList.add(tempTasksList%5Bi%5D);%0A        %7D%0A        assertListResult(%22list today%22, %22Today%22, expectedTasksList.toArray(new TestTask%5B0%5D));%0A    %7D%0A%0A    //@@author%0A%0A
     private 
@@ -4862,10 +4862,11 @@
 ;%0A    %7D%0A
+%0A
 %7D%0A

Update List Cmd Unit Test