Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change config filepath for tests #195

Merged
merged 6 commits into from
Nov 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/seedu/agendum/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ protected Config initConfig(String configFilePath) {

//Update config file in case it was missing to begin with or there are new/unused fields
try {
initializedConfig.setConfigFilePath(configFilePathUsed);
ConfigUtil.saveConfig(initializedConfig, configFilePathUsed);
} catch (IOException e) {
logger.warning("Failed to save config file : " + StringUtil.getDetails(e));
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/seedu/agendum/commons/core/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class Config {
private String aliasTableFilePath = DEFAULT_ALIAS_TABLE_FILE;
private String userPrefsFilePath = DEFAULT_USER_PREFS_FILE;
private String toDoListFilePath = DEFAULT_SAVE_LOCATION;
private String configFilePath = DEFAULT_CONFIG_FILE;
private String toDoListName = "MyToDoList";

public String getAppTitle() {
Expand Down Expand Up @@ -70,6 +71,14 @@ public String getToDoListName() {
public void setToDoListName(String toDoListName) {
this.toDoListName = toDoListName;
}

public String getConfigFilePath() {
return configFilePath;
}

public void setConfigFilePath(String configFilePath) {
this.configFilePath = configFilePath;
}


@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/agendum/storage/StorageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void setToDoListFilePath(String filePath){

private void saveConfigFile() {
try {
ConfigUtil.saveConfig(config, Config.DEFAULT_CONFIG_FILE);
ConfigUtil.saveConfig(config, config.getConfigFilePath());
} catch (IOException e) {
logger.warning("Failed to save config file : " + StringUtil.getDetails(e));
}
Expand Down
4 changes: 1 addition & 3 deletions src/test/java/seedu/agendum/TestApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
public class TestApp extends MainApp {

public static final String SAVE_LOCATION_FOR_TESTING = TestUtil.getFilePathInSandboxFolder("sampleData.xml");
protected static final String DEFAULT_PREF_FILE_LOCATION_FOR_TESTING = TestUtil.getFilePathInSandboxFolder("pref_testing.json");
public static final String APP_TITLE = "Test App";
protected static final String TO_DO_LIST_NAME = "Test";
protected Supplier<ReadOnlyToDoList> initialDataSupplier = () -> null;
Expand All @@ -42,10 +41,9 @@ public TestApp(Supplier<ReadOnlyToDoList> initialDataSupplier, String saveFileLo

@Override
protected Config initConfig(String configFilePath) {
Config config = super.initConfig(configFilePath);
Config config = TestUtil.createTempConfig();
config.setAppTitle(APP_TITLE);
config.setToDoListFilePath(saveFileLocation);
config.setUserPrefsFilePath(DEFAULT_PREF_FILE_LOCATION_FOR_TESTING);
config.setToDoListName(TO_DO_LIST_NAME);
return config;
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/seedu/agendum/storage/StorageManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import seedu.agendum.commons.core.Config;
import seedu.agendum.commons.events.model.ChangeSaveLocationEvent;
import seedu.agendum.commons.events.model.LoadDataRequestEvent;
import seedu.agendum.commons.events.model.ToDoListChangedEvent;
Expand All @@ -28,6 +27,7 @@
import seedu.agendum.model.ToDoList;
import seedu.agendum.model.UserPrefs;
import seedu.agendum.testutil.EventsCollector;
import seedu.agendum.testutil.TestUtil;
import seedu.agendum.testutil.TypicalTestTasks;

public class StorageManagerTest {
Expand All @@ -40,7 +40,7 @@ public class StorageManagerTest {
@Before
public void setup() {
storageManager = new StorageManager(getTempFilePath("ab"), getTempFilePath("command"),
getTempFilePath("prefs"), new Config());
getTempFilePath("prefs"), TestUtil.createTempConfig());
}


Expand Down Expand Up @@ -95,7 +95,7 @@ public void getToDoListFilePath(){
public void handleToDoListChangedEventExceptionThrownEventRaised() throws IOException {
//Create a StorageManager while injecting a stub that throws an exception when the save method is called
Storage storage = new StorageManager(new XmlToDoListStorageExceptionThrowingStub("dummy"),
new JsonAliasTableStorage("dummy"), new JsonUserPrefsStorage("dummy"), new Config());
new JsonAliasTableStorage("dummy"), new JsonUserPrefsStorage("dummy"), TestUtil.createTempConfig());
EventsCollector eventCollector = new EventsCollector();
storage.handleToDoListChangedEvent(new ToDoListChangedEvent(new ToDoList()));
assertTrue(eventCollector.get(0) instanceof DataSavingExceptionEvent);
Expand Down
59 changes: 44 additions & 15 deletions src/test/java/seedu/agendum/testutil/TestUtil.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
package seedu.agendum.testutil;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors;

import org.loadui.testfx.GuiTest;
import org.testfx.api.FxToolkit;

import com.google.common.io.Files;

import guitests.guihandles.TaskCardHandle;
import javafx.geometry.Bounds;
import javafx.geometry.Point2D;
Expand All @@ -10,28 +26,20 @@
import javafx.scene.input.KeyCodeCombination;
import javafx.scene.input.KeyCombination;
import junit.framework.AssertionFailedError;
import org.loadui.testfx.GuiTest;
import org.testfx.api.FxToolkit;
import seedu.agendum.TestApp;
import seedu.agendum.commons.core.Config;
import seedu.agendum.commons.exceptions.IllegalValueException;
import seedu.agendum.commons.util.ConfigUtil;
import seedu.agendum.commons.util.FileUtil;
import seedu.agendum.commons.util.StringUtil;
import seedu.agendum.commons.util.XmlUtil;
import seedu.agendum.model.ToDoList;
import seedu.agendum.model.task.*;
import seedu.agendum.model.task.Name;
import seedu.agendum.model.task.ReadOnlyTask;
import seedu.agendum.model.task.Task;
import seedu.agendum.model.task.UniqueTaskList;
import seedu.agendum.storage.XmlSerializableToDoList;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors;

/**
* A utility class for test cases.
*/
Expand Down Expand Up @@ -348,5 +356,26 @@ public static TestTask[] getDoneTasks(TestTask[] tasks) {
public static boolean compareCardAndTask(TaskCardHandle card, ReadOnlyTask task) {
return card.isSameTask(task);
}

public static Config createTempConfig() {
Config config = new Config();
final String DEFAULT_CONFIG_FILE_LOCATION_FOR_TESTING = getFilePathInSandboxFolder("config_testing.json");
final String DEFAULT_PREF_FILE_LOCATION_FOR_TESTING = TestUtil.getFilePathInSandboxFolder("pref_testing.json");
final String DEFAULT_TODOLIST_FILE_LOCATION_FOR_TESTING = TestUtil.getFilePathInSandboxFolder("todolist_testing.xml");
final String DEFAULT_ALIAS_TABLE_FILE_LOCATION_FOR_TESTING = TestUtil.getFilePathInSandboxFolder("todolist_testing.xml");

config.setAppTitle(TestApp.APP_TITLE);
config.setUserPrefsFilePath(DEFAULT_PREF_FILE_LOCATION_FOR_TESTING);
config.setToDoListFilePath(DEFAULT_TODOLIST_FILE_LOCATION_FOR_TESTING);
config.setAliasTableFilePath(DEFAULT_ALIAS_TABLE_FILE_LOCATION_FOR_TESTING);
config.setConfigFilePath(DEFAULT_CONFIG_FILE_LOCATION_FOR_TESTING);

try {
ConfigUtil.saveConfig(config, DEFAULT_CONFIG_FILE_LOCATION_FOR_TESTING);
} catch (IOException e) {
System.out.println("Failed to save config file : " + StringUtil.getDetails(e));
}
return config;
}

}