Skip to content

Commit

Permalink
Merge aa891b6 into c00b823
Browse files Browse the repository at this point in the history
  • Loading branch information
louietyj committed Nov 6, 2016
2 parents c00b823 + aa891b6 commit 7e51f33
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/main/java/seedu/todo/controllers/CompleteTaskController.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public class CompleteTaskController extends Controller {
private static final String COMMAND_SYNTAX = "complete <index>";
private static final String COMMAND_KEYWORD = "complete";

private static final String MESSAGE_SUCCESS = "Task marked as complete!";
private static final String MESSAGE_INVALID_ITEM = "Could not mark task as complete: Invalid index provided!";
private static final String MESSAGE_CANNOT_COMPLETE_EVENT = "An event cannot be marked as complete!";
private static final String MESSAGE_ALREADY_COMPLETED = "Could not mark task as complete: Task is already complete!";
private static final String MESSAGE_COULD_NOT_SAVE = "Could not mark task as complete: An error occured while saving the database file.";
public static final String MESSAGE_SUCCESS = "Task marked as complete!";
public static final String MESSAGE_INVALID_ITEM = "Could not mark task as complete: Invalid index provided!";
public static final String MESSAGE_CANNOT_COMPLETE_EVENT = "An event cannot be marked as complete!";
public static final String MESSAGE_ALREADY_COMPLETED = "Could not mark task as complete: Task is already complete!";
public static final String MESSAGE_COULD_NOT_SAVE = "Could not mark task as complete: An error occured while saving the database file.";

private static CommandDefinition commandDefinition =
new CommandDefinition(NAME, DESCRIPTION, COMMAND_SYNTAX, COMMAND_KEYWORD);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public class UncompleteTaskController extends Controller {
private static final String COMMAND_SYNTAX = "uncomplete <index>";
private static final String COMMAND_KEYWORD = "uncomplete";

private static final String MESSAGE_SUCCESS = "Task marked as incomplete!";
private static final String MESSAGE_INVALID_ITEM = "Could not mark task as incomplete: Invalid index provided!";
private static final String MESSAGE_CANNOT_UNCOMPLETE_EVENT = "An event cannot be marked as incomplete!";
private static final String MESSAGE_ALREADY_INCOMPLETE = "Could not mark task as incomplete: Task is not completed!";
private static final String MESSAGE_COULD_NOT_SAVE = "Could not mark task as incomplete: An error occured while saving the database file.";
public static final String MESSAGE_SUCCESS = "Task marked as incomplete!";
public static final String MESSAGE_INVALID_ITEM = "Could not mark task as incomplete: Invalid index provided!";
public static final String MESSAGE_CANNOT_UNCOMPLETE_EVENT = "An event cannot be marked as incomplete!";
public static final String MESSAGE_ALREADY_INCOMPLETE = "Could not mark task as incomplete: Task is not completed!";
public static final String MESSAGE_COULD_NOT_SAVE = "Could not mark task as incomplete: An error occured while saving the database file.";


private static CommandDefinition commandDefinition =
Expand Down
126 changes: 126 additions & 0 deletions src/test/java/seedu/todo/guitests/CompleteUncompleteTaskTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package seedu.todo.guitests;

import static org.junit.Assert.assertEquals;

import java.time.LocalDateTime;

import org.junit.Before;
import org.junit.Test;

import seedu.todo.commons.util.DateUtil;
import seedu.todo.controllers.CompleteTaskController;
import seedu.todo.controllers.UncompleteTaskController;
import seedu.todo.models.Event;
import seedu.todo.models.Task;

/**
* @@author A0093907W
*/
public class CompleteUncompleteTaskTest extends GuiTest {

private final LocalDateTime oneDayFromNow = LocalDateTime.now().plusDays(1);
private final String oneDayFromNowString = DateUtil.formatDate(oneDayFromNow);
private final String oneDayFromNowIsoString = DateUtil.formatIsoDate(oneDayFromNow);
private final LocalDateTime twoDaysFromNow = LocalDateTime.now().plusDays(2);
private final String twoDaysFromNowString = DateUtil.formatDate(twoDaysFromNow);
private final String twoDaysFromNowIsoString = DateUtil.formatIsoDate(twoDaysFromNow);
private final LocalDateTime oneDayToNow = LocalDateTime.now().minusDays(1);
private final String oneDayToNowString = DateUtil.formatDate(oneDayToNow);
private final String oneDayToNowIsoString = DateUtil.formatIsoDate(oneDayToNow);

String commandAdd1 = String.format("add task Buy KOI by \"%s 8pm\"", oneDayToNowString);
Task task1 = new Task();
String commandAdd2 = String.format("add task Buy Milk by \"%s 9pm\"", oneDayFromNowString);
Task task2 = new Task();
String commandAdd3 = String.format("add event Some Event from \"%s 4pm\" to \"%s 5pm\"",
twoDaysFromNowString, twoDaysFromNowString);
Event event3 = new Event();

public CompleteUncompleteTaskTest() {
task1.setName("Buy KOI");
task1.setDueDate(DateUtil.parseDateTime(
String.format("%s 20:00:00", oneDayToNowIsoString)));
task2.setName("Buy Milk");
task2.setDueDate(DateUtil.parseDateTime(
String.format("%s 21:00:00", oneDayFromNowIsoString)));
event3.setName("Some Event");
event3.setStartDate(DateUtil.parseDateTime(
String.format("%s 16:00:00", twoDaysFromNowIsoString)));
event3.setEndDate(DateUtil.parseDateTime(
String.format("%s 17:00:00", twoDaysFromNowIsoString)));
}

@Before
public void fixtures() {
console.runCommand("clear");
console.runCommand(commandAdd1);
console.runCommand(commandAdd2);
console.runCommand(commandAdd3);
}

@Test
public void complete_futureTask_show() {
assertTaskVisibleAfterCmd("complete 2", task2);
}

@Test
public void complete_overdueTask_hide() {
assertTaskNotVisibleAfterCmd("complete 1", task1);
}

@Test
public void uncomplete_futureTask_show() {
console.runCommand("complete 2");
assertTaskVisibleAfterCmd("uncomplete 2", task2);
}

@Test
public void uncomplete_overdueTask_show() {
console.runCommand("complete 1");
console.runCommand("list completed");
assertTaskVisibleAfterCmd("uncomplete 1", task1);
}

@Test
public void complete_event_error() {
console.runCommand("complete 3");
String consoleMessage = CompleteTaskController.MESSAGE_CANNOT_COMPLETE_EVENT;
assertEquals(consoleMessage, console.getConsoleTextArea());
}

@Test
public void uncomplete_event_error() {
console.runCommand("uncomplete 3");
String consoleMessage = UncompleteTaskController.MESSAGE_CANNOT_UNCOMPLETE_EVENT;
assertEquals(consoleMessage, console.getConsoleTextArea());
}

@Test
public void complete_completedTask_error() {
console.runCommand("complete 2");
console.runCommand("complete 2");
String consoleMessage = CompleteTaskController.MESSAGE_ALREADY_COMPLETED;
assertEquals(consoleMessage, console.getConsoleTextArea());
}

@Test
public void uncomplete_uncompleteTask_error() {
console.runCommand("uncomplete 1");
String consoleMessage = UncompleteTaskController.MESSAGE_ALREADY_INCOMPLETE;
assertEquals(consoleMessage, console.getConsoleTextArea());
}

@Test
public void complete_wrongIndex_error() {
console.runCommand("complete 10");
String consoleMessage = CompleteTaskController.MESSAGE_INVALID_ITEM;
assertEquals(consoleMessage, console.getConsoleTextArea());
}

@Test
public void uncomplete_wrongIndex_error() {
console.runCommand("uncomplete 10");
String consoleMessage = UncompleteTaskController.MESSAGE_INVALID_ITEM;
assertEquals(consoleMessage, console.getConsoleTextArea());
}
}

0 comments on commit 7e51f33

Please sign in to comment.