Skip to content

Commit

Permalink
Add JUnit tests to test behavior of the code
Browse files Browse the repository at this point in the history
  • Loading branch information
ongwenpin committed Aug 25, 2022
1 parent 81a9f1d commit 8f63a0f
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/main/java/duke/task/Deadline.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public Deadline(String description, LocalDate deadlineDate, LocalTime deadlineTi
@Override
public String TaskInfo() {
if (deadlineTime == null) {
return "[D] [" + getStatusIcon() + "] " + description + "(by:" +
return "[D] [" + getStatusIcon() + "] " + description + " (by:" +
deadlineDate.format(DateTimeFormatter.ofPattern("MMM dd yyyy")) +")";
} else {
return "[D] [" + getStatusIcon() + "] " + description + "(by:" +
return "[D] [" + getStatusIcon() + "] " + description + " (by:" +
deadlineDate.format(DateTimeFormatter.ofPattern("MMM dd yyyy")) + " " + deadlineTime +")";
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duke/task/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public Event(String description, String duration) {

@Override
public String TaskInfo() {
return "[E] [" + getStatusIcon() + "] " + description + "(at:" + duration + ")";
return "[E] [" + getStatusIcon() + "] " + description + " (at:" + duration + ")";
}

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


import duke.task.Deadline;

import org.junit.jupiter.api.Test;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

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

public class DeadlineTest {

@Test
public void toDoDeadline() {
Deadline testDeadline = new Deadline("Return book",
LocalDate.parse("2022-08-25", DateTimeFormatter.ofPattern("yyyy-MM-dd")), null);
assertEquals(testDeadline.TaskInfo(), "[D] [ ] Return book (by:Aug 25 2022)");
}


}
18 changes: 18 additions & 0 deletions src/test/java/duke/EventTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package duke;

import duke.task.Event;

import org.junit.jupiter.api.Test;

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

public class EventTest {

@Test
public void testEvent() {
Event testEvent = new Event("project meeting", "Mon 2-4pm");
assertEquals(testEvent.TaskInfo(), "[E] [ ] project meeting (at:Mon 2-4pm)");
}


}
18 changes: 18 additions & 0 deletions src/test/java/duke/ToDoTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package duke;

import duke.task.Task;

import duke.task.ToDo;
import org.junit.jupiter.api.Test;

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

public class ToDoTest {

@Test
public void toDoTest() {
Task testTask = new ToDo("Read book");
assertEquals(testTask.TaskInfo(), "[T] [ ] Read book");
}

}

0 comments on commit 8f63a0f

Please sign in to comment.