Skip to content

Commit 0b4cc60

Browse files
committed
Add JUnit tests for Parser Class
Duke currently does not have tests for Parser Class. There is a high chance a bug may occur in the Parser class in the future, when new code is added. Implement JUnit tests to ensure that the Parser class still functions correctly after future changes. JUnit tests were chosen due to their convenience.
1 parent 957f56a commit 0b4cc60

11 files changed

Lines changed: 48 additions & 16 deletions

File tree

File renamed without changes.

src/main/java/main/java/Duke.java renamed to src/main/java/main/java/main/java/Duke.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public Duke() {
4242
System.out.println("What can I do for you?");
4343
}
4444

45-
public void process(String[] processedInput) {
45+
private void process(String[] processedInput) {
4646
this.ui.processCommand(processedInput, this.taskList);
4747
}
4848
}

src/main/java/main/java/DukeException.java renamed to src/main/java/main/java/main/java/DukeException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package main.java;
22

3-
class DukeException extends Exception {
3+
public class DukeException extends Exception {
44
private final String errorMessage;
55

66
public DukeException(String error) {

src/main/java/main/java/Event.java renamed to src/main/java/main/java/main/java/Event.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public Event(String eventInfo, boolean isDone, LocalDate date) {
1414
this.date = date;
1515
}
1616

17-
public String getDate() {
17+
protected String getDate() {
1818
return Task.printDate(this.date);
1919
}
2020

src/main/java/main/java/Parser.java renamed to src/main/java/main/java/main/java/Parser.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import java.time.format.DateTimeParseException;
55
import java.util.ArrayList;
66

7-
class Parser {
7+
public class Parser{
88

99
public String[] processCommand (String input) throws DukeException {
1010
String command = input.split(" ")[0];
@@ -25,7 +25,7 @@ public String[] processCommand (String input) throws DukeException {
2525
}
2626
}
2727

28-
public String[] processList(String input) throws DukeException {
28+
private String[] processList(String input) throws DukeException {
2929
String[] result = new String[1];
3030
String[] processedInput = input.split(" ");
3131
if (processedInput.length > 1) {
@@ -36,7 +36,7 @@ public String[] processList(String input) throws DukeException {
3636
return result;
3737
}
3838

39-
public String[] processDone(String input) throws DukeException {
39+
private String[] processDone(String input) throws DukeException {
4040
String[] result = new String[2];
4141
String[] processedInput = input.split(" ");
4242
if (processedInput.length == 1) {
@@ -54,7 +54,7 @@ public String[] processDone(String input) throws DukeException {
5454
}
5555
}
5656

57-
public String[] processDelete(String input) throws DukeException {
57+
private String[] processDelete(String input) throws DukeException {
5858
String[] result = new String[2];
5959
String[] processedInput = input.split(" ");
6060
if (processedInput.length == 1) {
@@ -72,7 +72,7 @@ public String[] processDelete(String input) throws DukeException {
7272
}
7373
}
7474

75-
public String[] processToDo(String input) throws DukeException {
75+
private String[] processToDo(String input) throws DukeException {
7676
String[] result = new String[2];
7777
String[] processedInput = input.split(" ");
7878
if (processedInput.length == 1) {
@@ -85,7 +85,7 @@ public String[] processToDo(String input) throws DukeException {
8585
return result;
8686
}
8787

88-
public String[] processDeadLine(String input) throws DukeException {
88+
private String[] processDeadLine(String input) throws DukeException {
8989
String[] result = new String[3];
9090
String[] processedInput = input.substring(9).split("/by");
9191
if (processedInput.length == 0) {
@@ -104,7 +104,7 @@ public String[] processDeadLine(String input) throws DukeException {
104104
}
105105
}
106106

107-
public String[] processEvent(String input) throws DukeException {
107+
private String[] processEvent(String input) throws DukeException {
108108
String[] result = new String[3];
109109
String[] processedInput = input.substring(6).split("/at");
110110
if (processedInput.length == 0) {
File renamed without changes.

src/main/java/main/java/Task.java renamed to src/main/java/main/java/main/java/Task.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public Task(String taskName, boolean isDone) {
1515
this.isDone = isDone;
1616
}
1717

18-
public void completeTask() {
18+
protected void completeTask() {
1919
this.isDone = true;
2020
}
2121

@@ -28,7 +28,7 @@ public static String printDate(LocalDate date) {
2828
" " + day + " " + year;
2929
}
3030

31-
public boolean isComplete() {
31+
protected boolean isComplete() {
3232
return this.isDone;
3333
}
3434
}

src/main/java/main/java/TaskList.java renamed to src/main/java/main/java/main/java/TaskList.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ public TaskList() {
2121
}
2222
}
2323

24-
public void listTask() {
24+
protected void listTask() {
2525
System.out.println("Here are the tasks in your list:");
2626
for (int i = 0; i < taskList.size(); i++) {
27-
Task currTask = taskList.get(i);
27+
main.java.Task currTask = taskList.get(i);
2828
System.out.println(i + 1 + "." + currTask);
2929
}
3030
}
3131

32-
public void doneTask(int index) throws DukeException {
32+
protected void doneTask(int index) throws DukeException {
3333
if (this.taskList.size() >= index) {
3434
Task currTask = this.taskList.get(index - 1);
3535
currTask.completeTask();
File renamed without changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
class Ui {
55

6-
public void processCommand(String[] input, TaskList taskList) {
6+
protected void processCommand(String[] input, TaskList taskList) {
77
try {
88
if (input[0].equals("list")) {
99
taskList.listTask();

0 commit comments

Comments
 (0)