// @@author A0147944U
package guitests;

import org.junit.Test;

import seedu.task.commons.core.Messages;
import seedu.task.logic.commands.BackupCommand;
import seedu.task.testutil.TestUtil;
import seedu.task.testutil.TypicalTestTasks;

import static org.junit.Assert.assertTrue;

@SuppressWarnings("unused")
public class BackupCommandTest extends TaskManagerGuiTest {

    public static final String filepath_A = TestUtil.getFilePathInSandboxFolder("empty");
    public static final String filepath_B = TestUtil.getFilePathInSandboxFolder("notempty");
    public static final String filepath_C = "c:/inaccessible";
    public static final String filepath_D = "invalid:/drive";
    public static final String filepath_E = "c:/invalid>character";

    @Test
    public void backup() {

        /** Removed temporarily as these cases do not work on Travis, i.e. C:/ is accessible, invaild:/drive is valid */
        /*
        //verify an empty TaskManager can be backed up in a valid directory
        commandBox.runCommand("clear");
        assertListSize(0);
        assertResultMessage("Task manager has been cleared!");
        commandBox.runCommand("backup " + filepath_A);
        assertResultMessage(String.format(BackupCommand.MESSAGE_BACKUP_SUCCESS, filepath_A + ".xml"));
        //assertBackupCommandSuccess();
        
        //verify a non-empty TaskManager can be backed up in a valid directory
        commandBox.runCommand("add Help Jim with his task, at 2016-10-25 9am");
        assertTrue(taskListPanel.isListMatching(TypicalTestTasks.taskH));
        commandBox.runCommand("backup " + filepath_B);
        assertResultMessage(String.format(BackupCommand.MESSAGE_BACKUP_SUCCESS, filepath_B + ".xml"));
        //assertBackupCommandSuccess();
        
        //verify TaskManager can be backed up in a valid directory onto an existing backup
        commandBox.runCommand("backup " + filepath_A);
        assertResultMessage(String.format(BackupCommand.MESSAGE_BACKUP_SUCCESS, filepath_A + ".xml"));
        //assertBackupCommandSuccess();

        //verify a TaskManager can't be backed up in an inaccessible directory
        commandBox.runCommand("backup " + filepath_C);
        assertResultMessage(String.format(BackupCommand.MESSAGE_BACKUP_FAILURE, filepath_C + ".xml"));
        //assertBackupCommandFailure();
        
        //verify a TaskManager can't be backed up in an invalid directory
        commandBox.runCommand("backup " + filepath_D);
        assertResultMessage(String.format(BackupCommand.MESSAGE_BACKUP_FAILURE, filepath_D + ".xml"));
        //assertBackupCommandFailure();
        commandBox.runCommand("backup " + filepath_E);
        assertResultMessage(String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT, BackupCommand.MESSAGE_USAGE));
        //assertBackupCommandFailure();
         */
    }
}

@@ -62,49 +62,8 @@
 t;%0A%0A
-import seedu.task.commons.core.Messages;%0A
 impo
@@ -237,36 +237,8 @@
 e;%0A%0A
-@SuppressWarnings(%22unused%22)%0A
 publ
@@ -375,21 +375,39 @@
 Folder(%22
-empty
+backup_not_pre_existing
 %22);%0A    
@@ -487,16 +487,27 @@
 er(%22
-notempty
+backup_pre_existing
 %22);%0A
@@ -703,178 +703,139 @@
 r%22;%0A
-%0A    @Test%0A    public void backup() %7B%0A%0A        /** Removed temporarily as these cases do not work on Travis, i.e. C:/ is accessible, invaild:/drive is valid */%0A        /*
+    public static final String filepath_F = TestUtil.getFilePathInSandboxFolder(%22protected%22);%0A%0A    @Test%0A    public void backup() %7B
 %0A   
@@ -1195,49 +1195,20 @@
 xml%22
-));%0A        //assertBackupCommandSuccess(
+, %22created%22)
 );%0A 
@@ -1606,49 +1606,24 @@
 xml%22
-));%0A        //assertBackupCommandSuccess(
+, %22overwritten%22)
 );%0A 
@@ -1867,36 +1867,52 @@
 epath_A + %22.xml%22
+, %22overwritten%22
 ));%0A
+%0A
         //assert
@@ -1908,39 +1908,71 @@
    /
-/assertBackupCommandSuccess();%0A
+* Disabled as Travis is does not have an inaccessible directory
 %0A   
@@ -2217,122 +2217,147 @@
     
-//assertBackupCommandFailure();%0A        %0A        //verify a TaskManager can't be backed up in an invalid directory
+*/%0A        %0A        /* Disabled as unable to test with FilePicker%0A        //verify if invalid directory given, FilePicker will be presented
 %0A   
@@ -2515,48 +2515,8 @@
 ));%0A
-        //assertBackupCommandFailure();%0A
     
@@ -2692,51 +2692,241 @@
     
-//assertBackupCommandFailure();%0A         */
+*/%0A        %0A        //verify a TaskManager will detect if a file is protected%0A        commandBox.runCommand(%22backup %22 + filepath_F);%0A        assertResultMessage(String.format(BackupCommand.MESSAGE_BACKUP_ERROR, filepath_F + %22.xml%22));
 %0A   

improve and update backupcommandtest