Skip to content

Commit

Permalink
Improve code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
SukiTsang committed Nov 2, 2016
1 parent 584da7e commit 8417357
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 49 deletions.
5 changes: 2 additions & 3 deletions src/main/java/seedu/task/logic/commands/UnpinCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,15 @@ public CommandResult execute() {
ReadOnlyTask orginialTask = lastShownList.get(targetIndex - 1);
try {
Task taskToUnpin = new Task(orginialTask);
if(taskToUnpin.getImportance()){
if(taskToUnpin.getImportance()) {
taskToUnpin.setIsImportant(false);
model.unpinTask(orginialTask, taskToUnpin);
}else{
} else {
return new CommandResult(false, Messages.MESSAGE_INVALID_UNPIN_TASK);
}
} catch (IllegalValueException e) {
assert false : "Not possible for task on list to have illegal value";
}

return new CommandResult(true, String.format(MESSAGE_UNPIN_TASK_SUCCESS, orginialTask));
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/task/model/task/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public UniqueTagList getTags() {
public void setTags(UniqueTagList replacement) {
tags.setTags(replacement);
}
//@@author A0153467Y

/**
* Retrieves an immutable version of the task. Will not mutate if task is changed afterwards.
*/
Expand All @@ -116,7 +116,7 @@ public ReadOnlyTask getImmutable() {
return null;
}
}

//@@author A0153467Y
/**
* Sets the task's importance flag
* @param isImportant is a variable to show whether the task is important or not
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/seedu/task/model/task/UniqueTaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ public void unpin(ReadOnlyTask originalTask, Task toUnpin) {

/**
* Marks a task as completed in the list.
*
* @param originalTask refers to task which is not marked as completed yet
* @param completeTask refers to the same task as originalTask except it is marked as completed
*/
public void complete(ReadOnlyTask originalTask, Task completeTask) {
assert originalTask != null;
Expand All @@ -146,6 +149,9 @@ public void complete(ReadOnlyTask originalTask, Task completeTask) {
//@@author A0153467Y
/**
* Marks a task which is marked as completed to not completed in the list.
*
* @param originalTask refers to a task marked as completed
* @param uncompleteTask refers to the same task as original except it is not marked as complete
*/
public void uncomplete(ReadOnlyTask originalTask, Task uncompleteTask) {
assert originalTask != null;
Expand Down
25 changes: 16 additions & 9 deletions src/test/java/guitests/PinCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,26 @@
import static seedu.task.logic.commands.PinCommand.MESSAGE_PIN_TASK_SUCCESS;
import static seedu.task.logic.commands.PinCommand.MESSAGE_USAGE;

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

import seedu.task.commons.core.Messages;
import seedu.task.model.task.ReadOnlyTask;
import seedu.task.testutil.TestTask;

public class PinCommandTest extends TaskManagerGuiTest {

private TestTask[] currentList;
private int targetIndex;

@Before
public void runOnceBeforeClass() {
currentList = td.getTypicalTasks();
}

@Test
public void pinTask() {
TestTask[] currentList = td.getTypicalTasks();
int targetIndex = 1;
targetIndex = 1;

// pin the first task
commandBox.runCommand("pin " + targetIndex);
Expand All @@ -38,25 +47,23 @@ public void pinTask() {
assertTrue(newTask.getImportance());
assertResultMessage(String.format(MESSAGE_PIN_TASK_SUCCESS, newTask));
}

@Test
public void pinTask_emptyList() {
TestTask[] currentList = td.getTypicalTasks();

// pin at an empty list
commandBox.runCommand("clear");
commandBox.runCommand("pin " + (currentList.length + 1));
assertResultMessage(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
}

@Test
public void invalidPinTask() {
TestTask[] currentList = td.getTypicalTasks();
// invalid index
commandBox.runCommand("pin " + (currentList.length + 1));
assertResultMessage(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
//invalid command

// invalid command
commandBox.runCommand("pin");
assertResultMessage(String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT, MESSAGE_USAGE));
}
}
}
36 changes: 22 additions & 14 deletions src/test/java/guitests/UncompleteCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,33 @@
import static org.junit.Assert.assertFalse;
import static seedu.task.logic.commands.UncompleteCommand.MESSAGE_UNCOMPLETE_TASK_SUCCESS;

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

import seedu.task.commons.core.Messages;
import seedu.task.model.task.ReadOnlyTask;
import seedu.task.testutil.TestTask;

public class UncompleteCommandTest extends TaskManagerGuiTest {

private TestTask[] currentList;
private int targetIndex;

@Before
public void runOnceBeforeClass() {
currentList = td.getTypicalTasks();
}

@Test
public void uncomplete() {
TestTask[] currentList = td.getTypicalTasks();
int targetIndex = 1;

// invalid index
commandBox.runCommand("uncomplete " + (currentList.length + 1));
assertResultMessage(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
targetIndex = 1;

// mark an originally completed task as not complete
commandBox.runCommand("complete " + targetIndex);
commandBox.runCommand("uncomplete " + targetIndex);
ReadOnlyTask newTask = taskListPanel.getTask(targetIndex - 1);
assertFalse(newTask.getComplete());
assertResultMessage(String.format(MESSAGE_UNCOMPLETE_TASK_SUCCESS, newTask));
assertResultMessage(String.format(MESSAGE_UNCOMPLETE_TASK_SUCCESS, newTask));

// unmark another task
targetIndex = 3;
Expand All @@ -39,18 +44,21 @@ public void uncomplete() {
targetIndex = currentList.length;
commandBox.runCommand("uncomplete " + targetIndex);
newTask = taskListPanel.getTask(targetIndex - 1);
//this task should still be marked as not complete
// this task should still be marked as not complete
assertFalse(newTask.getComplete());
assertResultMessage(Messages.MESSAGE_INVALID_UNCOMPLETE_TASK);

}

@Test
public void invalidUncomplete() {
// invalid index
commandBox.runCommand("uncomplete " + (currentList.length + 1));
assertResultMessage(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);

// mark at an empty list
commandBox.runCommand("clear");
commandBox.runCommand("uncomplete " + (currentList.length + 1));
assertResultMessage(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);

//invalid command
commandBox.runCommand("unncomaplete");
assertResultMessage(Messages.MESSAGE_UNKNOWN_COMMAND);
}

}
}
31 changes: 18 additions & 13 deletions src/test/java/guitests/UnpinCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,26 @@
import static org.junit.Assert.assertFalse;
import static seedu.task.logic.commands.UnpinCommand.MESSAGE_UNPIN_TASK_SUCCESS;

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

import seedu.task.commons.core.Messages;
import seedu.task.model.task.ReadOnlyTask;
import seedu.task.testutil.TestTask;

public class UnpinCommandTest extends TaskManagerGuiTest {

private TestTask[] currentList;
private int targetIndex;

@Before
public void runOnceBeforeClass() {
currentList = td.getTypicalTasks();
}

@Test
public void unpin() {
TestTask[] currentList = td.getTypicalTasks();
int targetIndex = 1;
targetIndex = 1;

// unpin the first task
commandBox.runCommand("pin " + targetIndex);
Expand All @@ -34,33 +43,29 @@ public void unpin() {

@Test
public void invalidUnpin() {
TestTask[] currentList = td.getTypicalTasks();

// unpin a task which is not pinned
int targetIndex = 3;
targetIndex = 3;
commandBox.runCommand("unpin " + targetIndex);
ReadOnlyTask newTask = taskListPanel.getTask(targetIndex - 1);
//check that the task is still not pinned

// check that the task is still not pinned
assertFalse(newTask.getImportance());
assertResultMessage(Messages.MESSAGE_INVALID_UNPIN_TASK);
//invalid command

// invalid command
commandBox.runCommand("unppinn");
assertResultMessage(Messages.MESSAGE_UNKNOWN_COMMAND);


// invalid index
commandBox.runCommand("unpin " + (currentList.length + 1));
assertResultMessage(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
}

@Test
public void unpinTask_emtpyList() {
TestTask[] currentList = td.getTypicalTasks();
// unpin at an empty list
commandBox.runCommand("clear");
commandBox.runCommand("unpin " + (currentList.length + 1));
assertResultMessage(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
}
}
}
2 changes: 1 addition & 1 deletion src/test/java/seedu/task/testutil/TaskBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public TaskBuilder withTags(String ... tags) throws IllegalValueException {
}
return this;
}

//@@author A0153467Y
public TaskBuilder withImportance(boolean isImportant) throws IllegalValueException{
this.task.setIsImportant(isImportant);
return this;
Expand Down
15 changes: 8 additions & 7 deletions src/test/java/seedu/task/testutil/TestTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@ public TestTask() {
public void setName(Name name) {
this.name = name;
}

//@@author A0153467Y
public void setIsImportant(boolean isImportant){
this.isImportant=isImportant;
}

//@@author
public void setOpenTime(DateTime openTime) {
this.openTime = openTime;
}

public void setCloseTime(DateTime closeTime) {
this.closeTime = closeTime;
}

//@@author A0153467Y
public void setIsCompleted(boolean isCompleted){
this.isCompleted = isCompleted;
}

//@@author
public void setRecurrentWeek(int recurrentWeek){
this.recurrentWeek=recurrentWeek;
}
Expand All @@ -49,12 +49,12 @@ public void setRecurrentWeek(int recurrentWeek){
public Name getName() {
return name;
}

//@@author A0153467Y
@Override
public boolean getComplete() {
return isCompleted;
}

//@@author
@Override
public DateTime getOpenTime() {
return openTime;
Expand All @@ -74,11 +74,12 @@ public UniqueTagList getTags() {
public int getRecurrentWeek() {
return recurrentWeek;
}

//@@author A0153467Y
@Override
public boolean getImportance() {
return isImportant;
}
//@@author
@Override
public String toString() {
return getAsText();
Expand Down

0 comments on commit 8417357

Please sign in to comment.