Skip to content

Commit

Permalink
Merge master into ui-enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
Fan Weiguang committed Nov 4, 2016
2 parents 5450f2c + 31cc8a9 commit e7ac72a
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 29 deletions.
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
5 changes: 3 additions & 2 deletions src/main/java/seedu/agendum/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,14 @@ public AddCommand(String name, Optional<LocalDateTime> deadlineDate)
*/
public AddCommand(String name, Optional<LocalDateTime> startDateTime, Optional<LocalDateTime> endDateTime)
throws IllegalValueException {
Optional<LocalDateTime> balancedEndDateTime = endDateTime;
if (startDateTime.isPresent() && endDateTime.isPresent()) {
endDateTime = Optional.of(DateTimeUtils.balanceStartAndEndDateTime(startDateTime.get(), endDateTime.get()));
balancedEndDateTime = Optional.of(DateTimeUtils.balanceStartAndEndDateTime(startDateTime.get(), endDateTime.get()));
}
this.toAdd = new Task(
new Name(name),
startDateTime,
endDateTime
balancedEndDateTime
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ public class ScheduleCommand extends Command {
//@@author A0133367E
public ScheduleCommand(int targetIndex, Optional<LocalDateTime> startTime,
Optional<LocalDateTime> endTime) {
Optional<LocalDateTime> balancedEndTime = endTime;
if (startTime.isPresent() && endTime.isPresent()) {
endTime = Optional.of(DateTimeUtils.balanceStartAndEndDateTime(startTime.get(), endTime.get()));
balancedEndTime = Optional.of(DateTimeUtils.balanceStartAndEndDateTime(startTime.get(), endTime.get()));
}
this.targetIndex = targetIndex;
this.newStartDateTime = startTime;
this.newEndDateTime = endTime;
this.newEndDateTime = balancedEndTime;
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/agendum/logic/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,9 @@ private Set<Integer> parseIndexes(String args) {
return taskIds;
}

args = args.replaceAll("[ ]+", ",").replaceAll(",+", ",");
String replacedArgs = args.replaceAll("[ ]+", ",").replaceAll(",+", ",");

String[] taskIdStrings = args.split(",");
String[] taskIdStrings = replacedArgs.split(",");
for (String taskIdString : taskIdStrings) {
if (taskIdString.matches("\\d+")) {
taskIds.add(Integer.parseInt(taskIdString));
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
2 changes: 1 addition & 1 deletion src/main/java/seedu/agendum/ui/UiManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private Image getImage(String imagePath) {
return new Image(MainApp.class.getResourceAsStream(imagePath));
}

void showAlertDialogAndWait(Alert.AlertType type, String title, String headerText, String contentText) {
private void showAlertDialogAndWait(Alert.AlertType type, String title, String headerText, String contentText) {
showAlertDialogAndWait(mainWindow.getPrimaryStage(), type, title, headerText, contentText);
}

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[] getCompletedTasks(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;
}

}

0 comments on commit e7ac72a

Please sign in to comment.