package seedu.doist.logic.parser;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

import seedu.doist.logic.commands.Command;
import seedu.doist.logic.commands.SaveAtCommand;
import seedu.doist.logic.commands.exceptions.CommandException;
import seedu.doist.model.ModelManager;

//@@author A0140887W
public class SaveAsParserTest {

    @Test
    public void saveAsParser() {
        // a normal relative path
        assertCorrectPath("hello");
        // with new line and space
        assertCorrectPath("/nhello   ");
        // relative path that goes back to drive
        assertCorrectPath("/hello");
        // relative path that goes back to parent folder
        assertCorrectPath("../hello");
        //absolute path
        assertCorrectPath("C:/hello");
        //path with symbols file name
        assertCorrectPath("e@_()()2h2jnuxjdjFso");

        //existing file
        //File file = null;
        //try {
        //   file = File.createTempFile("hello", "");
        //    file.deleteOnExit();
        //    assertFileExists(file.getAbsolutePath());
        //} catch (IOException e) {
        //    fail();
        //}

        //illegal characters
        assertIncorrectPath("***");
        // spaces and new line
        assertIncorrectPath("  \n");
    }


    public void assertCorrectPath(String path) {
        assertPath(path, false, false);
    }

    public void assertIncorrectPath(String path) {
        assertPath(path, true, false);
    }

    public void assertFileExists(String path) {
        assertPath(path, true, true);
    }

    public void assertPath(String path, boolean isCommandExceptionExpected, boolean isFileExist) {
        SaveAtCommandParser parser = new SaveAtCommandParser();
        Command command = parser.parse(path);
        if (isFileExist) {
            assertFeedbackMessage(command, SaveAtCommand.MESSAGE_FILE_EXISTS, isCommandExceptionExpected);
        } else {
            assertFeedbackMessage(command, String.format(SaveAtCommand.MESSAGE_INVALID_PATH,
                    SaveAtCommand.MESSAGE_USAGE), isCommandExceptionExpected);
        }
    }

    public void assertFeedbackMessage(Command returnedCommand, String message, boolean isCommandExceptionExpected) {
        returnedCommand.setData(new ModelManager());
        try {
            returnedCommand.execute();
            assertFalse("CommandException should have been thrown", isCommandExceptionExpected);
        } catch (CommandException e) {
            assertTrue("CommandException should not have been thrown", isCommandExceptionExpected);
            assertEquals(message, e.getMessage());
        }
    }
}

@@ -159,16 +159,103 @@
 ertTrue;
+%0Aimport static org.junit.Assert.fail;%0A%0Aimport java.io.File;%0Aimport java.io.IOException;
 %0A%0Aimport
@@ -1077,18 +1077,16 @@
         
-//
 File fil
@@ -1103,18 +1103,16 @@
         
-//
 try %7B%0A  
@@ -1117,18 +1117,17 @@
         
-//
+ 
    file 
@@ -1166,26 +1166,24 @@
 %22);%0A        
-//
     file.del
@@ -1199,26 +1199,24 @@
 ();%0A        
-//
     assertFi
@@ -1257,18 +1257,16 @@
         
-//
 %7D catch 
@@ -1291,18 +1291,16 @@
         
-//
     fail
@@ -1311,18 +1311,16 @@
         
-//
 %7D%0A%0A     
@@ -1343,24 +1343,24 @@
 racters%0A
-
         
 assertIn
@@ -1343,32 +1343,34 @@
 racters%0A        
+//
 assertIncorrectP

Remove incorrect path test