package guitests;

import static org.junit.Assert.assertTrue;

import org.junit.Test;

import guitests.guihandles.TaskCardHandle;
import seedu.address.testutil.TestTask;
import seedu.address.testutil.TestUtil;

public class FinishCommandTest extends TaskManagerGuiTest {
    public void finish() {
        //finish unfinished task
        TestTask[] currentList = td.getTypicalTasks();
        TestTask taskToAdd = td.meeting;
        assertFinishSuccess(taskToAdd, currentList);
        currentList = TestUtil.addTasksToList(currentList, taskToAdd);

        //cannot finish finished task
        //invalid command, index must be positive integer and must not exceed current list length
        //invalid command, command word must be valid
        //invalid command,
    }

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

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

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

@@ -59,75 +59,203 @@
 ue;%0A
-%0A
 import 
-org.junit.Test;%0A%0Aimport guit
+static seedu.address.logic.commands.FinishCommand.MESSAGE_FINISH_TASK_SUCCESS;%0Aimport static seedu.addr
 es
-t
 s.
-guihandles.TaskCardHandle;
+logic.commands.FinishCommand.MESSAGE_FINISH_TASK_MARKED;%0A%0Aimport org.junit.Test;%0A
 %0Aimp
@@ -392,16 +392,26 @@
 iTest %7B%0A
+    @Test%0A
     publ
@@ -529,39 +529,27 @@
     
-TestTask taskToAdd = td.meeting
+int targetIndex = 1
 ;%0A  
@@ -576,23 +576,25 @@
 ccess(ta
-skToAdd
+rgetIndex
 , curren
@@ -605,88 +605,180 @@
 t);%0A
-        currentList = TestUtil.addTasksToList(currentList, taskToAdd
+%0A        //cannot finish finished task%0A        currentList = td.getTypicalTasks();%0A        targetIndex = 1;%0A        commandBox.runCommand(%22finish %22 + targetIndex
 );%0A
-%0A
         
 //ca
@@ -777,37 +777,155 @@
     
-//cannot finish finished task
+commandBox.runCommand(%22list all%22);%0A        commandBox.runCommand(%22finish %22 + targetIndex);%0A        assertResultMessage(MESSAGE_FINISH_TASK_MARKED);
 %0A   
@@ -1115,549 +1115,1033 @@
     
-private void assertFinishSuccess(TestTask taskToAdd, TestTask... currentList) %7B%0A        commandBox.runCommand(taskToAdd.getAddC
+/**%0A     * Runs the finish command to finish the task at specified index and confirms the result is correct.%0A     * @param targetIndexOneIndexed e.g. index 1 to finish the first task in the list,%0A     * @param currentList A copy of the current unfinished list of tasks (before finish c
 ommand
-());%0A
+).
 %0A     
-   //confirm the new card contains the right data%0A        TaskCardHandle addedCard = taskListPanel.navigateToTask(taskToAdd);%0A        assertMatching(taskToAdd, addedCard);%0A%0A        //confirm the list now contains all previous persons plus the new person%0A        TestTask%5B%5D expectedList = TestUtil.addTasksToList(currentList, taskToAdd);%0A        assertTrue(taskListPanel.isListMatching(expectedList
+*/%0A    private void assertFinishSuccess(int targetIndexOneIndexed, final TestTask%5B%5D currentList) %7B%0A        TestTask taskToFinish = currentList%5BtargetIndexOneIndexed - 1%5D; // -1 as array uses zero indexing%0A        //TestTask%5B%5D expectedRemainder = TestUtil.removeTaskFromList(currentList, targetIndexOneIndexed);%0A        TestTask%5B%5D expectedRemainder = currentList;%0A        commandBox.runCommand(%22finish %22 + targetIndexOneIndexed);%0A%0A        //confirm the list now contains all previous tasks except the finished task%0A        assertTrue(taskListPanel.isListMatching(expectedRemainder));%0A%0A        //confirm the result message is correct%0A        assertResultMessage(String.format(MESSAGE_FINISH_TASK_SUCCESS, taskToFinish.toString()
 ));%0A

Update FinishCommandTest