//@@ author A0147996E
package guitests;

import static org.junit.Assert.assertTrue;
import static seedu.address.logic.commands.FinishCommand.MESSAGE_FINISH_TASK_MARKED;
import static seedu.address.logic.commands.FinishCommand.MESSAGE_FINISH_TASK_SUCCESS;

import org.junit.Test;

import seedu.address.commons.core.Messages;
import seedu.address.testutil.TestTask;
import seedu.address.testutil.TestUtil;

public class FinishCommandTest extends TaskManagerGuiTest {

    @Test
    public void finishValidTest() {
        //finish unfinished task in list all
        TestTask[] currentList = td.getTypicalTasks();
        int targetIndex = 1;
        assertFinishSuccess(targetIndex, currentList);

        //finish tasks under a specific list
        commandBox.runCommand("list personal");
        targetIndex = 1;
        assertFinishSuccess(targetIndex, new TestTask[] {td.gym, td.gym2, td.gym3, td.date});

        //cannot finish task that has already been marked as finished
        currentList = td.getTypicalTasks();
        targetIndex = 1;
        commandBox.runCommand("finish " + targetIndex);
        commandBox.runCommand("list all");
        commandBox.runCommand("finish " + targetIndex);
        assertResultMessage(MESSAGE_FINISH_TASK_MARKED);

        //invalid command, index must be positive integer and must not exceed current list length
        currentList = td.getTypicalTasks();
        targetIndex = 8;
        commandBox.runCommand("finish " + targetIndex);
        assertResultMessage(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);

        //invalid command, command word must be valid
        commandBox.runCommand("finishes " + targetIndex);
        assertResultMessage(Messages.MESSAGE_UNKNOWN_COMMAND);
    }

    /**
     * Runs the finish command to finish the task at specified index and confirms the result is correct.
     * @param targetIndexOneIndexed e.g. index 1 to finish the first task in the list,
     * @param currentList A copy of the current unfinished list of tasks (before finish command).
     */
    private void assertFinishSuccess(int targetIndexOneIndexed, final TestTask[] currentList) {
        TestTask taskToFinish = currentList[targetIndexOneIndexed - 1]; // -1 as array uses zero indexing
        TestTask[] expectedRemainder = TestUtil.removeTaskFromList(currentList, targetIndexOneIndexed);
        commandBox.runCommand("finish " + targetIndexOneIndexed);

        //confirm the list now contains all previous tasks except the finished task
        assertTrue(taskListPanel.isListMatching(expectedRemainder));

        //confirm the result message is correct
        assertResultMessage(String.format(MESSAGE_FINISH_TASK_SUCCESS, taskToFinish.toString() + " finished"));
    }
}

@@ -317,16 +317,57 @@
 ssages;%0A
+import seedu.address.testutil.TestEvent;%0A
 import s
@@ -499,17 +499,16 @@
 iTest %7B%0A
-%0A
     @Tes
@@ -559,42 +559,32 @@
   //
-finish unfinished task in list all
+add some events in first
 %0A   
@@ -627,32 +627,355 @@
 TypicalTasks();%0A
+        currentList = TestUtil.addEventsToList(currentList, te.assignment, te.gym);%0A        TestEvent eventToAdd = te.assignment;%0A        commandBox.runCommand(eventToAdd.getAddCommand());%0A        eventToAdd = te.gym;%0A        commandBox.runCommand(eventToAdd.getAddCommand());%0A%0A        //finish unfinished task in list all%0A
         int targ
@@ -1066,16 +1066,26 @@
 h tasks 
+or events 
 under a 
@@ -1235,16 +1235,143 @@
 %7Btd.gym,
+ te.gym, td.gym2, td.gym3, td.date%7D);%0A        targetIndex = 2;%0A        assertFinishSuccess(targetIndex, new TestTask%5B%5D %7Bte.gym,
  td.gym2
@@ -1467,52 +1467,8 @@
 hed%0A
-        currentList = td.getTypicalTasks();%0A
     
@@ -1811,67 +1811,96 @@
     
-currentList = td.getTypicalTasks();%0A        targetIndex = 8
+int maxIndex = currentList.length;%0A        System.out.println(targetIndex + %22I am here%22)
 ;%0A  
@@ -1935,35 +1935,38 @@
 %22finish %22 + 
-targetIndex
+(maxIndex + 2)
 );%0A        a

Update finish command test