package guitests;

import org.junit.Test;

import seedu.taskmanager.TestApp;
import seedu.taskmanager.logic.commands.SaveCommand;

import static org.junit.Assert.assertTrue;

public class SaveCommandTest extends TaskManagerGuiTest {

    @Test
    public void clear() {

        //verify can save to another location when list is not empty
        assertTrue(itemListPanel.isListMatching(td.getTypicalItems()));
        commandBox.runCommand(SaveCommand.COMMAND_WORD + " data/new.xml");
        assertSaveCommandSuccess("data/new.xml");
        
        //verify can save to previously specified location (the default save location for testing)
        commandBox.runCommand(SaveCommand.COMMAND_WORD + " " + TestApp.SAVE_LOCATION_FOR_TESTING);
        assertSaveCommandSuccess(TestApp.SAVE_LOCATION_FOR_TESTING);
        
        //verify can save to another location when list is empty
        commandBox.runCommand("clear");
        commandBox.runCommand(SaveCommand.COMMAND_WORD + " data/new2.xml");
        assertSaveCommandSuccess("data/new2.xml");
    }

    private void assertSaveCommandSuccess(String saveToFilePath) {
        assertDataFilePathChanged(saveToFilePath);
        assertResultMessage(String.format(SaveCommand.MESSAGE_SUCCESS, saveToFilePath));
    }
}

@@ -99,176 +99,748 @@
 ger.
-logic.commands.SaveCommand;%0A%0Aimport static org.junit.Assert.assertTrue;%0A%0Apublic class SaveCommandTest extends TaskManagerGuiTest %7B%0A%0A    @Test%0A    public void clear() %7B%0A
+commons.core.Config;%0Aimport seedu.taskmanager.commons.exceptions.DataConversionException;%0Aimport seedu.taskmanager.commons.util.ConfigUtil;%0Aimport seedu.taskmanager.logic.commands.SaveCommand;%0Aimport seedu.taskmanager.testutil.TestUtil;%0A%0Aimport static org.junit.Assert.assertTrue;%0Aimport static seedu.taskmanager.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;%0A%0Apublic class SaveCommandTest extends TaskManagerGuiTest %7B%0A%0A    @Test%0A    public void save() throws DataConversionException %7B%0A%0A        String defaultConfigFilePath = Config.DEFAULT_CONFIG_FILE;%0A        Config currentConfig = ConfigUtil.readConfig(defaultConfigFilePath).orElse(new Config());%0A        String currentFilePath = currentConfig.getTaskManagerFilePath();%0A        
 %0A   
@@ -1036,21 +1036,57 @@
 ORD + %22 
-data/
+%22 + TestUtil.getFilePathInSandboxFolder(%22
 new.xml%22
@@ -1078,32 +1078,33 @@
 older(%22new.xml%22)
+)
 ;%0A        assert
@@ -1122,22 +1122,53 @@
 Success(
-%22data/
+TestUtil.getFilePathInSandboxFolder(%22
 new.xml%22
@@ -1164,24 +1164,25 @@
 r(%22new.xml%22)
+)
 ;%0A        %0A 
@@ -1448,32 +1448,306 @@
 TING);%0A        %0A
+        //verify cannot save to a non .xml file%0A        commandBox.runCommand(SaveCommand.COMMAND_WORD + %22 %22 + TestUtil.getFilePathInSandboxFolder(%22hello.txt%22));%0A        assertResultMessage(String.format(MESSAGE_INVALID_COMMAND_FORMAT, SaveCommand.MESSAGE_USAGE));%0A        %0A
         //verify
@@ -1894,21 +1894,57 @@
 ORD + %22 
-data/
+%22 + TestUtil.getFilePathInSandboxFolder(%22
 new2.xml
@@ -1941,24 +1941,25 @@
 (%22new2.xml%22)
+)
 ;%0A        as
@@ -1985,23 +1985,184 @@
 ess(
-%22data/new2.xml%22
+TestUtil.getFilePathInSandboxFolder(%22new2.xml%22));%0A        %0A        // reset file path to original%0A        commandBox.runCommand(SaveCommand.COMMAND_WORD + %22 %22 + currentFilePath
 );%0A 

Update save tests