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

Refactor test cases #78

Merged
merged 2 commits into from
Nov 2, 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
6 changes: 5 additions & 1 deletion src/main/java/seedu/malitio/commons/util/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,13 @@ public static void deleteFile(String filePath) throws IOException {
Files.deleteIfExists(path);
}

/**
*
* Converts two strings of file path to their canonical values and then compares them.
*/
public static boolean twoFilePathsAreEqual(String filePath1, String filePath2) throws IOException {
try {
if(new File(filePath1).getCanonicalPath().compareTo(new File(filePath2).getCanonicalPath()) == 0) {
if (new File(filePath1).getCanonicalPath().compareTo(new File(filePath2).getCanonicalPath()) == 0) {
return true;
}
} catch (IOException e1) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/malitio/commons/util/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static String removeTagsFromString(String arg) {

//@@author a0126633j
public static String removeSlashesAtBeginningOfString(String arg) {
while(arg.charAt(0) == '/') {
while (arg.charAt(0) == '/') {
arg = arg.substring(1);
}
return arg;
Expand Down
11 changes: 4 additions & 7 deletions src/test/java/guitests/DeleteCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ public void delete() {

/**
* Runs the delete command to delete the task at specified index and confirms the result is correct.
* (overloading functions for different tasks)
* @param targetIndexOneIndexed e.g. to delete the first task in the list, 1 should be given as the target index.
* @param floatingTaskList A copy of the current list of tasks (before deletion).
* @param task list: A copy of the current list of tasks (before deletion).
*/
private void assertDeleteSuccess(int targetIndexOneIndexed, final TestFloatingTask[] floatingTaskList) {
TestFloatingTask taskToDelete = floatingTaskList[targetIndexOneIndexed-1]; //-1 because array uses zero indexing
Expand All @@ -67,7 +68,7 @@ private void assertDeleteSuccess(int targetIndexOneIndexed, final TestFloatingTa
assertTrue(floatingTaskListPanel.isListMatching(expectedRemainder));

//confirm the result message is correct
// assertResultMessage(String.format(MESSAGE_DELETE_TASK_SUCCESS, taskToDelete));
assertResultMessage(String.format(MESSAGE_DELETE_TASK_SUCCESS, taskToDelete));
}

private void assertDeleteSuccess(int targetIndexOneIndexed, final TestDeadline[] deadlineList) {
Expand All @@ -76,10 +77,8 @@ private void assertDeleteSuccess(int targetIndexOneIndexed, final TestDeadline[]

commandBox.runCommand("delete " + DEADLINE_KEYWORD + targetIndexOneIndexed);

//confirm the list now contains all previous tasks except the deleted task
assertTrue(deadlineListPanel.isListMatching(expectedRemainder));

//confirm the result message is correct
assertResultMessage(String.format(MESSAGE_DELETE_TASK_SUCCESS, taskToDelete));
}

Expand All @@ -89,16 +88,14 @@ private void assertDeleteSuccess(int targetIndexOneIndexed, final TestEvent[] ev

commandBox.runCommand("delete " + EVENT_KEYWORD + targetIndexOneIndexed);

//confirm the list now contains all previous tasks except the deleted task
try {
assertTrue(eventListPanel.isListMatching(expectedRemainder));
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalValueException e) {
e.printStackTrace();
}

//confirm the result message is correct

assertResultMessage(String.format(MESSAGE_DELETE_TASK_SUCCESS, taskToDelete));
}

Expand Down
59 changes: 31 additions & 28 deletions src/test/java/guitests/FindCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,32 @@
public class FindCommandTest extends MalitioGuiTest {

//In the tests below, we assume event,floating task and deadline lists are identical, hence to save resources only work on them equally
@Test
@Test
public void find_nonEmptyList() throws IllegalArgumentException, IllegalValueException {

assertFindEventResult("find e with", td.event1, td.event2); //multiple results
assertFindResult("find with", td.event1, td.event2); //multiple results
assertResultMessage("2 tasks found!");

assertFindFloatingTaskResult("find peN HOMEWORK", td.floatingTask2);
assertFindDeadlineResult("find peN HOMEWORK", td.deadline3, td.deadline5);
assertFindResult("find peN HOMEWORK", td.floatingTask2, td.deadline3, td.deadline5);
// assertFindResult("find peN HOMEWORK");
assertResultMessage("3 tasks found!");

assertFindDeadlineResult("find 12-25", td.deadline4); //find dates
assertFindEventResult("find 12-25", td.event5);
assertFindResult("find 12-25", td.deadline4, td.event5); //find dates
// assertFindResult("find 12-25");
assertResultMessage("2 tasks found!");

assertFindEventResult("find wedding"); //no result
assertFindResult("find wedding"); //no result

//find after deleting one result
commandBox.runCommand("list");
commandBox.runCommand("delete f1");
assertFindFloatingTaskResult("find bring",td.floatingTask2);
assertFindResult("find bring",td.floatingTask2);
}

@Test
public void find_emptyList() throws IllegalArgumentException, IllegalValueException {
commandBox.runCommand("clear");
assertFindEventResult("find eat"); //no result
assertFindResult("find eat"); //no result
}

@Test
Expand All @@ -52,13 +52,13 @@ public void find_invalidCommand_fail() {

@Test
public void find_specificTasks() throws IllegalArgumentException, IllegalValueException {
assertFindEventResult("find e with", td.event1, td.event2); //multiple results
assertFindResult("find e with", td.event1, td.event2); //multiple results
assertResultMessage("2 tasks found!");

assertFindDeadlineResult("find d H", td.deadline1, td.deadline4, td.deadline5);
assertFindResult("find d H", td.deadline1, td.deadline4, td.deadline5);
assertResultMessage("3 tasks found!");

assertFindFloatingTaskResult("find f tell", td.floatingTask3);
assertFindResult("find f tell", td.floatingTask3);
assertResultMessage("1 tasks found!");

commandBox.runCommand("find e");
Expand All @@ -68,23 +68,26 @@ public void find_specificTasks() throws IllegalArgumentException, IllegalValueEx

/**
* Overload functions to assert result in each floating task, deadline and event list is correct
* @throws IllegalValueException
* @throws IllegalArgumentException
*/
private void assertFindFloatingTaskResult(String command, TestFloatingTask... expectedHits ) {
commandBox.runCommand(command);
assertFloatingTaskListSize(expectedHits.length);

assertTrue(floatingTaskListPanel.isListMatching(expectedHits));
}
private void assertFindDeadlineResult(String command, TestDeadline... expectedHits ) {
commandBox.runCommand(command);
assertDeadlineListSize(expectedHits.length);

assertTrue(deadlineListPanel.isListMatching(expectedHits));
}
private void assertFindEventResult(String command, TestEvent... expectedHits ) throws IllegalArgumentException, IllegalValueException {

private void assertFindResult(String command, Object... expectedHits ) throws IllegalArgumentException, IllegalValueException {
commandBox.runCommand(command);
assertEventListSize(expectedHits.length);

assertTrue(eventListPanel.isListMatching(expectedHits));
switch (expectedHits.getClass().getSimpleName()) {
case "TestFloatingTask":
assertFloatingTaskListSize(expectedHits.length);
assertTrue(floatingTaskListPanel.isListMatching((TestFloatingTask[]) expectedHits));
break;
case "TestDeadline":
assertDeadlineListSize(expectedHits.length);
assertTrue(deadlineListPanel.isListMatching((TestDeadline[]) expectedHits));
break;
case "TestEvent":
assertEventListSize(expectedHits.length);
assertTrue(eventListPanel.isListMatching((TestEvent[])expectedHits));
break;
}
}
}
6 changes: 6 additions & 0 deletions src/test/java/guitests/SaveCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import seedu.malitio.commons.exceptions.DataConversionException;
import seedu.malitio.commons.util.ConfigUtil;
import seedu.malitio.logic.commands.SaveCommand;
import seedu.malitio.model.Malitio;
import seedu.malitio.storage.StorageManager;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -52,6 +53,10 @@ public void save() throws DataConversionException, IOException {
assertSaveSuccessful(DEFAULT_FILE_PATH);
assertFileDeletionSuccessful(TEST_FILE_PATH);

//invalid file path
commandBox.runCommand("save abc");
assertResultMessage(SaveCommand.MESSAGE_INVALID_DIRECTORY + SaveCommand.MESSAGE_DIRECTORY_EXAMPLE);

//orginal save file location should be preserved after the tests
ConfigUtil.changeMalitioSaveDirectory(originalFilePath);
}
Expand All @@ -65,6 +70,7 @@ public void assertSaveSuccessful(String newFileLocation) throws DataConversionEx
File f = new File(newFileLocation + DEFAULT_FILE_NAME);
if(f.exists()) {
assertEquals(original, new Malitio(storageManager.readMalitio(newFileLocation + DEFAULT_FILE_NAME).get()));
assertResultMessage(String.format(SaveCommand.MESSAGE_SAVE_SUCCESSFUL, newFileLocation + DEFAULT_FILE_NAME));
} else {
assertTrue(false);
}
Expand Down