From a9c2da438fd4da2c32cdaae2c4efd85e4484352b Mon Sep 17 00:00:00 2001 From: Irvin Lim Date: Mon, 7 Nov 2016 06:01:10 +0800 Subject: [PATCH] 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()); + } + }