//@@author A0147996E
package guitests;

import static org.junit.Assert.assertTrue;
import static seedu.address.logic.commands.AddCommand.COMMAND_ADD;
import static seedu.address.logic.commands.AddCommand.MESSAGE_SUCCESS;

import org.junit.Test;

import seedu.address.commons.core.Messages;
import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.commands.CommandFormatter;
import seedu.address.testutil.TestEvent;
import seedu.address.testutil.TestTask;
import seedu.address.testutil.TestUtil;

public class AddCommandTest extends TaskManagerGuiTest {

    @Test
    public void addTask() {
        //Start testing with an empty list
        TestTask[] currentList = {};
        commandBox.runCommand("clear");

        //add a floating task with name only
        TestTask taskToAdd = td.shopping2;
        assertAddSuccess(taskToAdd, currentList);
        currentList = TestUtil.addTasksToList(currentList, taskToAdd);

        //add a task with other fields other than name
        taskToAdd = td.date;
        assertAddSuccess(taskToAdd, currentList);
        currentList = TestUtil.addTasksToList(currentList, taskToAdd);

        //try to add a duplicate task
        commandBox.runCommand(td.date.getAddCommand());
        assertResultMessage(AddCommand.MESSAGE_DUPLICATE_TASK);
        assertTrue(taskListPanel.isListMatching(currentList));

        //add a task with duplicate name with existing unfinished task under different lists
        taskToAdd = td.date2;
        assertAddSuccess(taskToAdd, currentList);
        currentList = TestUtil.addTasksToList(currentList, taskToAdd);

        //add a task with duplicate name and list but different date
        taskToAdd = td.date3;
        assertAddSuccess(taskToAdd, currentList);
        currentList = TestUtil.addTasksToList(currentList, taskToAdd);

        //add a task with duplicate name, list, date but different time
        taskToAdd = td.date4;
        assertAddSuccess(taskToAdd, currentList);
        currentList = TestUtil.addTasksToList(currentList, taskToAdd);

        //add to empty list
        commandBox.runCommand("clear");
        taskToAdd = td.assignment;
        assertAddSuccess(taskToAdd);
        currentList = TestUtil.addTasksToList(currentList, taskToAdd);
    }

    @Test
    public void addEventsAndTasksToList() {
        //Start testing with an empty list
        commandBox.runCommand("clear");
        TestTask[] currentList = {};

        //add a task to list
        TestTask taskToAdd = td.shopping;
        assertAddSuccess(taskToAdd, currentList);
        currentList = TestUtil.addTasksToList(currentList, taskToAdd);

        //add an event to current list
        TestEvent eventToAdd = te.date;
        assertAddSuccess(eventToAdd, currentList);
        currentList = (TestUtil.addEventsToList(currentList, eventToAdd));

        //add another task
        taskToAdd = td.familyDinner;
        assertAddSuccess(taskToAdd, currentList);
        currentList = TestUtil.addTasksToList(currentList, taskToAdd);

      //add an event to test duplication to current list
        eventToAdd = te.date2;
        assertAddSuccess(eventToAdd, currentList);
        currentList = (TestUtil.addEventsToList(currentList, eventToAdd));

        //add an event to test duplication to current list
        eventToAdd = te.date3;
        assertAddSuccess(eventToAdd, currentList);
        currentList = (TestUtil.addEventsToList(currentList, eventToAdd));
    }

    @Test
    public void invalidCommand () {
        //unknown command
        commandBox.runCommand("adds homework");
        assertResultMessage(Messages.MESSAGE_UNKNOWN_COMMAND);

        //invalid command, task must have a name
        commandBox.runCommand("add p/important");
        assertResultMessage(String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));

        //invalid command, name should be the first field entered
        commandBox.runCommand("add p/important homework");
        assertResultMessage(String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
    }

    private void assertAddSuccess(TestTask taskToAdd, TestTask... currentList) {
        commandBox.runCommand(taskToAdd.getAddCommand());

        //AssertTrue if can navigate to the task card in current list view that matches the taskToAdd
        assertTrue(taskListPanel.navigateToTask(taskToAdd));

        //confirm the list now contains all previous tasks plus the new task
        TestTask[] expectedList = TestUtil.addTasksToList(currentList, taskToAdd);
        assertTrue(taskListPanel.isListMatching(expectedList));
        assertResultMessage(CommandFormatter.undoFormatter(
                String.format(MESSAGE_SUCCESS, taskToAdd.getName()), COMMAND_ADD));
    }
}

@@ -215,16 +215,41 @@
 CCESS;%0A%0A
+import org.junit.Before;%0A
 import o
@@ -591,28 +591,30 @@
 est %7B%0A%0A    @
-Test
+Before
 %0A    public 
@@ -618,23 +618,21 @@
 ic void 
-addTask
+setUp
 () %7B%0A   
@@ -640,118 +640,162 @@
     
-//Start testing with an empty list%0A        TestTask%5B%5D currentList = %7B%7D;%0A        commandBox.runCommand(%22clear%22)
+String initCommand = %22clear%22;%0A        commandBox.runCommand(initCommand);%0A    %7D%0A%0A    @Test%0A    public void addTask() %7B%0A        TestTask%5B%5D currentList = %7B%7D
 ;%0A%0A 
@@ -1033,21 +1033,19 @@
 ith 
-other
+all
  fields 
 othe
@@ -1044,23 +1044,17 @@
 lds 
-other than name
+specified
 %0A   
@@ -1215,21 +1215,8 @@
   //
-try to add a 
 dupl
@@ -1221,24 +1221,30 @@
 plicate task
+ tests
 %0A        com
@@ -1420,101 +1420,8 @@
 );%0A%0A
-        //add a task with duplicate name with existing unfinished task under different lists%0A
     
@@ -1572,77 +1572,8 @@
 );%0A%0A
-        //add a task with duplicate name and list but different date%0A
     
@@ -1724,80 +1724,8 @@
 );%0A%0A
-        //add a task with duplicate name, list, date but different time%0A
     
@@ -1875,363 +1875,68 @@
 d);%0A
-%0A        //add to empty list%0A        commandBox.runCommand(%22clear%22);%0A        taskToAdd = td.assignment;%0A        assertAddSuccess(taskToAdd);%0A        currentList = TestUtil.addTasksToList(currentList, taskToAdd);%0A    %7D%0A%0A    @Test%0A    public void addEventsAndTasksToList() %7B%0A        //Start testing with an empty list%0A        commandBox.runCommand(%22clear%22);
+    %7D%0A%0A    @Test%0A    public void addEventsAndTasksToList() %7B
 %0A   
@@ -1974,37 +1974,8 @@
 %7D;%0A%0A
-        //add a task to list%0A
     
@@ -2138,47 +2138,8 @@
 );%0A%0A
-        //add an event to current list%0A
     
@@ -2305,251 +2305,8 @@
 );%0A%0A
-        //add another task%0A        taskToAdd = td.familyDinner;%0A        assertAddSuccess(taskToAdd, currentList);%0A        currentList = TestUtil.addTasksToList(currentList, taskToAdd);%0A%0A      //add an event to test duplication to current list%0A
     
@@ -2463,67 +2463,8 @@
 );%0A%0A
-        //add an event to test duplication to current list%0A
     
@@ -2673,34 +2673,8 @@
 ) %7B%0A
-        //unknown command%0A
     
@@ -2785,57 +2785,8 @@
 );%0A%0A
-        //invalid command, task must have a name%0A
     
@@ -2947,74 +2947,8 @@
 );%0A%0A
-        //invalid command, name should be the first field entered%0A
     

Update add command test