package guitests;

import org.junit.Test;

import seedu.lifekeeper.testutil.TestActivity;
import seedu.lifekeeper.testutil.TestUtil;

import static org.junit.Assert.assertTrue;
import static seedu.lifekeeper.logic.commands.DeleteCommand.MESSAGE_DELETE_TASK_SUCCESS;
//@@author A0125097A
public class DeleteCommandTest extends AddressBookGuiTest {

    @Test
    public void delete() {

        //delete the first in the list
        TestActivity[] currentList = td.getTypicalActivities();
        int targetIndex = 1;
        assertDeleteSuccess(targetIndex, currentList);

        //delete the last in the list
        currentList = TestUtil.removeActivityFromList(currentList, targetIndex);
        targetIndex = currentList.length;
        assertDeleteSuccess(targetIndex, currentList);

        //delete from the middle of the list
        currentList = TestUtil.removeActivityFromList(currentList, targetIndex);
        targetIndex = currentList.length/2;
        assertDeleteSuccess(targetIndex, currentList);

        //invalid index
        commandBox.runCommand("delete " + currentList.length + 1);
        assertResultMessage("The task index provided is invalid");

    }

    /**
     * Runs the delete command to delete the activity at specified index and confirms the result is correct.
     * @param targetIndexOneIndexed e.g. to delete the first activity in the list, 1 should be given as the target index.
     * @param currentList A copy of the current list of persons (before deletion).
     */
    private void assertDeleteSuccess(int targetIndexOneIndexed, final TestActivity[] currentList) {
        TestActivity personToDelete = currentList[targetIndexOneIndexed-1]; //-1 because array uses zero indexing
        TestActivity[] expectedRemainder = TestUtil.removeActivityFromList(currentList, targetIndexOneIndexed);

        commandBox.runCommand("delete " + targetIndexOneIndexed);

        //confirm the list now contains all previous persons except the deleted activity
        assertTrue(activityListPanel.isListMatching(expectedRemainder));

        //confirm the result message is correct
        assertResultMessage(String.format(MESSAGE_DELETE_TASK_SUCCESS, personToDelete.getAsText()));
    }

}

@@ -205,65 +205,273 @@
 per.
-logic.commands.DeleteCommand.MESSAGE_DELETE_TASK_SUCCESS;
+commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;%0Aimport static seedu.lifekeeper.logic.commands.DeleteCommand.MESSAGE_DELETE_TASK_SUCCESS;%0Aimport static seedu.lifekeeper.logic.commands.DeleteCommand.MESSAGE_USAGE;%0Aimport seedu.lifekeeper.commons.core.Messages;%0A
 %0A//@
@@ -585,14 +585,24 @@
 lete
+_validIndex
 () %7B%0A
-%0A
     
@@ -993,33 +993,34 @@
 , currentList);%0A
+ 
 %0A
-
         //delete
@@ -1173,11 +1173,21 @@
 ngth
-/2;
+ / 2;        
 %0A   
@@ -1242,32 +1242,182 @@
 t);%0A
+    %7D
 %0A    
+%0A
     
-//invalid index
+@Test%0A    public void delete_invalidIndex() %7B%0A        TestActivity%5B%5D currentList = td.getTypicalActivities();%0A        int targetIndex = currentList.length + 1;
 %0A   
@@ -1455,38 +1455,27 @@
 ete %22 + 
-currentList.length + 1
+targetIndex
 );%0A     
@@ -1501,48 +1501,202 @@
 age(
-%22The task index provided is invalid%22
+Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);%0A        %0A        commandBox.runCommand(%22delete %22 + 0);%0A        assertResultMessage(String.format(MESSAGE_INVALID_COMMAND_FORMAT, MESSAGE_USAGE)
 );%0A
-%0A
     

Refactor DeleteCommandTest