Skip to content

Commit

Permalink
add tests for save command (#186)
Browse files Browse the repository at this point in the history
* add tests for save command

* update save test
  • Loading branch information
LiuYulin0629 authored and LiHaoTan committed Apr 10, 2017
1 parent 8cb390f commit ab30344
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/test/java/guitests/SaveCommandTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//@@author A0148052L
package guitests;

import org.junit.Test;

import onlythree.imanager.logic.commands.SaveCommand;

public class SaveCommandTest extends TaskListGuiTest {

@Test
public void saveFile_relativeFilePath_successful() {
String filePath = "data" + "\\" + "taskList.xml";
assertSaveSuccess(filePath);
}

@Test
public void saveFile_relativeFileName_fileNameError() {
commandBox.runCommand("save " + "data" + "\\" + ".xml");
assertResultMessage(SaveCommand.MESSAGE_INVALID_FILE_NAME);
}

private void assertSaveSuccess(String filePath) {
commandBox.runCommand("save " + filePath);
assertResultMessage(String.format(SaveCommand.MESSAGE_SUCCESS, filePath));
}
}
15 changes: 15 additions & 0 deletions src/test/java/onlythree/imanager/logic/LogicManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
Expand Down Expand Up @@ -36,6 +37,7 @@
import onlythree.imanager.logic.commands.ExitCommand;
import onlythree.imanager.logic.commands.FindCommand;
import onlythree.imanager.logic.commands.HelpCommand;
import onlythree.imanager.logic.commands.SaveCommand;
import onlythree.imanager.logic.commands.SelectCommand;
import onlythree.imanager.logic.commands.ViewCommand;
import onlythree.imanager.logic.commands.exceptions.CommandException;
Expand Down Expand Up @@ -185,6 +187,19 @@ public void execute_clear() throws Exception {

assertCommandSuccess("clear", ClearCommand.MESSAGE_SUCCESS, new TaskList(), Collections.emptyList());
}
//@@author A0148052L
public void execute_save_successful() throws Exception {
assertCommandSuccess("save " + saveFolder.getRoot().getPath() + File.separator + "taskList.xml",
SaveCommand.MESSAGE_SUCCESS, new TaskList(), Collections.emptyList());
}

@Test
public void execute_save_invalidFileName() throws Exception {
List<ReadOnlyTask> expectedShownList = new ArrayList<>(model.getFilteredTaskList());
assertCommandBehavior(false, "save " + "data" + "\\" + ".xml",
SaveCommand.MESSAGE_INVALID_FILE_NAME, new TaskList(), expectedShownList);
}
//@@author

//@@author A0140023E
@Test
Expand Down

0 comments on commit ab30344

Please sign in to comment.