Skip to content

Commit

Permalink
Add unit tests for Parser and TaskList
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiJie96 committed Aug 27, 2020
1 parent f5e3e48 commit 84d672b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/test/java/ParserTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import org.junit.jupiter.api.Test;

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

public class ParserTest {

@Test
public void parse_noDescription_exceptionThrown() {
try {
Parser.parse("event");
fail();
} catch (DukeException e) {
assertEquals(" OOPS!!! The description of a event cannot be empty.", e.getMessage());
}
}

@Test
public void parse_wrongCommand_exceptionThrown() {
try {
Parser.parse("random");
fail();
} catch (DukeException e) {
assertEquals(" OOPS!!! I'm sorry, but I don't know what that means :-(", e.getMessage());
}
}
}
19 changes: 19 additions & 0 deletions src/test/java/TaskListTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import org.junit.jupiter.api.Test;

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

public class TaskListTest {

@Test
public void handleDeadline_wrongDateFormat_exceptionThrown() {
try {
TaskList tasks = new TaskList();
CommandName deadline = CommandName.DEADLINE;
tasks.addTask(deadline, "desc", "2020/10/10");
fail();
} catch (DukeException e) {
assertEquals(" OOPS!!! Pass in a date in yyyy-mm-dd :-(", e.getMessage());
}
}
}

0 comments on commit 84d672b

Please sign in to comment.