Skip to content

Commit

Permalink
[Test]Modified favorite task test
Browse files Browse the repository at this point in the history
  • Loading branch information
ChewZL committed Oct 24, 2016
1 parent 413580b commit 097b102
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void favoriteTask_indexTooSmall() throws IllegalValueException {
}

@Test
public void favoriteTask_validIndex() throws IllegalValueException {
public void favoriteTask_duplicateFavorite() throws IllegalValueException {
/*
* CommandResult should return a string that denotes success in execution if index given
* to favoriteTaskCommand constructor is within the range of added tasks.
Expand All @@ -72,6 +72,21 @@ public void favoriteTask_validIndex() throws IllegalValueException {
String expected = String.format(FavoriteTaskCommand.MESSAGE_FAVORITE_TASK_SUCCESS, "[Floating Task][Description: Task 1]");
assertCommandFeedback(command, expected);
}

@Test
public void favoriteTask_validIndex() throws IllegalValueException {
/*
* CommandResult should return a string that the task
* has already been favorited
*/
InMemoryTaskList model;
model = TestUtil.setupSomeFavoritedTasksInTaskList(3);
FavoriteTaskCommand command = new FavoriteTaskCommand(2);
command.setData(model);

String expected = String.format(FavoriteTaskCommand.MESSAGE_TASK_ALR_FAVORITED);
assertCommandFeedback(command, expected);
}

/*
* Given a command and an expected string, execute the command
Expand Down
42 changes: 29 additions & 13 deletions src/test/java/seedu/address/testutil/TestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,37 @@ public static InMemoryTaskList setupFloatingTasks(int n) throws IllegalValueExce
return newTaskList;
}

// Setting up tasks in the TaskList in order to find them in the tests
// Setting up completed tasks in the TaskList in order to find them in the tests
public static InMemoryTaskList setupSomeCompletedTasksInTaskList(int n) throws IllegalValueException {
InMemoryTaskList newTaskList = new TaskManager();
// Add 3 tasks into the task manager
for (int i = 0; i < n; i++) {
AddTaskCommand command = new AddTaskCommand(String.format("Task %d", i));
command.setData(newTaskList);
command.execute();
}
UnmodifiableObservableList<Task> list= newTaskList.getCurrentFilteredTasks();
for (int i = 0; i < n; i++) {
list.get(i).setAsComplete();
}
return newTaskList;
InMemoryTaskList newTaskList = new TaskManager();
// Add 3 tasks into the task manager
for (int i = 0; i < n; i++) {
AddTaskCommand command = new AddTaskCommand(String.format("Task %d", i));
command.setData(newTaskList);
command.execute();
}
UnmodifiableObservableList<Task> list= newTaskList.getCurrentFilteredTasks();
for (int i = 0; i < n; i++) {
list.get(i).setAsComplete();
}
return newTaskList;
}

// Setting up favorited tasks in the TaskList in order to find them in the tests
public static InMemoryTaskList setupSomeFavoritedTasksInTaskList(int n) throws IllegalValueException {
InMemoryTaskList newTaskList = new TaskManager();
// Add 3 tasks into the task manager
for (int i = 0; i < n; i++) {
AddTaskCommand command = new AddTaskCommand(String.format("Task %d", i));
command.setData(newTaskList);
command.execute();
}
UnmodifiableObservableList<Task> list= newTaskList.getCurrentFilteredTasks();
for (int i = 0; i < n; i++) {
list.get(i).setAsFavorite();
}
return newTaskList;
}
/**
* Setting up interleaved Floating, Deadline and Event tasks.
* Dates for Deadline tasks are set to 1 January 2016.
Expand Down

0 comments on commit 097b102

Please sign in to comment.