package guitests;

import static org.junit.Assert.assertTrue;
import static seedu.ezdo.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;

import org.junit.Test;

import seedu.ezdo.commons.core.Messages;
import seedu.ezdo.logic.commands.FindCommand;
import seedu.ezdo.model.todo.TaskDate;
import seedu.ezdo.testutil.TestTask;
//@@author A0141010L
public class FindCommandTest extends EzDoGuiTest {

    @Test
    public void find_nonEmptyList() {

        assertFindResult("find Mark"); // no results
        assertFindResult("find Meier", td.benson, td.daniel); // multiple results
        assertFindResult("find p/1", td.alice);
        assertFindResult("find s/11/11/2015", td.benson);
        assertFindResult("find s/before 30/12/2012", td.daniel, td.elle, td.george);
        assertFindResult("find s/after 01/12/2015", td.alice, td.fiona);
        assertFindResult("find d/14/04/2016", td.daniel);
        assertFindResult("find d/before 30/12/2014", td.carl);
        assertFindResult("find d/after 30/12/2016", td.alice, td.benson);
        assertFindResult("find t/owesMoney", td.benson);
        assertFindResult("find Meier p/2", td.daniel);
        assertFindResult("find Meier s/11/11/2015", td.benson);
        assertFindResult("find Meier s/11th Nov 2015", td.benson);
        assertFindResult("find Meier s/Nov 11th 2015", td.benson);
        assertFindResult("find Meier s/11-11-2015 d/12/02/2017 t/owesMoney t/friends", td.benson);
        assertFindResult("find p/2 d/april 14th 2016", td.daniel);
        assertFindResult("find p/2 d/14/04/2016", td.daniel);
        assertFindResult("find p/1", td.alice);

        //find after deleting one result
        commandBox.runCommand("list");
        commandBox.runCommand("kill 1");
        assertFindResult("find Meier", td.benson, td.daniel);
    }

    //@@author A0138907W
    @Test
    public void find_shortCommand() {
        assertFindResult("f Mark"); // no results
        assertFindResult("f Meier", td.benson, td.daniel); // multiple results

        //find after deleting one result
        commandBox.runCommand("kill 1");
        assertFindResult("f Meier", td.daniel);
    }

    //@@author
    @Test
    public void find_emptyList() {
        commandBox.runCommand("clear");
        assertFindResult("find Jean"); // no results
    }

    @Test
    public void find_invalidCommand_fail_1() {
        commandBox.runCommand("find");
        assertResultMessage(String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE));
        commandBox.runCommand("findgeorge");
        assertResultMessage(Messages.MESSAGE_UNKNOWN_COMMAND);
        commandBox.runCommand("find s/10a");
        assertResultMessage("0 tasks listed!");
        commandBox.runCommand("find Meier p/1 s/11-11-2015 d/02/12/2017 t/owesMoney t/nonExistentTag");
        assertResultMessage("0 tasks listed!");
    }

    @Test
    public void find_invalidCommand_fail_2() {
        commandBox.runCommand("find s/asdasd");
        assertResultMessage(TaskDate.MESSAGE_FIND_DATE_CONSTRAINTS);
    }

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

@@ -135,16 +135,70 @@
 ORMAT;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.Arrays;%0A%0A
 import o
@@ -212,16 +212,16 @@
 t.Test;%0A
-
 %0Aimport 
@@ -1679,16 +1679,423 @@
 lice);%0A%0A
+        //find all tasks with priority%0A        TestTask%5B%5D allTask = td.getTypicalTasks();%0A        ArrayList%3CTestTask%3E resultList = new ArrayList%3CTestTask%3E();%0A        resultList.addAll(Arrays.asList(allTask));%0A        resultList.remove(1); //remove task without priority%0A        TestTask%5B%5D resultArray = resultList.toArray(new TestTask%5BresultList.size()%5D);%0A        assertFindResult(%22find p/%22, resultArray);%0A%0A
         
@@ -2261,32 +2261,33 @@
 on, td.daniel);%0A
+%0A
     %7D%0A%0A    //@@a
@@ -2632,16 +2632,41 @@
 @author%0A
+    //@@author A0141010L%0A
     @Tes
@@ -3194,32 +3194,32 @@
 asks listed!%22);%0A
-
         commandB
@@ -3353,32 +3353,447 @@
 sted!%22);%0A    %7D%0A%0A
+    @Test%0A    public void find_nonexisting_task() %7B%0A        commandBox.runCommand(%22find s/10a%22);%0A        assertResultMessage(%220 tasks listed!%22);%0A        commandBox.runCommand(%22find Meier p/1 s/11-11-2015 d/02/12/2017 t/owesMoney t/nonExistentTag%22);%0A        assertResultMessage(%220 tasks listed!%22);%0A        commandBox.runCommand(%22find CashMeOutsideHowBoutDat%22);%0A        assertResultMessage(%220 tasks listed!%22);%0A    %7D%0A%0A
     @Test%0A    pu

Add test case for finding tasks with priority