Skip to content

Commit

Permalink
More coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ychoi1997 committed Nov 4, 2016
1 parent 4472c6a commit d36b1e8
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/main/java/seedu/task/logic/parser/Parser.java
Expand Up @@ -313,8 +313,7 @@ private Command prepareEdit(String args) {
} else if (matcher.group("newTitle") == null && matcher.group("description") == null
&& matcher.group("startDate") == null && matcher.group("dueDate") == null
&& matcher.group("interval") == null && matcher.group("timeInterval") == null
&& matcher.group("tagArguments") == null && matcher.group("taskColor") == null
&& matcher.group("taskColor").equalsIgnoreCase("cyan")) {
&& matcher.group("tagArguments") == null && matcher.group("taskColor") == null) {
return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE));
}
try {
Expand Down
45 changes: 43 additions & 2 deletions src/test/java/guitests/EditCommandTest.java
Expand Up @@ -8,6 +8,7 @@

import seedu.address.testutil.TestTask;
import seedu.task.commons.exceptions.IllegalValueException;
import seedu.task.logic.commands.EditCommand;
import seedu.task.model.task.Description;
import seedu.task.model.task.DueDate;
import seedu.task.model.task.StartDate;
Expand All @@ -16,6 +17,7 @@
//@@author A0153751H

public class EditCommandTest extends TaskManagerGuiTest {
private static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n";
private TestTask[] backup;

@Test
Expand All @@ -26,11 +28,50 @@ public void edit() {
assertMultipleParametersSuccess(7, currentList, "NEWNAME", "NEWDESC",
"11-11-2011", "12-12-2012", "none");
assertEditColorSuccess(1, currentList, "red");
assertEditColorSuccess(1, currentList, "green");
assertEditColorSuccess(1, currentList, "blue");
assertEditColorSuccess(7, currentList, "green");
assertEditColorSuccess(7, currentList, "blue");
assertIncorrectParameters(7, currentList, "edit");
assertIncorrectParameters(1, currentList, "edit bleh");
assertEditTagsSuccess(1, currentList, "tag1", "tag2");

}

private void assertEditTagsSuccess(int targetIndexOneIndexed, TestTask[] currentList, String string, String string2) {
TestTask taskToEdit = currentList[targetIndexOneIndexed-1]; //-1 because array uses zero indexing
TestTask expectedEditedTask = new TestTask();
try {
expectedEditedTask.setTags(string, string2);
} catch (IllegalValueException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
expectedEditedTask.setTitle(taskToEdit.getTitle());
expectedEditedTask.setDescription(taskToEdit.getDescription());
expectedEditedTask.setDueDate(taskToEdit.getDueDate());
expectedEditedTask.setInterval(taskToEdit.getInterval());
expectedEditedTask.setStartDate(taskToEdit.getStartDate());
expectedEditedTask.setStatus(taskToEdit.getStatus());
expectedEditedTask.setTimeInterval(taskToEdit.getTimeInterval());
backup = currentList;
backup[targetIndexOneIndexed-1] = expectedEditedTask;
TestTask[] expectedNewList = backup;

commandBox.runCommand("edit " + targetIndexOneIndexed + " ts/" + string
+ " ts/" + string2);

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

//confirm the result message is correct
assertResultMessage(String.format("The data has been successfully edited.", taskToEdit));

}

private void assertIncorrectParameters(int targetIndexOneIndexed, TestTask[] currentList, String string) {
commandBox.runCommand(string);
assertResultMessage(MESSAGE_INVALID_COMMAND_FORMAT + EditCommand.MESSAGE_USAGE);
}

private void assertEditColorSuccess(int targetIndexOneIndexed, TestTask[] currentList, String color) {
TestTask taskToEdit = currentList[targetIndexOneIndexed-1]; //-1 because array uses zero indexing
TestTask expectedEditedTask = new TestTask();
Expand Down
23 changes: 21 additions & 2 deletions src/test/java/seedu/address/testutil/TestTask.java
@@ -1,6 +1,12 @@
package seedu.address.testutil;

import seedu.task.model.task.*;

import java.util.HashSet;
import java.util.Set;

import seedu.task.commons.exceptions.IllegalValueException;
import seedu.task.model.tag.Tag;
import seedu.task.model.tag.UniqueTagList;

/**
Expand Down Expand Up @@ -50,11 +56,24 @@ public void setStatus(Status status) {
this.status = status;
}

//@@author A0153751H
//@@author A0153751H
public void setTaskColor(TaskColor taskColor) {
this.taskColor = taskColor;
}
//@@author

public void setTags(UniqueTagList tags) {
this.tags = tags;
}

public void setTags(String...strings) throws IllegalValueException {
Set<Tag> temp = new HashSet<Tag>();
for(String a: strings) {
Tag newTag = new Tag(a);
temp.add(newTag);
}
this.tags = new UniqueTagList(temp);
}
//@@author

@Override
public String toString() {
Expand Down

0 comments on commit d36b1e8

Please sign in to comment.