//@@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.commons.exceptions.IllegalValueException;
import seedu.address.testutil.TestTask;
import seedu.address.testutil.TestUtil;

public class FinishCommandTest extends TaskManagerGuiTest {
    private TestTask[] currentList = td.getTypicalTasks();

    @Test
    public void finish_recurringTask_finishSuccess() throws IllegalValueException {
        commandBox.runCommand("clear");
        TestTask[] currentList = {};
        int targetIndex = 1;
        currentList = TestUtil.addTasksToList(currentList, tr.gym);
        commandBox.runCommand(tr.gym.getAddCommand());

        currentList = TestUtil.addTasksToList(currentList, tr.cs2103);
        commandBox.runCommand(tr.cs2103.getAddCommand());

        commandBox.runCommand("finish " + targetIndex);
        currentList[targetIndex - 1].setDate("27/12/2017");

        targetIndex = 2;
        commandBox.runCommand("finish " + targetIndex);
        currentList[targetIndex - 1].setDate("01/03/2018");
        assertTrue(taskListPanel.isListMatching(currentList));
    }

    @Test
    public void finish_validIndexTest_finishSuccess() {
        int targetIndex = 1;
        assertFinishSuccess(targetIndex);
        targetIndex = currentList.length / 2;
        assertFinishSuccess(targetIndex);
        targetIndex = currentList.length;
        assertFinishSuccess(targetIndex);
    }

    @Test
    public void finish_alreadyFinishedTask_finishUnsuccess() {
        int targetIndex = 1;
        commandBox.runCommand("finish " + targetIndex);
        commandBox.runCommand("list all");
        commandBox.runCommand("finish " + targetIndex);
        assertResultMessage(MESSAGE_FINISH_TASK_MARKED);
    }

    @Test
    public void finish_outOfBoundInx_finishUnsuccess() {
        int maxIndex = currentList.length;
        commandBox.runCommand("finish " + (maxIndex + 1));
        assertResultMessage(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
    }

    @Test
    public void finish_invalidCommandFormat_unknownCommand() {
        commandBox.runCommand("finishes 1");
        assertResultMessage(Messages.MESSAGE_UNKNOWN_COMMAND);
    }

    @Test
    public void finish_validEvent_finishSuccess() {
        commandBox.runCommand("clear");
        commandBox.runCommand("add testEvent startT/22:00 due/today");
        commandBox.runCommand("finish 1");
        assertTrue(taskListPanel.isListMatching());
    }

    /**
     * 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) {
        TestTask taskToFinish = currentList[targetIndexOneIndexed - 1]; // -1 as array uses zero indexing
        currentList = TestUtil.removeTaskFromList(currentList, targetIndexOneIndexed);

        commandBox.runCommand("finish " + targetIndexOneIndexed);
        assertResultMessage(String.format(MESSAGE_FINISH_TASK_SUCCESS, taskToFinish.getName()));
        commandBox.runCommand("list");
        assertTrue(taskListPanel.isListMatching(currentList));
    }
}

@@ -2553,111 +2553,567 @@
     
-commandBox.runCommand(%22add testEvent startT/22:00 due/today%22);%0A        commandBox.runCommand(%22finish 1%22
+TestTask%5B%5D currentList = %7B%7D;%0A        int targetIndex = 1;%0A        currentList = TestUtil.addTasksToList(currentList, te.gym);%0A        commandBox.runCommand(te.gym.getAddCommand());%0A%0A        currentList = TestUtil.addTasksToList(currentList, te.cs2103);%0A        commandBox.runCommand(te.cs2103.getAddCommand());%0A%0A        commandBox.runCommand(%22finish %22 + targetIndex);%0A        currentList%5BtargetIndex - 1%5D.setFinished(true);%0A%0A        targetIndex = 1;%0A        commandBox.runCommand(%22finish %22 + targetIndex);%0A        currentList%5BtargetIndex - 1%5D.setFinished(true
 );%0A 
@@ -3159,24 +3159,25 @@
 atching());%0A
+%0A
     %7D%0A%0A    /

Modify testcase for FinishCommand