Skip to content
This repository has been archived by the owner on Mar 2, 2019. It is now read-only.

Commit

Permalink
add title parameter to edit command
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhangYiJiang committed Oct 16, 2016
1 parent aad2326 commit b7a2525
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/main/java/seedu/todo/logic/commands/EditCommand.java
Expand Up @@ -12,6 +12,9 @@ public class EditCommand extends BaseCommand {

private Argument<Integer> index = new IntArgument("index").required();

private Argument<String> title = new StringArgument("title")
.flag("t");

private Argument<String> description = new StringArgument("description")
.flag("m");

Expand All @@ -26,7 +29,7 @@ public class EditCommand extends BaseCommand {

@Override
protected Parameter[] getArguments() {
return new Parameter[] { index, date, description, pin, location };
return new Parameter[] { index, title, date, description, pin, location };
}

@Override
Expand All @@ -44,6 +47,10 @@ public List<CommandSummary> getCommandSummary() {
@Override
public CommandResult execute() throws ValidationException {
ImmutableTask editedTask = this.model.update(index.getValue(), task -> {
if (title.hasBoundValue()) {
task.setTitle(title.getValue());
}

if (description.hasBoundValue()) {
task.setDescription(description.getValue());
}
Expand Down
16 changes: 15 additions & 1 deletion src/test/java/seedu/todo/logic/commands/EditCommandTest.java
Expand Up @@ -44,6 +44,19 @@ public void testEditInvalidIndex() throws Exception {
execute(true);
}

@Test
public void testEditTitle() throws Exception {
setParameter("1");
setParameter("t", "New Title");
execute(true);

ImmutableTask task = getTaskAt(1);
assertEquals("New Title", task.getTitle());
assertTrue(task.isPinned());
assertEquals("NUS", task.getLocation().get());
assertFalse(task.getDescription().isPresent());
}

@Test
public void testEditPinned() throws Exception {
setParameter("1");
Expand Down Expand Up @@ -133,13 +146,14 @@ public void testRemoveDate() throws Exception {

@Test
public void testEditMoreThanOneParameter() throws Exception {
setParameter("t", "New Title");
setParameter("1");
setParameter("m", "New description");
setParameter("l", "Singapura");
execute(true);

ImmutableTask toEditTwoThings = getTaskAt(1);
assertEquals("Task 1", toEditTwoThings.getTitle());
assertEquals("New Title", toEditTwoThings.getTitle());
assertTrue(toEditTwoThings.isPinned());
assertEquals("New description", toEditTwoThings.getDescription().get());
assertEquals("Singapura", toEditTwoThings.getLocation().get());
Expand Down

0 comments on commit b7a2525

Please sign in to comment.