From fa2cbcd18636de48a979f37e56ecbbb2e0c9959c Mon Sep 17 00:00:00 2001 From: Irvin Lim Date: Mon, 7 Nov 2016 04:58:48 +0800 Subject: [PATCH 1/8] Add disambiguation for ConfigController --- .../todo/controllers/ConfigController.java | 93 +++++++++---------- 1 file changed, 45 insertions(+), 48 deletions(-) diff --git a/src/main/java/seedu/todo/controllers/ConfigController.java b/src/main/java/seedu/todo/controllers/ConfigController.java index e57db4ab3f97..c63b5304c1e6 100644 --- a/src/main/java/seedu/todo/controllers/ConfigController.java +++ b/src/main/java/seedu/todo/controllers/ConfigController.java @@ -10,12 +10,11 @@ import seedu.todo.models.TodoListDB; import seedu.todo.ui.UiManager; +// @@author A0139812A /** * Controller to configure app settings. * Has side effects, since it has to perform * updates on the UI or file sources on update. - * - * @@author A0139812A */ public class ConfigController extends Controller { @@ -29,6 +28,7 @@ public class ConfigController extends Controller { private static final String MESSAGE_FAILURE = "Could not update settings: %s"; private static final String MESSAGE_INVALID_INPUT = "Invalid config setting provided!"; private static final String MESSAGE_WRONG_EXTENSION = "Could not change storage path: File must end with %s"; + private static final String TEMPLATE_SET_CONFIG = "config "; private static final String SPACE = " "; private static final int ARGS_LENGTH = 2; private static final String DB_FILE_EXTENSION = ".json"; @@ -45,58 +45,55 @@ public CommandDefinition getCommandDefinition() { public void process(String input) { String params = input.replaceFirst("config", "").trim(); + // Check for basic command. if (params.length() <= 0) { - - // Showing all configs Renderer.renderConfig(MESSAGE_SHOWING); + return; + } + + // Check args length + String[] args = params.split(SPACE, ARGS_LENGTH); + if (args.length != ARGS_LENGTH) { + Renderer.renderDisambiguation(TEMPLATE_SET_CONFIG, MESSAGE_INVALID_INPUT); + return; + } + + assert args.length == ARGS_LENGTH; + + // Split by args + String configName = args[0]; + String configValue = args[1]; + + // Get current config + Config config = ConfigCenter.getInstance().getConfig(); + + // Check name + List validConfigDefinitions = config.getDefinitionsNames(); + if (!validConfigDefinitions.contains(configName)) { + Renderer.renderDisambiguation(TEMPLATE_SET_CONFIG, MESSAGE_INVALID_INPUT); + return; + } - } else { - - String[] args = params.split(SPACE, ARGS_LENGTH); - - // Check args length - if (args.length != ARGS_LENGTH) { - Renderer.renderConfig(MESSAGE_INVALID_INPUT); - return; - } - - assert args.length == ARGS_LENGTH; - - // Split by args - String configName = args[0]; - String configValue = args[1]; - - // Get current config - Config config = ConfigCenter.getInstance().getConfig(); - - // Check name - List validConfigDefinitions = config.getDefinitionsNames(); - if (!validConfigDefinitions.contains(configName)) { - Renderer.renderConfig(MESSAGE_INVALID_INPUT); - return; - } - - assert validConfigDefinitions.contains(configName); - - // Update config value - try { - config = updateConfigByName(config, configName, configValue); - } catch (CannotConfigureException e) { - Renderer.renderConfig(e.getMessage()); - return; - } + assert validConfigDefinitions.contains(configName); - // Save config to file - try { - ConfigCenter.getInstance().saveConfig(config); - } catch (IOException e) { - Renderer.renderConfig(String.format(MESSAGE_FAILURE, e.getMessage())); - return; - } + // Update config value + try { + config = updateConfigByName(config, configName, configValue); + } catch (CannotConfigureException e) { + Renderer.renderConfig(e.getMessage()); + return; + } - // Update console for success - Renderer.renderConfig(String.format(MESSAGE_SUCCESS, configName)); + // Save config to file + try { + ConfigCenter.getInstance().saveConfig(config); + } catch (IOException e) { + Renderer.renderConfig(String.format(MESSAGE_FAILURE, e.getMessage())); + return; } + + // Update console for success + Renderer.renderConfig(String.format(MESSAGE_SUCCESS, configName)); } /** From de358c99d78dbb86b84289bf1cfbe01464f9caff Mon Sep 17 00:00:00 2001 From: Irvin Lim Date: Mon, 7 Nov 2016 05:07:18 +0800 Subject: [PATCH 2/8] Improve SLAP --- .../todo/controllers/ConfigController.java | 59 +++++++++---------- 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/src/main/java/seedu/todo/controllers/ConfigController.java b/src/main/java/seedu/todo/controllers/ConfigController.java index c63b5304c1e6..505c47208b82 100644 --- a/src/main/java/seedu/todo/controllers/ConfigController.java +++ b/src/main/java/seedu/todo/controllers/ConfigController.java @@ -1,7 +1,6 @@ package seedu.todo.controllers; import java.io.IOException; -import java.util.List; import seedu.todo.commons.core.Config; import seedu.todo.commons.core.ConfigCenter; @@ -29,7 +28,8 @@ public class ConfigController extends Controller { private static final String MESSAGE_INVALID_INPUT = "Invalid config setting provided!"; private static final String MESSAGE_WRONG_EXTENSION = "Could not change storage path: File must end with %s"; private static final String TEMPLATE_SET_CONFIG = "config "; - private static final String SPACE = " "; + + private static final String STRING_SPACE = " "; private static final int ARGS_LENGTH = 2; private static final String DB_FILE_EXTENSION = ".json"; @@ -52,42 +52,29 @@ public void process(String input) { } // Check args length - String[] args = params.split(SPACE, ARGS_LENGTH); + String[] args = params.split(STRING_SPACE, ARGS_LENGTH); if (args.length != ARGS_LENGTH) { Renderer.renderDisambiguation(TEMPLATE_SET_CONFIG, MESSAGE_INVALID_INPUT); return; } - assert args.length == ARGS_LENGTH; - - // Split by args String configName = args[0]; String configValue = args[1]; - - // Get current config Config config = ConfigCenter.getInstance().getConfig(); - // Check name - List validConfigDefinitions = config.getDefinitionsNames(); - if (!validConfigDefinitions.contains(configName)) { + // Check if configName is a valid name. + if (!config.getDefinitionsNames().contains(configName)) { Renderer.renderDisambiguation(TEMPLATE_SET_CONFIG, MESSAGE_INVALID_INPUT); return; } - assert validConfigDefinitions.contains(configName); - - // Update config value try { + // Update config value config = updateConfigByName(config, configName, configValue); - } catch (CannotConfigureException e) { - Renderer.renderConfig(e.getMessage()); - return; - } - - // Save config to file - try { + + // Save config to file ConfigCenter.getInstance().saveConfig(config); - } catch (IOException e) { + } catch (CannotConfigureException | IOException e) { Renderer.renderConfig(String.format(MESSAGE_FAILURE, e.getMessage())); return; } @@ -118,17 +105,8 @@ private Config updateConfigByName(Config config, String configName, String confi break; case "databaseFilePath" : - // Make sure the new path has a .json extension - if (!configValue.endsWith(DB_FILE_EXTENSION)) { - throw new CannotConfigureException(String.format(MESSAGE_WRONG_EXTENSION, DB_FILE_EXTENSION)); - } - // Move the DB file to the new location - try { - TodoListDB.getInstance().move(configValue); - } catch (IOException e) { - throw new CannotConfigureException(e.getMessage()); - } + moveDatabaseFile(configValue); // Update config config.setDatabaseFilePath(configValue); @@ -141,5 +119,22 @@ private Config updateConfigByName(Config config, String configName, String confi return config; } + + /** + * Moves the database file to the new location. + * Throws an exception if the new path does not exist, or if it has the wrong extension. + */ + private void moveDatabaseFile(String newPath) throws CannotConfigureException { + // Make sure the new path has a .json extension + if (!newPath.endsWith(DB_FILE_EXTENSION)) { + throw new CannotConfigureException(String.format(MESSAGE_WRONG_EXTENSION, DB_FILE_EXTENSION)); + } + + try { + TodoListDB.getInstance().move(newPath); + } catch (IOException e) { + throw new CannotConfigureException(e.getMessage()); + } + } } From c66af20fd51265648250aa5f7d2e5da6b82ebca6 Mon Sep 17 00:00:00 2001 From: louietyj Date: Mon, 7 Nov 2016 04:49:10 +0800 Subject: [PATCH 3/8] Tests are running too slowly >< --- src/test/java/seedu/todo/guitests/guihandles/ConsoleHandle.java | 2 +- src/test/java/seedu/todo/guitests/guihandles/GuiHandle.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/seedu/todo/guitests/guihandles/ConsoleHandle.java b/src/test/java/seedu/todo/guitests/guihandles/ConsoleHandle.java index b768981ff34e..e543c8cc90bd 100644 --- a/src/test/java/seedu/todo/guitests/guihandles/ConsoleHandle.java +++ b/src/test/java/seedu/todo/guitests/guihandles/ConsoleHandle.java @@ -10,7 +10,7 @@ public class ConsoleHandle extends GuiHandle { private static final String CONSOLE_INPUT_ID = "#consoleInputTextField"; private static final String CONSOLE_TEXT_ID = "#consoleTextArea"; - private static final int COMMAND_WAIT_TIME = 100; + private static final int COMMAND_WAIT_TIME = 10; public ConsoleHandle(GuiRobot guiRobot, Stage primaryStage, String stageTitle) { super(guiRobot, primaryStage, stageTitle); diff --git a/src/test/java/seedu/todo/guitests/guihandles/GuiHandle.java b/src/test/java/seedu/todo/guitests/guihandles/GuiHandle.java index 0145a39d66f2..8386f2af5bd5 100644 --- a/src/test/java/seedu/todo/guitests/guihandles/GuiHandle.java +++ b/src/test/java/seedu/todo/guitests/guihandles/GuiHandle.java @@ -68,7 +68,7 @@ protected String getTextAreaText(String filedName) { protected void setTextField(String textFieldId, String newText) { guiRobot.clickOn(textFieldId); ((TextField) guiRobot.lookup(textFieldId).tryQuery().get()).setText(newText); - guiRobot.sleep(20); // so that the texts stays visible on the GUI for a short period + guiRobot.sleep(10); // so that the texts stays visible on the GUI for a short period } public void pressEnter() { From ac88b767f539f48bec8cab4f9d02ee8c79607301 Mon Sep 17 00:00:00 2001 From: Irvin Lim Date: Mon, 7 Nov 2016 05:17:02 +0800 Subject: [PATCH 4/8] Initialize IndexView in TestApp --- src/test/java/seedu/todo/TestApp.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/test/java/seedu/todo/TestApp.java b/src/test/java/seedu/todo/TestApp.java index 63ce1417d1a3..3e075045d0e4 100644 --- a/src/test/java/seedu/todo/TestApp.java +++ b/src/test/java/seedu/todo/TestApp.java @@ -10,6 +10,8 @@ import seedu.todo.storage.JsonStorage; import seedu.todo.storage.Storage; import seedu.todo.testutil.TestUtil; +import seedu.todo.ui.UiManager; +import seedu.todo.ui.views.IndexView; public class TestApp extends MainApp { @@ -55,9 +57,8 @@ protected Config initConfig() { @Override public void start(Stage primaryStage) { ui.start(primaryStage); - } - public static void main(String[] args) { - launch(args); + IndexView view = UiManager.loadView(IndexView.class); + UiManager.renderView(view); } } From 97949d0185cbd33ae1ea6c2f3eca48da8765ffdd Mon Sep 17 00:00:00 2001 From: Irvin Lim Date: Mon, 7 Nov 2016 04:37:29 +0800 Subject: [PATCH 5/8] Add Config GuiHandles --- .../resources/ui/components/ConfigItem.fxml | 2 +- .../java/seedu/todo/guitests/GuiTest.java | 3 ++ .../guitests/guihandles/ConfigItemHandle.java | 39 ++++++++++++++++++ .../guitests/guihandles/ConfigViewHandle.java | 40 +++++++++++++++++++ .../guitests/guihandles/MainGuiHandle.java | 4 ++ 5 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 src/test/java/seedu/todo/guitests/guihandles/ConfigItemHandle.java create mode 100644 src/test/java/seedu/todo/guitests/guihandles/ConfigViewHandle.java diff --git a/src/main/resources/ui/components/ConfigItem.fxml b/src/main/resources/ui/components/ConfigItem.fxml index 3176a172ac16..e044f8c05e41 100644 --- a/src/main/resources/ui/components/ConfigItem.fxml +++ b/src/main/resources/ui/components/ConfigItem.fxml @@ -6,7 +6,7 @@ - diff --git a/src/test/java/seedu/todo/guitests/GuiTest.java b/src/test/java/seedu/todo/guitests/GuiTest.java index 5f48146600e7..3ac8dd62993e 100644 --- a/src/test/java/seedu/todo/guitests/GuiTest.java +++ b/src/test/java/seedu/todo/guitests/GuiTest.java @@ -21,6 +21,7 @@ import seedu.todo.commons.events.BaseEvent; import seedu.todo.commons.util.DateUtil; import seedu.todo.guitests.guihandles.AliasViewHandle; +import seedu.todo.guitests.guihandles.ConfigViewHandle; import seedu.todo.guitests.guihandles.ConsoleHandle; import seedu.todo.guitests.guihandles.HelpViewHandle; import seedu.todo.guitests.guihandles.MainGuiHandle; @@ -48,6 +49,7 @@ public abstract class GuiTest { protected TaskListHandle taskList; protected TagListHandle tagList; protected AliasViewHandle aliasView; + protected ConfigViewHandle configView; protected HelpViewHandle helpView; private Stage stage; @@ -70,6 +72,7 @@ public void setup() throws Exception { taskList = mainGui.getTaskList(); tagList = mainGui.getTagList(); aliasView = mainGui.getAliasView(); + configView = mainGui.getConfigView(); helpView = mainGui.getHelpView(); // TODO: create handles for other components this.stage = stage; diff --git a/src/test/java/seedu/todo/guitests/guihandles/ConfigItemHandle.java b/src/test/java/seedu/todo/guitests/guihandles/ConfigItemHandle.java new file mode 100644 index 000000000000..a62d3aa4baa0 --- /dev/null +++ b/src/test/java/seedu/todo/guitests/guihandles/ConfigItemHandle.java @@ -0,0 +1,39 @@ +package seedu.todo.guitests.guihandles; + +import javafx.scene.Node; +import javafx.stage.Stage; +import seedu.todo.commons.core.ConfigDefinition; +import seedu.todo.guitests.GuiRobot; + +// @@author A0139812A +public class ConfigItemHandle extends GuiHandle { + + private static final String CONFIG_NAME_TEXT_ID = "#configName"; + private static final String CONFIG_DESC_TEXT_ID = "#configDescription"; + private static final String CONFIG_VALUE_TEXT_ID = "#configValue"; + private Node node; + + public ConfigItemHandle(GuiRobot guiRobot, Stage primaryStage, Node node){ + super(guiRobot, primaryStage, null); + this.node = node; + } + + public String getConfigName() { + return getStringFromText(CONFIG_NAME_TEXT_ID, node); + } + + public String getConfigDescription() { + return getStringFromText(CONFIG_DESC_TEXT_ID, node); + } + + public String getConfigValue() { + return getStringFromText(CONFIG_VALUE_TEXT_ID, node); + } + + public boolean isEqualsTo(ConfigDefinition configDefinition) { + return getConfigName().equals(configDefinition.getConfigName()) + && getConfigDescription().equals(configDefinition.getConfigDescription()) + && getConfigValue().equals(configDefinition.getConfigValue()); + } + +} diff --git a/src/test/java/seedu/todo/guitests/guihandles/ConfigViewHandle.java b/src/test/java/seedu/todo/guitests/guihandles/ConfigViewHandle.java new file mode 100644 index 000000000000..79324af0dec8 --- /dev/null +++ b/src/test/java/seedu/todo/guitests/guihandles/ConfigViewHandle.java @@ -0,0 +1,40 @@ + +package seedu.todo.guitests.guihandles; + +import java.util.Optional; + +import javafx.scene.Node; +import javafx.stage.Stage; +import seedu.todo.commons.core.ConfigDefinition; +import seedu.todo.guitests.GuiRobot; + +// @@author A0139812A +public class ConfigViewHandle extends GuiHandle { + + private static final String CONFIGVIEW_TEXT_ID = "#configInstructionsText"; + private static final String CONFIG_ITEM_ID = "#configItem"; + + public ConfigViewHandle(GuiRobot guiRobot, Stage primaryStage, String stageTitle) { + super(guiRobot, primaryStage, stageTitle); + } + + /** + * Checks for the existence of a child element to determine if the view has loaded correctly. + */ + public boolean hasLoaded() { + return guiRobot.lookup(CONFIGVIEW_TEXT_ID).queryAll().size() > 0; + } + + public ConfigItemHandle getConfigItem(ConfigDefinition configDefinition) { + Optional itemNode = guiRobot.lookup(CONFIG_ITEM_ID).queryAll().stream() + .filter(node -> new ConfigItemHandle(guiRobot, primaryStage, node).isEqualsTo(configDefinition)) + .findFirst(); + + if (itemNode.isPresent()) { + return new ConfigItemHandle(guiRobot, primaryStage, itemNode.get()); + } else { + return null; + } + } + +} diff --git a/src/test/java/seedu/todo/guitests/guihandles/MainGuiHandle.java b/src/test/java/seedu/todo/guitests/guihandles/MainGuiHandle.java index deffa7bc6c9c..9ab7f68340b3 100644 --- a/src/test/java/seedu/todo/guitests/guihandles/MainGuiHandle.java +++ b/src/test/java/seedu/todo/guitests/guihandles/MainGuiHandle.java @@ -19,6 +19,10 @@ public AliasViewHandle getAliasView() { return new AliasViewHandle(guiRobot, primaryStage, TestApp.APP_TITLE); } + public ConfigViewHandle getConfigView() { + return new ConfigViewHandle(guiRobot, primaryStage, TestApp.APP_TITLE); + } + public HelpViewHandle getHelpView() { return new HelpViewHandle(guiRobot, primaryStage, TestApp.APP_TITLE); } From 14f8304f955d86c24d3f45da8dd551ba148824ae Mon Sep 17 00:00:00 2001 From: Irvin Lim Date: Mon, 7 Nov 2016 05:09:02 +0800 Subject: [PATCH 6/8] Add basic test cases --- .../todo/controllers/ConfigController.java | 2 +- .../todo/guitests/ConfigCommandTest.java | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/test/java/seedu/todo/guitests/ConfigCommandTest.java diff --git a/src/main/java/seedu/todo/controllers/ConfigController.java b/src/main/java/seedu/todo/controllers/ConfigController.java index 505c47208b82..0c314847731a 100644 --- a/src/main/java/seedu/todo/controllers/ConfigController.java +++ b/src/main/java/seedu/todo/controllers/ConfigController.java @@ -27,7 +27,7 @@ public class ConfigController extends Controller { private static final String MESSAGE_FAILURE = "Could not update settings: %s"; private static final String MESSAGE_INVALID_INPUT = "Invalid config setting provided!"; private static final String MESSAGE_WRONG_EXTENSION = "Could not change storage path: File must end with %s"; - private static final String TEMPLATE_SET_CONFIG = "config "; + public static final String TEMPLATE_SET_CONFIG = "config "; private static final String STRING_SPACE = " "; private static final int ARGS_LENGTH = 2; diff --git a/src/test/java/seedu/todo/guitests/ConfigCommandTest.java b/src/test/java/seedu/todo/guitests/ConfigCommandTest.java new file mode 100644 index 000000000000..ba6b683145af --- /dev/null +++ b/src/test/java/seedu/todo/guitests/ConfigCommandTest.java @@ -0,0 +1,27 @@ +package seedu.todo.guitests; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import seedu.todo.commons.core.ConfigCenter; +import seedu.todo.commons.core.ConfigDefinition; +import seedu.todo.controllers.ConfigController; + +public class ConfigCommandTest extends GuiTest { + + @Test + public void config_showAll_success() { + console.runCommand("config"); + for (ConfigDefinition configDefinition : ConfigCenter.getInstance().getConfig().getDefinitions()) { + assertNotNull(configView.getConfigItem(configDefinition)); + } + } + + @Test + public void config_wrongNumArgs_disambig() { + console.runCommand("config 1 2 3 4"); + assertEquals(ConfigController.TEMPLATE_SET_CONFIG, console.getConsoleInputText()); + } + +} From 3671bdbde816ef4223fdbdbfb910167144b78787 Mon Sep 17 00:00:00 2001 From: Irvin Lim Date: Mon, 7 Nov 2016 05:29:36 +0800 Subject: [PATCH 7/8] Add HeaderHandle --- src/test/java/seedu/todo/guitests/GuiTest.java | 3 +++ .../todo/guitests/guihandles/HeaderHandle.java | 18 ++++++++++++++++++ .../guitests/guihandles/MainGuiHandle.java | 4 ++++ 3 files changed, 25 insertions(+) create mode 100644 src/test/java/seedu/todo/guitests/guihandles/HeaderHandle.java diff --git a/src/test/java/seedu/todo/guitests/GuiTest.java b/src/test/java/seedu/todo/guitests/GuiTest.java index 3ac8dd62993e..227cb7983d4e 100644 --- a/src/test/java/seedu/todo/guitests/GuiTest.java +++ b/src/test/java/seedu/todo/guitests/GuiTest.java @@ -23,6 +23,7 @@ import seedu.todo.guitests.guihandles.AliasViewHandle; import seedu.todo.guitests.guihandles.ConfigViewHandle; import seedu.todo.guitests.guihandles.ConsoleHandle; +import seedu.todo.guitests.guihandles.HeaderHandle; import seedu.todo.guitests.guihandles.HelpViewHandle; import seedu.todo.guitests.guihandles.MainGuiHandle; import seedu.todo.guitests.guihandles.TagListHandle; @@ -46,6 +47,7 @@ public abstract class GuiTest { // Handles to GUI elements present at the start up are created in advance for easy access from child classes. protected MainGuiHandle mainGui; protected ConsoleHandle console; + protected HeaderHandle header; protected TaskListHandle taskList; protected TagListHandle tagList; protected AliasViewHandle aliasView; @@ -69,6 +71,7 @@ public void setup() throws Exception { FxToolkit.setupStage((stage) -> { mainGui = new MainGuiHandle(new GuiRobot(), stage); console = mainGui.getConsole(); + header = mainGui.getHeader(); taskList = mainGui.getTaskList(); tagList = mainGui.getTagList(); aliasView = mainGui.getAliasView(); diff --git a/src/test/java/seedu/todo/guitests/guihandles/HeaderHandle.java b/src/test/java/seedu/todo/guitests/guihandles/HeaderHandle.java new file mode 100644 index 000000000000..f44e14629cbd --- /dev/null +++ b/src/test/java/seedu/todo/guitests/guihandles/HeaderHandle.java @@ -0,0 +1,18 @@ +package seedu.todo.guitests.guihandles; + +import javafx.stage.Stage; +import seedu.todo.guitests.GuiRobot; + +public class HeaderHandle extends GuiHandle { + + private static final String HEADER_APPTITLE_TEXT_ID = "#headerAppTitle"; + + public HeaderHandle(GuiRobot guiRobot, Stage primaryStage, String stageTitle) { + super(guiRobot, primaryStage, stageTitle); + } + + public String getAppTitle() { + return getStringFromText(HEADER_APPTITLE_TEXT_ID); + } + +} diff --git a/src/test/java/seedu/todo/guitests/guihandles/MainGuiHandle.java b/src/test/java/seedu/todo/guitests/guihandles/MainGuiHandle.java index 9ab7f68340b3..17c66e46dc0d 100644 --- a/src/test/java/seedu/todo/guitests/guihandles/MainGuiHandle.java +++ b/src/test/java/seedu/todo/guitests/guihandles/MainGuiHandle.java @@ -11,6 +11,10 @@ public MainGuiHandle(GuiRobot guiRobot, Stage primaryStage) { super(guiRobot, primaryStage, TestApp.APP_TITLE); } + public HeaderHandle getHeader() { + return new HeaderHandle(guiRobot, primaryStage, TestApp.APP_TITLE); + } + public ConsoleHandle getConsole() { return new ConsoleHandle(guiRobot, primaryStage, TestApp.APP_TITLE); } From 99f3ce9d66b8dd38e6bedbcc82e512cecf77e33f Mon Sep 17 00:00:00 2001 From: Irvin Lim Date: Mon, 7 Nov 2016 06:01:10 +0800 Subject: [PATCH 8/8] Complete test cases --- .../todo/controllers/ConfigController.java | 6 +-- .../todo/guitests/ConfigCommandTest.java | 43 +++++++++++++++++-- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/main/java/seedu/todo/controllers/ConfigController.java b/src/main/java/seedu/todo/controllers/ConfigController.java index 0c314847731a..adcc5f19c377 100644 --- a/src/main/java/seedu/todo/controllers/ConfigController.java +++ b/src/main/java/seedu/todo/controllers/ConfigController.java @@ -24,14 +24,14 @@ public class ConfigController extends Controller { private static final String MESSAGE_SHOWING = "Showing all settings."; private static final String MESSAGE_SUCCESS = "Successfully updated %s."; - private static final String MESSAGE_FAILURE = "Could not update settings: %s"; + public static final String MESSAGE_FAILURE = "Could not update settings: %s"; private static final String MESSAGE_INVALID_INPUT = "Invalid config setting provided!"; - private static final String MESSAGE_WRONG_EXTENSION = "Could not change storage path: File must end with %s"; + public static final String MESSAGE_WRONG_EXTENSION = "Could not change storage path: File must end with %s"; public static final String TEMPLATE_SET_CONFIG = "config "; private static final String STRING_SPACE = " "; private static final int ARGS_LENGTH = 2; - private static final String DB_FILE_EXTENSION = ".json"; + public static final String DB_FILE_EXTENSION = ".json"; private static CommandDefinition commandDefinition = new CommandDefinition(NAME, DESCRIPTION, COMMAND_SYNTAX, COMMAND_KEYWORD); diff --git a/src/test/java/seedu/todo/guitests/ConfigCommandTest.java b/src/test/java/seedu/todo/guitests/ConfigCommandTest.java index ba6b683145af..94247c09b2d0 100644 --- a/src/test/java/seedu/todo/guitests/ConfigCommandTest.java +++ b/src/test/java/seedu/todo/guitests/ConfigCommandTest.java @@ -2,8 +2,11 @@ import static org.junit.Assert.*; +import java.io.File; + import org.junit.Test; +import seedu.todo.TestApp; import seedu.todo.commons.core.ConfigCenter; import seedu.todo.commons.core.ConfigDefinition; import seedu.todo.controllers.ConfigController; @@ -17,11 +20,45 @@ public void config_showAll_success() { assertNotNull(configView.getConfigItem(configDefinition)); } } - + @Test - public void config_wrongNumArgs_disambig() { - console.runCommand("config 1 2 3 4"); + public void config_invalidConfigName_disambig() { + console.runCommand("config invalidConfigName someValue"); assertEquals(ConfigController.TEMPLATE_SET_CONFIG, console.getConsoleInputText()); } + @Test + public void config_tooLittleArgs_disambig() { + console.runCommand("config appTitle"); + assertEquals(ConfigController.TEMPLATE_SET_CONFIG, console.getConsoleInputText()); + } + + @Test + public void config_setAppTitle_success() { + console.runCommand("config appTitle Pokemon Center"); + assertEquals("Pokemon Center", header.getAppTitle()); + assertEquals("Pokemon Center", ConfigCenter.getInstance().getConfig().getAppTitle()); + } + + @Test + public void config_setDatabaseFilePath_success() { + console.runCommand("config databaseFilePath databaseMoved.json"); + assertEquals("databaseMoved.json", ConfigCenter.getInstance().getConfig().getDatabaseFilePath()); + + boolean isFileExists = new File("databaseMoved.json").exists(); + if (isFileExists) { + new File("databaseMoved.json").delete(); + } + + assertTrue(isFileExists); + } + + @Test + public void configDatabaseFilePath_noJsonExtension_error() { + console.runCommand("config databaseFilePath databaseMoved.txt"); + assertEquals(TestApp.SAVE_LOCATION_FOR_TESTING, ConfigCenter.getInstance().getConfig().getDatabaseFilePath()); + assertEquals(String.format(ConfigController.MESSAGE_FAILURE, String.format(ConfigController.MESSAGE_WRONG_EXTENSION, ".json")), + console.getConsoleTextArea()); + } + }