Skip to content

Commit

Permalink
Merge pull request #14
Browse files Browse the repository at this point in the history
Add assertions to Command class to ensure valid input and state
  • Loading branch information
JJtan2002 authored Sep 10, 2024
2 parents 34e85dc + a2a8891 commit 3821b92
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main/java/echobot/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,20 @@ public class Command {
* @param tasks The list of tasks to be manipulated by this command.
*/
public Command(String[] inputParts, TaskList tasks) {
// Assert that inputParts is not null and has at least one element
assert inputParts != null && inputParts.length > 0
: "Input parts should not be null and must contain at least one element.";

this.inputParts = inputParts;
this.command = inputParts[0];
this.tasks = tasks;

// Assert that command is not null or empty
assert this.command != null && !this.command.trim().isEmpty()
: "Command should not be null or empty.";

// Assert that tasks is not null
assert this.tasks != null : "Task list should not be null.";
}

/**
Expand All @@ -54,6 +65,9 @@ public boolean isExit() {
* The command may modify the task list or provide feedback to the user.
*/
public void run() {
// Assert that the command is a valid one
assert this.command != null : "Command should not be null.";

switch (this.command) {
case "bye":
break;
Expand Down

0 comments on commit 3821b92

Please sign in to comment.