A0148145E
\java\guitests\EditCommandTest.java
public class EditCommandTest extends TaskSchedulerGuiTest {
@Test
public void edit() {
int indexToEdit = 1;
edit_name_success(indexToEdit, "change name");
edit_address_success(indexToEdit, "a changed location");
edit_period_success(indexToEdit, "05-Oct-2016", "15-Nov-2016");
edit_noIndex_success(indexToEdit);
}
private void edit_noIndex_success(int prevIndex) {
//edit name without index
String changedName = "new name";
commandBox.runCommand("edit " + changedName);
assertEquals(taskListPanel.navigateToTask(prevIndex - 1).getFullName(), changedName);
//edit end date without index
String deadline = "25-Oct-2016, Tue";
commandBox.runCommand("edit by " + deadline);
assertEquals(taskListPanel.navigateToTask(prevIndex - 1).getEndDate(), deadline);
}
private void edit_period_success(int indexToEdit, String changedStartDate, String changedEndDate) {
//edit the date
commandBox.runCommand("edit " + indexToEdit + " from " + changedStartDate + " to " + changedEndDate);
//confirm the editted card contains the right data
assertTrue(taskListPanel.navigateToTask(indexToEdit - 1).getStartDate().contains(changedStartDate));
assertTrue(taskListPanel.navigateToTask(indexToEdit - 1).getEndDate().contains(changedEndDate));
}
private void edit_address_success(int indexToEdit, String changedAddress) {
//edit the address
commandBox.runCommand("edit " + indexToEdit + " at " + changedAddress);
//confirm the editted card contains the right data
assertEquals(taskListPanel.navigateToTask(indexToEdit - 1).getLocation(), changedAddress);
}
private void edit_name_success(int indexToEdit, String changedName) {
//edit the name
commandBox.runCommand("edit " + indexToEdit + " " + changedName);
//confirm the editted card contains the right data
assertEquals(taskListPanel.navigateToTask(indexToEdit - 1).getFullName(), changedName);
}
}
\java\guitests\guihandles\GuiHandle.java
public void pressUp() {
guiRobot.type(KeyCode.UP).sleep(500);
}
public void pressDown() {
guiRobot.type(KeyCode.DOWN).sleep(500);
}
protected Paint getPaintFromShape(String fieldId, Node parentNode) {
return ((Shape) guiRobot.from(parentNode).lookup(fieldId).tryQuery().get()).getFill();
}
\java\guitests\guihandles\TaskCardHandle.java
protected Paint getPaintFromShape(String fieldId) {
return getPaintFromShape(fieldId, node);
}
\java\guitests\guihandles\TaskCardHandle.java
public Paint getPaintFromShape() {
return getPaintFromShape(CARDPANE_SHAPE_ID);
}
\java\guitests\guihandles\TaskCardHandle.java
public String getStartDate() {
return getTextFromLabel(START_DATE_FIELD_ID).replace("Start Date: ", "");
}
public String getEndDate() {
return getTextFromLabel(END_DATE_FIELD_ID).replace("Due Date: ", "");
}
\java\guitests\guihandles\TaskListPanelHandle.java
/**
* Returns true if the list is showing all the task details correctly and in no order.
* @param tasks A list of task.
*/
public boolean listContainsAll(ReadOnlyTask... tasks) throws IllegalArgumentException {
ArrayList<ReadOnlyTask> list = new ArrayList<ReadOnlyTask>(Arrays.asList(tasks));
for (int i = 0; i < tasks.length; i++) {
final int scrollTo = i;
guiRobot.interact(() -> getListView().scrollTo(scrollTo));
guiRobot.sleep(200);
for (int j = 0; j < list.size(); j++) {
if (TestUtil.compareCardAndTask(getTaskCardHandle(scrollTo), list.get(j))) {
list.remove(j);
break;
}
}
}
return list.size() == 0;
}
\java\guitests\MarkCommandTest.java
/**
* Runs the mark command to mark the task at specified index as completed and confirms the result is correct.
* @param targetIndexOneIndexed e.g. to mark the first task in the list, 1 should be given as the target index.
* @param currentList A copy of the current list of tasks (before deletion).
*/
public void assertMarkSuccess(int targetIndexOneIndexed, final TestTask[] currentList) {
TestTask taskToMark = currentList[targetIndexOneIndexed-1]; //-1 because array uses zero indexing
commandBox.runCommand("mark " + targetIndexOneIndexed);
//confirm the task card is now marked completed.
assertTrue(taskListPanel.navigateToTask(targetIndexOneIndexed - 1).getPaintFromShape()
.equals(TaskCard.COMPLETED_INDICATION));
assertFalse(taskListPanel.navigateToTask(targetIndexOneIndexed - 1).getPaintFromShape()
.equals(TaskCard.OVERDUE_INDICATION));
//confirm the result message is correct
assertResultMessage(String.format(MarkCommand.MESSAGE_MARK_TASK_SUCCESS, taskToMark));
}
}
\java\guitests\RecurCommandTest.java
public class RecurCommandTest extends TaskSchedulerGuiTest {
@Test
public void add() {
//invalid recur task
commandBox.runCommand("recur every 3 days until next week");
assertResultMessage(Messages.MESSAGE_PREV_TASK_NOT_FOUND);
//add one task
TestTask[] currentList = td.getTypicalTasks();
commandBox.runCommand(td.event.getAddCommand());
//recur without index
recur_withoutIndex_success(currentList, "recur every 3 days until next week", td.event);
//assert undo works for recur command
currentList = undo_recurCommand_success();
//recur with index
recur_withIndex_success(currentList);
}
private void recur_withIndex_success(TestTask[] currentList) {
long dateInterval;
long dateLimit;
dateInterval = 3 * 24 * 3600 * 1000; // 3 days
commandBox.runCommand("recur 1 every 3 days until next week");
Date dateNow = new Date();
Date taskDate = td.alice.getEndDate().getDate();
dateLimit = dateNow.getTime() - taskDate.getTime() + 7 * 24 * 3600 * 1000l; // 1 week later
currentList = generateExpectedList(td.alice, currentList, dateInterval, dateLimit);
assertTrue(taskListPanel.listContainsAll(currentList));
}
private TestTask[] undo_recurCommand_success() {
TestTask[] currentList;
commandBox.runCommand("undo");
currentList = td.getTypicalTasks();
currentList = TestUtil.addTasksToList(currentList, td.event);
assertTrue(taskListPanel.listContainsAll(currentList));
return currentList;
}
private void recur_withoutIndex_success(TestTask[] currentList, String string, TestTask task) {
commandBox.runCommand(string);
long dateInterval = 3 * 24 * 3600 * 1000; // 3 days
long dateLimit = 7 * 24 * 3600 * 1000; // 1 week
currentList = TestUtil.addTasksToList(currentList, task);
currentList = generateExpectedList(task, currentList, dateInterval, dateLimit);
assertTrue(taskListPanel.listContainsAll(currentList));
}
private TestTask[] generateExpectedList(TestTask task, TestTask[] currentList, long dateInterval, long dateLimit) {
for (long i = dateInterval; i <= dateLimit; i += dateInterval) {
TestTask taskToAdd = task.copy();
taskToAdd.addDuration(i);
currentList = TestUtil.addTasksToList(currentList, taskToAdd);
}
return currentList;
}
}
\java\guitests\ReplaceCommandTest.java
public class ReplaceCommandTest extends TaskSchedulerGuiTest {
@Test
public void replace() {
TestTask[] currentList = td.getTypicalTasks();
//invalid command
replace_invalidCommand_messageTaskNotFound();
//replace with a deadline task
currentList = replace_deadlineTask_success(currentList, 2, td.deadline);
//replace with a floating task
currentList = replace_floatingTask_success(currentList, currentList.length, td.floating);
//replace with overdue task
currentList = replace_overdueTask_success(currentList, 1, td.overdue);
//replace with an event task
currentList = replace_eventTask_success(currentList, 1, td.event);
//replace with a duplicate task
replace_duplicateTask_messageDuplicateError(currentList, 5, td.event);
//replace in empty list
replace_emptyList_messageInvalidIndex(5, td.event);
}
private void replace_emptyList_messageInvalidIndex(int indexToReplace, TestTask taskToCopy) {
commandBox.runCommand("clear");
commandBox.runCommand("replace " + indexToReplace + " " + taskToCopy.getTaskString());
assertResultMessage(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
}
private void replace_duplicateTask_messageDuplicateError(TestTask[] currentList, int indexToReplace, TestTask taskToCopy) {
commandBox.runCommand("replace " + indexToReplace + " " + taskToCopy.getTaskString());
assertResultMessage(Command.MESSAGE_DUPLICATE_TASK);
assertTrue(taskListPanel.isListMatching(currentList));
}
private TestTask[] replace_eventTask_success(TestTask[] currentList, int indexToReplace, TestTask taskToCopy) {
taskToCopy.setStartDate(currentList[indexToReplace - 1].getStartDate());
currentList = replace_floatingTask_success(currentList, indexToReplace, taskToCopy);
return currentList;
}
private TestTask[] replace_overdueTask_success(TestTask[] currentList, int indexToReplace, TestTask taskToCopy) {
assertReplaceSuccess(indexToReplace, taskToCopy, currentList);
//assert that overdue task is red
assertTrue(taskListPanel.navigateToTask(indexToReplace - 1).getPaintFromShape().equals(TaskCard.OVERDUE_INDICATION));
assertFalse(taskListPanel.navigateToTask(indexToReplace - 1).getPaintFromShape().equals(TaskCard.COMPLETED_INDICATION));
currentList[indexToReplace - 1] = taskToCopy;
currentList = TestUtil.addTasksToList(currentList);
return currentList;
}
private TestTask[] replace_floatingTask_success(TestTask[] currentList, int indexToReplace, TestTask taskToCopy) {
assertReplaceSuccess(indexToReplace, taskToCopy, currentList);
currentList[indexToReplace - 1] = taskToCopy;
currentList = TestUtil.addTasksToList(currentList);
return currentList;
}
private TestTask[] replace_deadlineTask_success(TestTask[] currentList, int indexToReplace, TestTask taskToCopy) {
taskToCopy.setEndDate(currentList[indexToReplace - 1].getEndDate());
currentList = replace_floatingTask_success(currentList, indexToReplace, taskToCopy);
return currentList;
}
private void replace_invalidCommand_messageTaskNotFound() {
commandBox.runCommand("replace eee " + td.ida.getTaskString());
assertResultMessage(Messages.MESSAGE_PREV_TASK_NOT_FOUND);
}
private void assertReplaceSuccess(int indexToReplace, TestTask taskToCopy, TestTask... currentList) {
commandBox.runCommand("replace " + indexToReplace + " " + taskToCopy.getTaskString());
//confirm the replaced card contains the right data
TaskCardHandle replacedCard = taskListPanel.navigateToTask(indexToReplace - 1);
assertMatching(taskToCopy, replacedCard);
//confirm the list now contains all previous tasks with the replaced task
TestTask[] expectedList = TestUtil.addTasksToList(currentList);
expectedList[indexToReplace - 1] = taskToCopy;
assertTrue(taskListPanel.isListMatching(expectedList));
}
}
\java\guitests\TagCommandTest.java
public class TagCommandTest extends TaskSchedulerGuiTest {
@Test
public void tag() {
String singleTagArg = "Priority";
String multiTagsArg = "School Urgent";
TestTask[] currentList = td.getTypicalTasks();
int targetIndex = 1;
//put a single tag
assertTagSuccess(targetIndex, singleTagArg, currentList);
//replace with multiple tags
assertTagSuccess(targetIndex, multiTagsArg, currentList);
//invalid index
tag_indexOutOfBound_messageInvalidIndex(currentList);
undo_tagCommand_success(currentList, targetIndex, singleTagArg);
}
private void tag_indexOutOfBound_messageInvalidIndex(TestTask[] currentList) {
commandBox.runCommand("tag " + currentList.length + 1);
assertResultMessage(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
}
private void undo_tagCommand_success(TestTask[] currentList, int targetIndexOneIndexed, String tagArgs) {
ReadOnlyTask task = taskListPanel.getTask(targetIndexOneIndexed - 1);
commandBox.runCommand("undo");
assertTrue(taskListPanel.navigateToTask(targetIndexOneIndexed - 1).getTags()
.equals(convertArgsToTagString(tagArgs)));
assertResultMessage(String.format(Command.MESSAGE_REVERT_COMMAND, TagCommand.COMMAND_WORD, "\n" + task));
}
/**
* Runs the tag command to rag the task at specified index and confirms the result is correct.
* @param targetIndexOneIndexed e.g. to tag the first task in the list, 1 should be given as the target index.
* @param currentList A copy of the current list of tasks.
*/
private void assertTagSuccess(int targetIndexOneIndexed, String tagArgs, final TestTask[] currentList) {
TestTask taskToTag = currentList[targetIndexOneIndexed-1]; //-1 because array uses zero indexing
commandBox.runCommand("tag " + targetIndexOneIndexed + " " + tagArgs);
assertTrue(taskListPanel.navigateToTask(targetIndexOneIndexed - 1).getTags()
.equals(convertArgsToTagString(tagArgs)));
//confirm the result message is correct
assertResultMessage(String.format(MESSAGE_SUCCESS, taskToTag));
}
/**
* Convert tags param string to task card display string
* @param tagArgs tags string that use in tag command
* @return tags string in task card display
*/
private String convertArgsToTagString(String tagArgs) {
final StringBuffer buffer = new StringBuffer();
final String separator = ", ";
for (String tag : tagArgs.split("\\s+")) {
buffer.append("[" + tag + "]").append(separator);
}
if (buffer.length() == 0) {
return "";
} else {
return buffer.substring(0, buffer.length() - separator.length());
}
}
}
\java\seedu\taskscheduler\testutil\TestTask.java
/**
* A mutable person object. For testing only.
*/
public class TestTask implements ReadOnlyTask {
private Name name;
private Location address;
private TaskDateTime startDateTime;
private TaskDateTime endDateTime;
private UniqueTagList tags;
private boolean completeStatus;
private TaskType type;
public TestTask() {
tags = new UniqueTagList();
}
public TestTask(Name name, TaskDateTime startDateTime, TaskDateTime endDateTime, Location address, UniqueTagList tags) {
assert !CollectionUtil.isAnyNull(name, startDateTime, endDateTime, address, tags);
this.name = name;
this.startDateTime = new TaskDateTime(startDateTime);
this.endDateTime = new TaskDateTime(endDateTime);
this.address = address;
this.tags = new UniqueTagList(tags);
this.completeStatus = false;
}
public TestTask(ReadOnlyTask source) {
this(source.getName(), source.getStartDate(), source.getEndDate(), source.getLocation(), source.getTags());
}
public void setName(Name name) {
this.name = name;
}
public void setAddress(Location address) {
this.address = address;
}
public void setStartDate(TaskDateTime date) {
this.startDateTime = date;
}
public void setEndDate(TaskDateTime date) {
this.endDateTime = date;
}
@Override
public Name getName() {
return name;
}
@Override
public TaskDateTime getStartDate() {
return startDateTime;
}
@Override
public TaskDateTime getEndDate() {
return endDateTime;
}
@Override
public Location getLocation() {
return address;
}
@Override
public UniqueTagList getTags() {
return tags;
}
@Override
public String toString() {
return getAsText();
}
public String getAddCommand() {
return "add " + getTaskString();
}
public String getTaskString() {
if (this.getType() == TaskType.FLOATING) {
return getFloatingString();
} else if (this.getType() == TaskType.DEADLINE) {
return getDeadlineString();
} else {
return getEventString();
}
}
private String getFloatingString() {
return " " + this.getName().fullName;
}
private String getDeadlineString() {
StringBuilder sb = new StringBuilder();
sb.append(" " + this.getName().fullName + " ");
sb.append("by " + this.getEndDate());
return sb.toString();
}
private String getEventString() {
StringBuilder sb = new StringBuilder();
sb.append(" " + this.getName().fullName + " ");
sb.append("from " + this.getStartDate() + " ");
sb.append("to " + this.getEndDate() + " ");
sb.append("at" + " " + this.getLocation().value);
return sb.toString();
}
public void addDuration(long duration) {
if (startDateTime.getDate() != null)
this.startDateTime.setDate(startDateTime.getDate().getTime() + duration + 1);
if (endDateTime.getDate() != null)
this.endDateTime.setDate(endDateTime.getDate().getTime() + duration + 1);
}
@Override
public TestTask copy() {
return new TestTask(this);
}
@Override
public boolean hasCompleted() {
return completeStatus;
}
@Override
public TaskType getType() {
return type;
}
public void setType(TaskType type) {
this.type = type;
}
@Override
public boolean isOverdue() {
// TODO Auto-generated method stub
return false;
}
}
\java\seedu\taskscheduler\testutil\TypicalTestTasks.java
/**
*
*/
public class TypicalTestTasks {
public static TestTask alice, benson, carl, daniel, elle, fiona, george, event, ida, overdue, floating, deadline;
public TypicalTestTasks() {
try {
alice = new TaskBuilder().withName("Career Fair").withAddress("NUS COM1")
.withStartDate("07 Oct 2016").withEndDate("11 Oct 2016").withType("EVENT").build();
benson = new TaskBuilder().withName("Groupwork Project").withAddress("")
.withStartDate("").withEndDate("14 Oct 2016 at 8 am").withType("DEADLINE").withTags("Deadline").build(); // deadline task
carl = new TaskBuilder().withName("Project Discussion").withAddress("Technoedge")
.withStartDate("14 Oct 2016 at 1 pm").withEndDate("21 Oct 2016").withType("EVENT").withTags("Event").build();
daniel = new TaskBuilder().withName("Groupwork Discussion").withAddress("ICube Lecture Hall")
.withStartDate("01 Jan 2018").withEndDate("31 Dec 2018").withType("EVENT").withTags("Event").build();
elle = new TaskBuilder().withName("CS2103 Lecture").withAddress("ICube Lecture Hall")
.withStartDate("01 Jan 2018").withEndDate("31 Dec 2018").withType("EVENT").withTags("Event").build();
fiona = new TaskBuilder().withName("Send kid to NUS").withAddress("NUS")
.withStartDate("01 Jan 2034").withEndDate("01 Apri 2038").withType("EVENT").withTags("Event").build();
george = new TaskBuilder().withName("Project Briefing").withAddress("")
.withStartDate("").withEndDate("").withType("FLOATING").withTags().build(); // floating task
//Manually added
ida = new TaskBuilder().withName("University Graduation").withAddress("University Cultural Centre")
.withStartDate("7 July 2016").withEndDate("15 July 2016").withType("EVENT").build();
overdue = new TaskBuilder().withName("Overdue Task Colour Test").withAddress("At ICube Lecture Hall")
.withStartDate("10 years ago").withEndDate("10 years ago").withType("EVENT").build();
event = new TaskBuilder().withName("Wildlife Photoshoot").withAddress("Wildlife Reserves")
.withStartDate("yesterday").withEndDate("today").withType("EVENT").build(); // event task
floating = new TaskBuilder().withName("Floating Task").withAddress("")
.withStartDate("").withEndDate("").withType("FLOATING").withTags().build(); // floating task
deadline = new TaskBuilder().withName("Deadline Task").withAddress("")
.withStartDate("").withEndDate("tomorrow").withType("DEADLINE").withTags("Deadline").build(); // deadline task
} catch (IllegalValueException e) {
e.printStackTrace();
assert false : "not possible";
}
}
public static void loadTaskSchedulerWithSampleData(TaskScheduler ab) {
try {
ab.addTask(new EventTask(alice));
ab.addTask(new DeadlineTask(benson));
ab.addTask(new Task(carl));
ab.addTask(new FloatingTask(daniel));
ab.addTask(new Task(elle));
ab.addTask(new Task(fiona));
ab.addTask(new Task(george));
} catch (UniqueTaskList.DuplicateTaskException e) {
assert false : "not possible";
}
}
public TestTask[] getTypicalTasks() {
return new TestTask[] {alice, benson, carl, daniel, elle, fiona, george};
}
public TaskScheduler getTypicalTaskScheduler(){
TaskScheduler ab = new TaskScheduler();
loadTaskSchedulerWithSampleData(ab);
return ab;
}
}