Skip to content

Commit

Permalink
Add comments on DukeCommandTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Denniszedead committed Feb 7, 2022
1 parent 35dfc3c commit 91a6712
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 42 deletions.
36 changes: 19 additions & 17 deletions src/main/java/duke/command/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected Command(String parameter) {
*
* @param taskList The TaskList which the command will act on.
* @param storage The Storage on which the command will act on.
* @return The string that will be shown on the duke dialogue.
* @return The string that will be shown on the Dialogue Box.
* @throws DukeExceptions The exception from Duke if there are errors encountered.
*/
public abstract String run(TaskList taskList, Storage storage) throws DukeExceptions;
Expand Down Expand Up @@ -69,6 +69,7 @@ public static Command getCommand(String command, String parameter) throws Invali
} else if (command.equals("FIND")) {
return new FindCommand(parameter);
} else {
// Throws invalid command as the user gives a invalid command.
throw InvalidCommandException.createInvalidCommand(command);
}
}
Expand All @@ -88,14 +89,13 @@ protected ByeCommand(String parameter) {
*
* @param taskList The TaskList which the command will act on.
* @param storage The Storage on which the command will act on.
* @return Empty string, there is no significance.
* @throws DukeExceptions Should not have an exception unless it is an unexpected error.
* @return
*/
@Override
public String run(TaskList taskList, Storage storage) throws DukeExceptions {
// Exits duke.
System.exit(0);

return "";
}
}
Expand All @@ -114,8 +114,8 @@ protected ListCommand(String parameter) {
*
* @param taskList The TaskList which the command will act on.
* @param storage The Storage on which the command will act on.
* @return All the tasks in the task list which will then be shown in the Dialogue box.
* @throws DukeExceptions Should not have an exception unless it is an unexpected error.
* @return
*/
@Override
public String run(TaskList taskList, Storage storage) throws DukeExceptions {
Expand All @@ -137,10 +137,9 @@ protected MarkCommand(String parameter) {
* Marks the task indicated by the index in the task list.
*
* @param taskList The TaskList which the command will act on.
* @param ui The UI on which the command will act on.
* @param storage The Storage on which the command will act on.
* @return The recently marked task that will be shown on the Dialogue box.
* @throws DukeExceptions Occurs if the user did not enter a number or the number is out of range from the index.
* @return
*/
@Override
public String run(TaskList taskList, Storage storage) throws DukeExceptions {
Expand Down Expand Up @@ -182,10 +181,9 @@ protected UnmarkCommand(String parameter) {
* Unmarks the task indicated by the index in the task list.
*
* @param taskList The TaskList which the command will act on.
* @param ui The UI on which the command will act on.
* @param storage The Storage on which the command will act on.
* @return The recently unmarked task that will be shown in the dialogue box.
* @throws DukeExceptions Occurs if the user did not enter a number or the number is out of range from the index.
* @return
*/
@Override
public String run(TaskList taskList, Storage storage) throws DukeExceptions {
Expand Down Expand Up @@ -228,10 +226,9 @@ protected TodoCommand(String parameter) {
* Adds a todo task in the task list.
*
* @param taskList The TaskList which the command will act on.
* @param ui The UI on which the command will act on.
* @param storage The Storage on which the command will act on.
* @return The recently created todo which will then be shown on the dialogue box.
* @throws DukeExceptions If the user did not indicate a name of the task.
* @return
*/
@Override
public String run(TaskList taskList, Storage storage) throws DukeExceptions {
Expand Down Expand Up @@ -268,10 +265,9 @@ protected DeadlineCommand(String parameter) {
* Adds a deadline command into the task list.
*
* @param taskList The TaskList which the command will act on.
* @param ui The UI on which the command will act on.
* @param storage The Storage on which the command will act on.
* @return The recently created deadline that will be then shown in the dialogue box.
* @throws DukeExceptions If the users enters no parameter, no date or invalid date.
* @return
*/
@Override
public String run(TaskList taskList, Storage storage) throws DukeExceptions {
Expand Down Expand Up @@ -329,10 +325,9 @@ protected EventCommand(String parameter) {
* Adds an event task in the task list.
*
* @param taskList The TaskList which the command will act on.
* @param ui The UI on which the command will act on.
* @param storage The Storage on which the command will act on.
* @return The recently created event which will be then sent to the dialogue box.
* @throws DukeExceptions If the users enters no parameter, no date or invalid date.
* @return
*/
@Override
public String run(TaskList taskList, Storage storage) throws DukeExceptions {
Expand Down Expand Up @@ -391,10 +386,9 @@ class DeleteCommand extends Command {
* Deletes the task indicated by the index number in the task list.
*
* @param taskList The TaskList which the command will act on.
* @param ui The UI on which the command will act on.
* @param storage The Storage on which the command will act on.
* @param storage The Storage on which the command will act on.
* @return The recently deleted task that will be sent to the dialogue box.
* @throws DukeExceptions If the user did not enter a number.
* @return
*/
@Override
public String run(TaskList taskList, Storage storage) throws DukeExceptions {
Expand Down Expand Up @@ -437,6 +431,14 @@ protected FindCommand(String parameter) {
super(parameter);
}

/**
* Gets all the tasks that contains the keyword and shos it to the user.
*
* @param taskList The TaskList which the command will act on.
* @param storage The Storage on which the command will act on.
* @return The tasks that contain the keyword.
* @throws DukeExceptions
*/
@Override
public String run(TaskList taskList, Storage storage) throws DukeExceptions {
// Check if the user did not enter a keyword, then throw the EmptyKeywordException exception.
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/duke/components/DialogBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,24 @@ private void flip() {
setAlignment(Pos.TOP_LEFT);
}

/**
* Creates a new dialogue box from the user based on the text and image.
*
* @param text
* @param img
* @return
*/
public static DialogBox getUserDialog(String text, Image img) {
return new DialogBox(text, img);
}

/**
* Creates a new dialogue box from duke.
*
* @param text
* @param img
* @return
*/
public static DialogBox getDukeDialog(String text, Image img) {
var db = new DialogBox(text, img);
db.flip();
Expand Down
46 changes: 21 additions & 25 deletions src/test/java/duke/command/TestCommand.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
package duke.command;

import java.awt.color.CMMException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

import duke.dukeexceptions.InvalidDateException;
import duke.task.Task;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import duke.dukeexceptions.DukeExceptions;
import duke.dukeexceptions.InvalidCommandException;
import duke.storage.Storage;
import duke.task.Task;
import duke.tasklist.TaskList;

public class TestCommand {
String fileName = "data/test/dukeEmptyTxt.txt";
private String fileName = "data/test/dukeEmptyTxt.txt";

@Test
void createCommand_noCommand_missingCommandExceptionThrown() {
Expand Down Expand Up @@ -126,11 +122,11 @@ void createMarkCommand_markCommandWithNumber_taskMarked() {
FileWriter fw = new FileWriter(dataFile);

// Add the initial data into the data file.
tasks.addTask(Task.createTask("TODO",false, "Task 1", ""));
tasks.addTask(Task.createTask("TODO", false, "Task 1", ""));
storage.updateData(tasks);
String result = "";
while (sc.hasNext()) {
result += sc.nextLine() + "\n";
result += sc.nextLine() + "\n";
}
Assertions.assertEquals(initial, result);

Expand All @@ -142,7 +138,7 @@ void createMarkCommand_markCommandWithNumber_taskMarked() {
result = "";
sc = new Scanner(dataFile);
while (sc.hasNext()) {
result += sc.nextLine() + "\n";
result += sc.nextLine() + "\n";
}
Assertions.assertEquals(expectedTwo, result);

Expand Down Expand Up @@ -197,11 +193,11 @@ void createUnmarkCommandResult_unmarkCommandWithNumber_taskUnmarked() {
FileWriter fw = new FileWriter(dataFile);

// Initialize the data in the data file.
tasks.addTask(Task.createTask("TODO",true, "Task 1", ""));
tasks.addTask(Task.createTask("TODO", true, "Task 1", ""));
storage.updateData(tasks);
String result = "";
while (sc.hasNext()) {
result += sc.nextLine() + "\n";
result += sc.nextLine() + "\n";
}
Assertions.assertEquals(initial, result);

Expand All @@ -213,7 +209,7 @@ void createUnmarkCommandResult_unmarkCommandWithNumber_taskUnmarked() {
result = "";
sc = new Scanner(dataFile);
while (sc.hasNext()) {
result += sc.nextLine() + "\n";
result += sc.nextLine() + "\n";
}
Assertions.assertEquals(expectedTwo, result);

Expand All @@ -227,7 +223,7 @@ void createUnmarkCommandResult_unmarkCommandWithNumber_taskUnmarked() {
}

@Test
void createTodoCommand_TodoWithoutName_throwsEmptyTaskException() {
void createTodoCommand_todoWithoutName_throwsEmptyTaskException() {
try {
Command cmd = Command.getCommand("TODO", "");
Storage storage = new Storage(fileName);
Expand All @@ -241,7 +237,7 @@ void createTodoCommand_TodoWithoutName_throwsEmptyTaskException() {
}

@Test
void createTodoCommand_TodoWithName_createTodoInFile() {
void createTodoCommand_todoWithName_createTodoInFile() {
String initial = "";
String expectedOne = "Added the following todo into the list:\n[T][ ] Task 1";
String expectedTwo = "TODO\n"
Expand All @@ -260,7 +256,7 @@ void createTodoCommand_TodoWithName_createTodoInFile() {
String result = "";
sc = new Scanner(dataFile);
while (sc.hasNext()) {
result += sc.nextLine() + "\n";
result += sc.nextLine() + "\n";
}
Assertions.assertEquals(initial, result);

Expand All @@ -273,7 +269,7 @@ void createTodoCommand_TodoWithName_createTodoInFile() {
result = "";
sc = new Scanner(dataFile);
while (sc.hasNext()) {
result += sc.nextLine() + "\n";
result += sc.nextLine() + "\n";
}
Assertions.assertEquals(expectedTwo, result);

Expand Down Expand Up @@ -331,8 +327,8 @@ void createDeadlineCommand_deadlineWithInvalidDate_throwsInvalidDateException()
@Test
void createDeadlineCommand_correctDeadline_createDeadlineInFile() {
String initial = "";
String expectedOne
= "Added the following deadline into the list:\n[D][ ] Deadline 1 (by: 01 Jan 2022 11:59 PM)";
String expectedOne =
"Added the following deadline into the list:\n[D][ ] Deadline 1 (by: 01 Jan 2022 11:59 PM)";
String expectedTwo = "DEADLINE\n"
+ "false\n"
+ "Deadline 1\n"
Expand All @@ -350,7 +346,7 @@ void createDeadlineCommand_correctDeadline_createDeadlineInFile() {
String result = "";
sc = new Scanner(dataFile);
while (sc.hasNext()) {
result += sc.nextLine() + "\n";
result += sc.nextLine() + "\n";
}
Assertions.assertEquals(initial, result);

Expand All @@ -363,7 +359,7 @@ void createDeadlineCommand_correctDeadline_createDeadlineInFile() {
result = "";
sc = new Scanner(dataFile);
while (sc.hasNext()) {
result += sc.nextLine() + "\n";
result += sc.nextLine() + "\n";
}
Assertions.assertEquals(expectedTwo, result);

Expand Down Expand Up @@ -421,8 +417,8 @@ void createEventCommand_deadlineWithInvalidDate_throwsInvalidDateException() {
@Test
void createEventCommand_correctEvent_createEventInFile() {
String initial = "";
String expectedOne
= "Added the following event into the list:\n[E][ ] Event 1 (at: 03 May 2022 06:00 PM)";
String expectedOne =
"Added the following event into the list:\n[E][ ] Event 1 (at: 03 May 2022 06:00 PM)";
String expectedTwo = "EVENT\n"
+ "false\n"
+ "Event 1\n"
Expand All @@ -440,7 +436,7 @@ void createEventCommand_correctEvent_createEventInFile() {
String result = "";
sc = new Scanner(dataFile);
while (sc.hasNext()) {
result += sc.nextLine() + "\n";
result += sc.nextLine() + "\n";
}
Assertions.assertEquals(initial, result);

Expand All @@ -453,7 +449,7 @@ void createEventCommand_correctEvent_createEventInFile() {
result = "";
sc = new Scanner(dataFile);
while (sc.hasNext()) {
result += sc.nextLine() + "\n";
result += sc.nextLine() + "\n";
}
Assertions.assertEquals(expectedTwo, result);

Expand Down Expand Up @@ -518,7 +514,7 @@ void deleteCommand_correctDelete_deleteTaskInList() {
result = "";
sc = new Scanner(dataFile);
while (sc.hasNext()) {
result += sc.nextLine() + "\n";
result += sc.nextLine() + "\n";
}
Assertions.assertEquals(expectedTwo, result);

Expand Down

0 comments on commit 91a6712

Please sign in to comment.