Skip to content

Commit

Permalink
Make basic JUnit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
markgcera committed Aug 29, 2023
1 parent af9bb9b commit 9d010a5
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 11 deletions.
9 changes: 5 additions & 4 deletions src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@ public static void main(String[] args) {

Storage.loadTasksFromFile(taskList);

Ui.printIntroMsg();
Ui ui = new Ui();
ui.printIntroMsg();

input = scanner.nextLine();

while (!input.equals("bye")) {
Ui.printSeparator();
ui.printSeparator();
Parser.parse(input, taskList);
Storage.updateTasksFile(taskList);
Ui.printSeparator();
ui.printSeparator();
input = scanner.nextLine();
}

scanner.close();
Ui.printOutroMsg();
ui.printOutroMsg();
}

}
15 changes: 11 additions & 4 deletions src/main/java/duke/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,17 @@ public static void markTask(String[] inputParts, ArrayList<Task> taskList, boole
}

public static void deleteTask(String[] inputParts, ArrayList<Task> taskList) {
int index = Integer.parseInt(inputParts[1]) - 1;
Task removedTask = taskList.remove(index);
System.out.println("Noted. I've removed this task:\n" + removedTask);
System.out.println("Now you have " + taskList.size() + " tasks in the list.");
try {
int index = Integer.parseInt(inputParts[1]) - 1;
if (index > taskList.size()) {
throw new DukeException("☹ OOPS!!! Unable to delete non-existent task");
}
Task removedTask = taskList.remove(index);
System.out.println("Noted. I've removed this task:\n" + removedTask);
System.out.println("Now you have " + taskList.size() + " tasks in the list.");
} catch (DukeException e) {
System.out.println(e);
}
}

public static void addTask(String[] inputParts, ArrayList<Task> taskList) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/duke/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ public class Ui {
+ "Bye. Hope to see you again soon!\n"
+ LINE_SEPARATOR;

public static void printIntroMsg() {
public void printIntroMsg() {
System.out.println(GREETING_MESSAGE);
}

public static void printOutroMsg() {
public void printOutroMsg() {
System.out.println(GOODBYE_MESSAGE);
}

public static void printSeparator() {
public void printSeparator() {
System.out.println(LINE_SEPARATOR);
}

Expand Down
13 changes: 13 additions & 0 deletions src/test/java/duke/DeadlineTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package duke;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class DeadlineTest {
@Test
public void deadlineTest() {
Deadline dl = new Deadline("test", "2019-10-15");
assertEquals("Oct 15 2019", dl.getBy());
}
}
13 changes: 13 additions & 0 deletions src/test/java/duke/EventTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package duke;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class EventTest {
@Test
public void eventTest() {
Event dl = new Event("test", "2019-10-15", "2019-10-16");
assertEquals("Oct 15 2019 to Oct 16 2019", dl.getFromTo());
}
}

0 comments on commit 9d010a5

Please sign in to comment.