package guitests;

import static org.junit.Assert.assertTrue;

import java.util.List;

import org.junit.Test;

import com.google.common.collect.Lists;

import guitests.guihandles.TaskCardHandle;
import seedu.taskboss.commons.core.Messages;
import seedu.taskboss.commons.exceptions.IllegalValueException;
import seedu.taskboss.logic.commands.AddCommand;
import seedu.taskboss.model.category.UniqueCategoryList.DuplicateCategoryException;
import seedu.taskboss.testutil.TestCategory;
import seedu.taskboss.testutil.TestTask;
import seedu.taskboss.testutil.TestUtil;

public class AddCommandTest extends TaskBossGuiTest {

    @Test
    public void add() throws DuplicateCategoryException, IllegalValueException {
        TestTask[] currentList = td.getTypicalTasks();
        //add one task
        TestTask taskToAdd = td.taskH;
        assertAddSuccess(false, false, Lists.newArrayList(new TestCategory
                (AddCommand.BUILT_IN_ALL_TASKS, td.taskA)), taskToAdd, currentList);
        currentList = TestUtil.addTasksToList(currentList, taskToAdd);

        //add another task
        taskToAdd = td.taskI;
        assertAddSuccess(false, false, Lists.newArrayList(new TestCategory
                (AddCommand.BUILT_IN_ALL_TASKS, td.taskA)), taskToAdd, currentList);
        currentList = TestUtil.addTasksToList(currentList, taskToAdd);

        //add another task using short command
        taskToAdd = td.taskK;
        assertAddSuccess(false, true, Lists.newArrayList(new TestCategory
                (AddCommand.BUILT_IN_ALL_TASKS, td.taskA)), taskToAdd, currentList);
        currentList = TestUtil.addTasksToList(currentList, taskToAdd);

        //add another task using short command '+'
        taskToAdd = td.taskL;
        assertAddSuccess(true, false, Lists.newArrayList(new TestCategory
                (AddCommand.BUILT_IN_ALL_TASKS, td.taskA)), taskToAdd, currentList);
        currentList = TestUtil.addTasksToList(currentList, taskToAdd);

        //add duplicate task
        commandBox.runCommand(td.taskH.getAddCommand());
        assertResultMessage(AddCommand.MESSAGE_DUPLICATE_TASK);
        assertTrue(taskListPanel.isListMatching(currentList));

        //add invalid dates task
        commandBox.runCommand(td.taskJ.getAddCommand());
        assertResultMessage(AddCommand.ERROR_INVALID_DATES);
        assertTrue(taskListPanel.isListMatching(currentList));

        //add to empty list
        commandBox.runCommand("clear");
        assertAddSuccess(false, false, Lists.newArrayList(new TestCategory
                (AddCommand.BUILT_IN_ALL_TASKS, td.taskA), new TestCategory("Friends", td.taskA)), td.taskA);

        //invalid command
        commandBox.runCommand("adds new task");
        assertResultMessage(Messages.MESSAGE_UNKNOWN_COMMAND);
    }

    private void assertAddSuccess(boolean isPlusSign, boolean isShortCommand,
            List<TestCategory> expectedCategoryList,
            TestTask taskToAdd, TestTask... currentList)
            throws DuplicateCategoryException, IllegalValueException {
        if (isShortCommand) {
            commandBox.runCommand(taskToAdd.getShortAddCommand());
        } else if (isPlusSign) {
            commandBox.runCommand(taskToAdd.getAddCommandPlus());
        } else {
            commandBox.runCommand(taskToAdd.getAddCommand());
        }

        //confirm the new card contains the right data
        TaskCardHandle addedCard = taskListPanel.navigateToTask(taskToAdd.getName().fullName);
        assertMatching(taskToAdd, addedCard);

        //confirm the list now contains all previous tasks plus the new task
        TestTask[] expectedList = TestUtil.addTasksToList(currentList, taskToAdd);
        assertTrue(taskListPanel.isListMatching(expectedList));

        assertTrue(categoryListPanel.isListMatching(expectedCategoryList));
    }

}

@@ -67,87 +67,22 @@
 ort 
-java.util.List;%0A%0Aimport org.junit.Test;%0A%0Aimport com.google.common.collect.Lists
+org.junit.Test
 ;%0A%0Ai
@@ -369,53 +369,8 @@
 on;%0A
-import seedu.taskboss.testutil.TestCategory;%0A
 impo
@@ -711,16 +711,17 @@
 .taskH;%0A
+%0A
         
@@ -754,104 +754,8 @@
 lse,
- Lists.newArrayList(new TestCategory%0A                (AddCommand.BUILT_IN_ALL_TASKS, td.taskA)),
  tas
@@ -947,104 +947,8 @@
 lse,
- Lists.newArrayList(new TestCategory%0A                (AddCommand.BUILT_IN_ALL_TASKS, td.taskA)),
  tas
@@ -1159,104 +1159,8 @@
 rue,
- Lists.newArrayList(new TestCategory%0A                (AddCommand.BUILT_IN_ALL_TASKS, td.taskA)),
  tas
@@ -1375,104 +1375,8 @@
 lse,
- Lists.newArrayList(new TestCategory%0A                (AddCommand.BUILT_IN_ALL_TASKS, td.taskA)),
  tas
@@ -2008,143 +2008,8 @@
 lse,
- Lists.newArrayList(new TestCategory%0A                (AddCommand.BUILT_IN_ALL_TASKS, td.taskA), new TestCategory(%22Friends%22, td.taskA)),
  td.
@@ -2242,73 +2242,8 @@
 and,
-%0A            List%3CTestCategory%3E expectedCategoryList,%0A           
  Tes
@@ -2258,16 +2258,36 @@
 skToAdd,
+%0A                   
  TestTas
@@ -2487,16 +2487,30 @@
  %7D else 
+%7B%0A            
 if (isPl
@@ -2515,24 +2515,28 @@
 PlusSign) %7B%0A
+    
             
@@ -2589,32 +2589,36 @@
 lus());%0A        
+   
+ 
 %7D else %7B%0A       
@@ -2602,32 +2602,36 @@
        %7D else %7B%0A
+    
             comm
@@ -2668,32 +2668,46 @@
 tAddCommand());%0A
+            %7D%0A
         %7D%0A%0A     
@@ -3125,85 +3125,8 @@
 t));
-%0A%0A        assertTrue(categoryListPanel.isListMatching(expectedCategoryList));
 %0A   

Revert "Update AddCommandTest"