Skip to content

Commit

Permalink
Bugfix for complete/uncomplete, updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
irvinlim committed Nov 7, 2016
1 parent bd733cc commit d5010f8
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 4 deletions.
20 changes: 18 additions & 2 deletions src/main/java/seedu/todo/controllers/CompleteTaskController.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class CompleteTaskController extends Controller {
private static final String COMMAND_KEYWORD = "complete";

public static final String MESSAGE_SUCCESS = "Task marked as complete!";
public static final String MESSAGE_MISSING_INDEX = "Please specify the index of the item to delete.";
public static final String MESSAGE_INDEX_NOT_NUMBER = "Index has to be a number!";
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!";
Expand All @@ -34,10 +36,24 @@ public CommandDefinition getCommandDefinition() {

@Override
public void process(String args) {
// TODO: Example of last minute work
// Get index.
String param = args.replaceFirst(COMMAND_KEYWORD, "").trim();

if (param.length() <= 0) {
Renderer.renderDisambiguation(COMMAND_SYNTAX, MESSAGE_MISSING_INDEX);
return;
}

assert param.length() > 0;

// Get index.
int index = Integer.decode(args.replaceFirst("complete", "").trim());
int index = 0;
try {
index = Integer.decode(param);
} catch (NumberFormatException e) {
Renderer.renderDisambiguation(COMMAND_SYNTAX, MESSAGE_INDEX_NOT_NUMBER);
return;
}

// Get record
EphemeralDB edb = EphemeralDB.getInstance();
Expand Down
20 changes: 18 additions & 2 deletions src/main/java/seedu/todo/controllers/UncompleteTaskController.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class UncompleteTaskController extends Controller {
private static final String COMMAND_KEYWORD = "uncomplete";

public static final String MESSAGE_SUCCESS = "Task marked as incomplete!";
public static final String MESSAGE_MISSING_INDEX = "Please specify the index of the item to delete.";
public static final String MESSAGE_INDEX_NOT_NUMBER = "Index has to be a number!";
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!";
Expand All @@ -35,10 +37,24 @@ public CommandDefinition getCommandDefinition() {

@Override
public void process(String args) {
// TODO: Example of last minute work
// Get index.
String param = args.replaceFirst(COMMAND_KEYWORD, "").trim();

if (param.length() <= 0) {
Renderer.renderDisambiguation(COMMAND_SYNTAX, MESSAGE_MISSING_INDEX);
return;
}

assert param.length() > 0;

// Get index.
int index = Integer.decode(args.replaceFirst("uncomplete", "").trim());
int index = 0;
try {
index = Integer.decode(param);
} catch (NumberFormatException e) {
Renderer.renderDisambiguation(COMMAND_SYNTAX, MESSAGE_INDEX_NOT_NUMBER);
return;
}

// Get record
EphemeralDB edb = EphemeralDB.getInstance();
Expand Down
29 changes: 29 additions & 0 deletions src/test/java/seedu/todo/guitests/CompleteUncompleteTaskTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import seedu.todo.commons.util.DateUtil;
import seedu.todo.controllers.CompleteTaskController;
import seedu.todo.controllers.UncompleteTaskController;
import seedu.todo.controllers.concerns.Renderer;
import seedu.todo.models.Event;
import seedu.todo.models.Task;

Expand Down Expand Up @@ -125,4 +126,32 @@ public void uncomplete_wrongIndex_error() {
String consoleMessage = UncompleteTaskController.MESSAGE_INVALID_ITEM;
assertEquals(consoleMessage, console.getConsoleTextArea());
}

@Test
public void complete_missingIndex_error() {
console.runCommand("complete");
String consoleMessage = Renderer.MESSAGE_DISAMBIGUATE + "\n\n" + CompleteTaskController.MESSAGE_MISSING_INDEX;
assertEquals(consoleMessage, console.getConsoleTextArea());
}

@Test
public void uncomplete_missingIndex_error() {
console.runCommand("uncomplete");
String consoleMessage = Renderer.MESSAGE_DISAMBIGUATE + "\n\n" + UncompleteTaskController.MESSAGE_MISSING_INDEX;
assertEquals(consoleMessage, console.getConsoleTextArea());
}

@Test
public void complete_indexNotNumber_error() {
console.runCommand("complete this");
String consoleMessage = Renderer.MESSAGE_DISAMBIGUATE + "\n\n" + CompleteTaskController.MESSAGE_INDEX_NOT_NUMBER;
assertEquals(consoleMessage, console.getConsoleTextArea());
}

@Test
public void uncomplete_indexNotNumber_error() {
console.runCommand("uncomplete this");
String consoleMessage = Renderer.MESSAGE_DISAMBIGUATE + "\n\n" + UncompleteTaskController.MESSAGE_INDEX_NOT_NUMBER;
assertEquals(consoleMessage, console.getConsoleTextArea());
}
}

0 comments on commit d5010f8

Please sign in to comment.