Skip to content

Commit

Permalink
Add JUnit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
esmanda3w committed Aug 27, 2020
1 parent 6b0706f commit c9edfa4
Show file tree
Hide file tree
Showing 4 changed files with 196 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/test/java/DeadlineTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import org.junit.jupiter.api.Test;

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

public class DeadlineTest {
@Test
public void testDeadlinePrinting_correctFormat_success() throws DukeException {
Task d = new Deadline("proj", "2019-10-15 2359");
assertEquals("[D][\u2718] proj (by: Tue, 15 Oct 2019, 23:59)", d.toString());
}

@Test
public void testDeadlinePrinting_wrongFormat_exceptionThrown() {
try {
Task d = new Deadline("project", "Sunday");
fail();
} catch (DukeException ex) {
String error = "UHOH! You need to use the proper format!\n"
+ "eg deadline return book /by 2019-10-15 2359";
assertEquals(error, ex.getMessage());
}
}

@Test
public void testDeadlinePrinting_doneDeadline_success() throws DukeException {
Task d = new Deadline("proj", "2019-10-15 2359");
d.markDone();
assertEquals("[D][\u2713] proj (by: Tue, 15 Oct 2019, 23:59)", d.toString());
}

@Test
public void testToTaskData_doneDeadline_success() throws DukeException {
Task d = new Deadline("proj", "2019-10-15 2359");
d.markDone();
assertEquals("D ; 1 ; proj ; 2019-10-15 2359", d.toTaskData());
}

@Test
public void testToTaskData_notDoneDeadline_success() throws DukeException {
Task d = new Deadline("proj", "2019-10-15 2359");
assertEquals("D ; 0 ; proj ; 2019-10-15 2359", d.toTaskData());
}

}
44 changes: 44 additions & 0 deletions src/test/java/EventTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import org.junit.jupiter.api.Test;

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

public class EventTest {
@Test
public void testEventPrinting_correctFormat_success() throws DukeException {
Task e = new Event("meeting", "2019-10-15 1200");
assertEquals("[E][\u2718] meeting (at: Tue, 15 Oct 2019, 12:00)", e.toString());
}

@Test
public void testEventPrinting_wrongFormat_exceptionThrown() {
try {
Task e = new Event("meeting", "Sunday");
fail();
} catch (DukeException ex) {
String error = "UHOH! You need to use the proper format!\n"
+ "eg event project meeting /at 2019-10-15 1200";
assertEquals(error, ex.getMessage());
}
}

@Test
public void testEventPrinting_doneEvent_success() throws DukeException {
Task e = new Event("meeting", "2019-10-15 1200");
e.markDone();
assertEquals("[E][\u2713] meeting (at: Tue, 15 Oct 2019, 12:00)", e.toString());
}

@Test
public void testToTaskData_doneEvent_success() throws DukeException {
Task e = new Event("meeting", "2019-10-15 1200");
e.markDone();
assertEquals("E ; 1 ; meeting ; 2019-10-15 1200", e.toTaskData());
}

@Test
public void testToTaskData_notDoneDeadline_success() throws DukeException {
Task e = new Event("meeting", "2019-10-15 1200");
assertEquals("E ; 0 ; meeting ; 2019-10-15 1200", e.toTaskData());
}
}
76 changes: 76 additions & 0 deletions src/test/java/ParserTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
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_exitCommand_success() throws DukeException {
assertEquals(true, Parser.parse("bye") instanceof ExitCommand);
}

@Test
public void parse_helpCommand_success() throws DukeException {
assertEquals(true, Parser.parse("help") instanceof HelpCommand);
}

@Test
public void parse_listCommand_success() throws DukeException {
assertEquals(true, Parser.parse("list") instanceof ListCommand);
}

@Test
public void parse_doneCommand_success() throws DukeException {
assertEquals(true, Parser.parse("done 1") instanceof DoneCommand);
}

@Test
public void parse_doneCommand_exceptionThrown() {
try {
Parser.parse("done");
fail();
} catch (DukeException ex) {
String error = "UHOH! You need to specify which task to mark done! \n"
+ "eg done 1";
assertEquals(error, ex.getMessage());
}
}

@Test
public void parse_deleteCommand_success() throws DukeException {
assertEquals(true, Parser.parse("delete 1") instanceof DeleteCommand);
}

@Test
public void parse_deleteCommand_exceptionThrown() {
try {
Parser.parse("delete");
fail();
} catch (DukeException ex) {
String error = "UHOH! You need to specify which task to delete!\n"
+ "eg delete 1";
assertEquals(error, ex.getMessage());
}
}

@Test
public void parse_addCommand_success() throws DukeException {
assertEquals(true, Parser.parse("todo read") instanceof AddCommand);
assertEquals(true,
Parser.parse("deadline project /by 2019-10-15 2359") instanceof AddCommand);
assertEquals(true,
Parser.parse("event meeting /at 2019-10-15 1200") instanceof AddCommand);
}

@Test
public void parse_unknownCommand_exceptionThrown() {
try {
Parser.parse("hello");
fail();
} catch (DukeException ex) {
String error = "UHOH! Sorry, I don't understand what you are saying! D=\n"
+ "Type \"help\" to view the list of commands you can use!";
assertEquals(error, ex.getMessage());
}
}
}
31 changes: 31 additions & 0 deletions src/test/java/TodoTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import org.junit.jupiter.api.Test;

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

public class TodoTest {
@Test
public void testTodoPrinting_doneTodo_success() {
Task todo = new Todo("read");
todo.markDone();
assertEquals("[T][\u2713] read", todo.toString());
}

@Test
public void testTodoPrinting_notDoneTodo_success() {
Task todo = new Todo("read");
assertEquals("[T][\u2718] read", todo.toString());
}

@Test
public void testToTaskData_doneTodo_success() {
Task todo = new Todo("read");
todo.markDone();
assertEquals("T ; 1 ; read", todo.toTaskData());
}

@Test
public void testToTaskData_notDoneTodo_success() {
Task todo = new Todo("read");
assertEquals("T ; 0 ; read", todo.toTaskData());
}
}

0 comments on commit c9edfa4

Please sign in to comment.