Skip to content

Commit

Permalink
Complete test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
irvinlim authored and louietyj committed Nov 7, 2016
1 parent 94c2cf6 commit a9c2da4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/main/java/seedu/todo/controllers/ConfigController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <setting> <value>";

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);
Expand Down
43 changes: 40 additions & 3 deletions src/test/java/seedu/todo/guitests/ConfigCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}

}

0 comments on commit a9c2da4

Please sign in to comment.