//@@author A0147996E
package guitests;

import static org.junit.Assert.assertTrue;
<<<<<<< HEAD
import static seedu.address.logic.commands.UndoCommand.MESSAGE_SUCCESS;

import org.junit.Test;

import seedu.address.testutil.TestEvent;
import seedu.address.testutil.TestTask;

public class UndoCommandTest extends TaskManagerGuiTest {

    @Test
    public void undo_add() {
        TestTask[] currentList = td.getTypicalTasks();

        TestEvent eventToAdd = te.assignment;
        commandBox.runCommand(eventToAdd.getAddCommand());
        assertUndoSuccess(currentList);

        TestTask taskToAdd = td.travel;
        commandBox.runCommand(taskToAdd.getAddCommand());
        assertUndoSuccess(currentList);
    }

    @Test
    public void undo_delete() {
        TestTask[] currentList = td.getTypicalTasks();

        int targetIndex = 2;
        commandBox.runCommand("delete " + targetIndex);
        assertUndoSuccess(currentList);

        targetIndex = 3;
        commandBox.runCommand("delete " + targetIndex);
        assertUndoSuccess(currentList);
    }

    @Test
    public void undo_finish() {
        TestTask[] currentList = td.getTypicalTasks();

        int targetIndex = 2;
        commandBox.runCommand("finish " + targetIndex);
        assertUndoSuccess(currentList);

        targetIndex = 3;
        commandBox.runCommand("finish " + targetIndex);
        assertUndoSuccess(currentList);
    }

    @Test
    public void undo_edit() {
        TestTask[] currentList = td.getTypicalTasks();

        int targetIndex = 2;
        String detailsToEdit = " n/assignment2 dueT/18:30";
        commandBox.runCommand("edit " + targetIndex + detailsToEdit);
        assertUndoSuccess(currentList);

        targetIndex = 4;
        detailsToEdit = " start/03/05/ due/08/05 *u p/important #school";
        commandBox.runCommand("edit " + targetIndex + detailsToEdit);
        assertUndoSuccess(currentList);
    }

    private void assertUndoSuccess(final TestTask[] currentList) {
        commandBox.runCommand("undo");
        //confirm the list now contains all previous tasks
        assertTrue(taskListPanel.isListMatching(currentList));
        //confirm the result message is correct
        assertResultMessage(MESSAGE_SUCCESS);
=======
import static seedu.address.logic.commands.FinishCommand.MESSAGE_FINISH_TASK_SUCCESS;

import org.junit.Test;

import seedu.address.testutil.TestEvent;
import seedu.address.testutil.TestTask;
import seedu.address.testutil.TestUtil;

public class UndoCommandTest extends TaskManagerGuiTest {

    @Test
    public void finishUndoTest() {
        //add some events in first
        TestTask[] currentList = td.getTypicalTasks();
        currentList = TestUtil.addEventsToList(currentList, te.assignment, te.gym);
        TestEvent eventToAdd = te.assignment;
        commandBox.runCommand(eventToAdd.getAddCommand());
        eventToAdd = te.gym;
        commandBox.runCommand(eventToAdd.getAddCommand());

        //finish unfinished task in list all
        int targetIndex = 1;
        assertFinishSuccess(targetIndex, currentList);

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

        commandBox.runCommand("undo");
        commandBox.runCommand("list personal");
        TestTask[] expectedTasks = new TestTask[] {te.gym, td.gym2, td.gym3, td.date};
        assertTrue(taskListPanel.isListMatching(expectedTasks));

        commandBox.runCommand("finish 2");
        commandBox.runCommand("undo");
        commandBox.runCommand("list personal");
        expectedTasks = new TestTask[] {te.gym, td.gym2, td.gym3, td.date};
        assertTrue(taskListPanel.isListMatching(expectedTasks));
    }

    /**
     * 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"));
>>>>>>> origin/master
    }
}

@@ -80,20 +80,8 @@
 ue;%0A
-%3C%3C%3C%3C%3C%3C%3C HEAD
 %0Aimp
@@ -2243,2734 +2243,8 @@
 S);%0A
-=======%0Aimport static seedu.address.logic.commands.FinishCommand.MESSAGE_FINISH_TASK_SUCCESS;%0A%0Aimport org.junit.Test;%0A%0Aimport seedu.address.testutil.TestEvent;%0Aimport seedu.address.testutil.TestTask;%0Aimport seedu.address.testutil.TestUtil;%0A%0Apublic class UndoCommandTest extends TaskManagerGuiTest %7B%0A%0A    @Test%0A    public void finishUndoTest() %7B%0A        //add some events in first%0A        TestTask%5B%5D currentList = td.getTypicalTasks();%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 targetIndex = 1;%0A        assertFinishSuccess(targetIndex, currentList);%0A%0A        //finish tasks or events under a specific list%0A        commandBox.runCommand(%22list personal%22);%0A        targetIndex = 1;%0A        assertFinishSuccess(targetIndex, new TestTask%5B%5D %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, td.gym3, td.date%7D);%0A%0A        commandBox.runCommand(%22undo%22);%0A        commandBox.runCommand(%22list personal%22);%0A        TestTask%5B%5D expectedTasks = new TestTask%5B%5D %7Bte.gym, td.gym2, td.gym3, td.date%7D;%0A        assertTrue(taskListPanel.isListMatching(expectedTasks));%0A%0A        commandBox.runCommand(%22finish 2%22);%0A        commandBox.runCommand(%22undo%22);%0A        commandBox.runCommand(%22list personal%22);%0A        expectedTasks = new TestTask%5B%5D %7Bte.gym, td.gym2, td.gym3, td.date%7D;%0A        assertTrue(taskListPanel.isListMatching(expectedTasks));%0A    %7D%0A%0A    /**%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 command).%0A     */%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        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() + %22 finished%22));%0A%3E%3E%3E%3E%3E%3E%3E origin/master%0A
     

Resolve conflicts