package guitests;

import java.util.Optional;
import java.util.logging.Logger;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import seedu.taskell.TestApp;
import seedu.taskell.commons.core.Config;
import seedu.taskell.commons.core.LogsCenter;
import seedu.taskell.commons.exceptions.DataConversionException;
import seedu.taskell.storage.JsonConfigStorage;

public class SaveStorageLocationCommandTest extends TaskManagerGuiTest {
    
    private static final Logger logger = LogsCenter.getLogger(SaveStorageLocationCommandTest.class);
    
    private static final String CONFIG_JSON = "config.json";
    private static final String CONFIG_LOCATION = "./src/test/data/SaveLocationCommandTest";
    
    private static final String DEFAULT_SAVE_LOCATION = TestApp.SAVE_LOCATION_FOR_TESTING;
    
    @Test
    public void saveToValidFilePath() throws DataConversionException {
        commandBox.runCommand("save cat/");
        assertWriteToJsonSuccess();
    }
    
    @Test
    public void saveToInvalidFilePath() throws DataConversionException {
        JsonConfigStorage jsonConfigStorage = new JsonConfigStorage(CONFIG_LOCATION);

        commandBox.runCommand("save E:");   
        
        Optional<Config> newConfig = jsonConfigStorage.readConfig(CONFIG_JSON);
        
        String newFilePath = newConfig.get().getTaskManagerFilePath();

        logger.severe("New path: " + newFilePath);
        
        assert(newFilePath.equals(DEFAULT_SAVE_LOCATION));
    }
    
    private void assertWriteToJsonSuccess() throws DataConversionException {
        JsonConfigStorage jsonConfigStorage = new JsonConfigStorage(CONFIG_LOCATION);
        Optional<Config> config = jsonConfigStorage.readConfig(CONFIG_JSON);
        assert(config.isPresent());
    } 
    

}

@@ -12,16 +12,44 @@
 tests;%0A%0A
+import java.io.IOException;%0A
 import j
@@ -97,23 +97,21 @@
 ng.L
-ogger;%0A
+evel;
 %0Aimport 
 org.
@@ -110,87 +110,56 @@
 ort 
-org.junit.Rule;%0Aimport org.junit.Test;%0Aimport org.junit.rules.ExpectedException
+java.util.logging.Logger;%0A%0Aimport org.junit.Test
 ;%0A%0Ai
@@ -336,24 +336,88 @@
 nException;%0A
+import seedu.taskell.logic.commands.SaveStorageLocationCommand;%0A
 import seedu
@@ -1009,19 +1009,74 @@
 d(%22save 
-cat
+./src/test/data/SaveLocationCommandTest/newStorageLocation
 /%22);%0A   
@@ -1630,24 +1630,827 @@
 %0A    %7D%0A    %0A
+    /** NOTE: because of the way SaveStorageLocationCommand works after running this command%0A     *          config.json in Taskell saves the test data so this method is necessary to reset%0A     *          config.json to default data%0A     * */%0A    @Test%0A    public void resetConfigFile() throws IOException %7B%0A        Config config = new Config();%0A        config.setAppTitle(%22Taskell%22);%0A        config.setLogLevel(Level.INFO);%0A        config.setUserPrefsFilePath(%22preferences.json%22);%0A        config.setTaskManagerFilePath(%22data/taskmanager.xml%22);%0A        config.setTaskManagerName(%22MyTaskManager%22);%0A        SaveStorageLocationCommand.setConfig(config);%0A        %0A        JsonConfigStorage jsonConfigStorage = new JsonConfigStorage(CONFIG_JSON);%0A        jsonConfigStorage.saveConfigFile(config);%0A    %7D%0A    %0A
     private 

edit SaveStorageLocationCommand to change filepath and resetConfigFile()