Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/A-Assertions'
Browse files Browse the repository at this point in the history
  • Loading branch information
limhawjia committed Sep 9, 2019
2 parents 7101459 + b316c29 commit 1f492b7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public void configure(Options options) {

// Initialize tasks and storage
Storage storage = options.getStorage();
assert storage != null;
TasksController tasks = TasksController.fromStorage(storage, ui);

// Initialize command factory
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/duke/task/TasksController.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public void addTask(Task task) throws UiException {
try {
List<Task> tasks = storage.getTasks();
tasks.add(task);

assert tasks.contains(task);

storage.writeTasks(tasks);
view.displayNewTask(task, tasks.size(), ui);
} catch (StorageException e) {
Expand All @@ -80,6 +83,8 @@ public void setTaskToDone(int index) throws UiException {

view.displayTaskDone(tasks.get(index), ui);

assert tasks.get(index).isDone();

// write changes to storage file
storage.writeTasks(tasks);

Expand Down Expand Up @@ -116,6 +121,8 @@ public void deleteTask(int index) throws UiException {
tasks.remove(index);
view.displayTaskDeleted(deleted, tasks.size(), ui);

assert !tasks.contains(deleted);

storage.writeTasks(tasks);
} catch (StorageException e) {
ui.displayOutput(e.getMessage());
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/duke/task/tasks/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public void setDone(boolean done) {
this.done = done;
}

public boolean isDone() {
return this.done;
}

public String getDescription() {
return description;
}
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/ui/UiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@ public void initializeUi() {
}

public void displayOutput(String message) throws UiException {
if (isStarted) {
output.display(message); // output only allowed to print after it is initialized with the input
} else {
throw new UiException("Ui not initialized.");
}
assert isStarted;
output.display(message); // output only allowed to print after it is initialized with the input
}

@Override
Expand Down

0 comments on commit 1f492b7

Please sign in to comment.