Skip to content

Commit

Permalink
Add JUnit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hansebastian committed Aug 24, 2020
1 parent 724956d commit bf5ab46
Show file tree
Hide file tree
Showing 32 changed files with 272 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/test/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/test/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/test/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions src/test/.idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/test/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

import duke.command.ByeCommand;
import duke.command.Command;
import duke.command.ListCommand;
import org.junit.jupiter.api.Test;

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

public class ParserTest {
@Test
public void parseCommand_unkownCommand_exceptionThrown() {
try {
Command c = Parser.parse("asd");
} catch (DukeException e) {
assertTrue(e.getMessage().contains("I'm sorry, but I don't know what that means :-("));
}
}

@Test
public void parseCommand_byeCommand_byeCommandObjectCreated() {
try {
Command c = Parser.parse("bye");
assertTrue(c instanceof ByeCommand);

} catch (DukeException e) {
System.out.println("Test failed");
}
}

@Test
public void parseCommand_listCommand_listCommandObjectCreated() {
try {
Command c = Parser.parse("list");
assertTrue(c instanceof ListCommand);

} catch (DukeException e) {
System.out.println("Test failed");
}
}

@Test
public void parseCommand_unspecifiedDoneCommand_exceptionThrown() {
try {
Command c = Parser.parse("done");
} catch (DukeException e) {
assertTrue(e.getMessage().contains("Please enter a valid task number for me to mark as done."));
}
}
}
13 changes: 13 additions & 0 deletions src/test/java/duke/command/ByeCommandTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package duke.command;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class ByeCommandTest {
@Test
public void isExitTrue_byeCommandCreated_true() {
Command test = new ByeCommand();
assertTrue(test.isExit());
}

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

import duke.DukeException;
import duke.Parser;
import duke.command.Command;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class DeadlineTest {
@Test
public void createDeadline_withoutDateTime_exceptionThrown() {
try {
Deadline d = new Deadline("submission", "");
} catch (DukeException e) {
assertTrue(e.getMessage().contains("Please input date and time in correct format"));
}
}

@Test
public void createDeadline_withoutInvalidDateTime_exceptionThrown() {
try {
Deadline d = new Deadline("submission", "2020/14/54 2810");
} catch (DukeException e) {
assertTrue(e.getMessage().contains("Please input date and time in correct format"));
}
}

@Test
public void createDeadline_withDateTime_deadlineCreated() {
try {
Deadline d = new Deadline("submission", "2020/11/14 15:30");
assertTrue(d instanceof Deadline);
} catch (DukeException e) {
System.out.println("Test failed");
}
}
}
18 changes: 18 additions & 0 deletions src/test/java/duke/task/ToDoTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package duke.task;

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

public class ToDoTest {
@Test
public void createTodo_withDescription_stringReturned() {
ToDo test = new ToDo("Walk Dog");
assertEquals("T | 0 | Walk Dog",test.toString());
}

@Test
public void createTodo_withOutDescription_stringReturned() {
ToDo test = new ToDo("");
assertEquals("T | 0 | ",test.toString());
}
}
Binary file added src/test/out/production/main/duke/Duke.class
Binary file not shown.
Binary file not shown.
Binary file added src/test/out/production/main/duke/Parser$1.class
Binary file not shown.
Binary file added src/test/out/production/main/duke/Parser.class
Binary file not shown.
Binary file added src/test/out/production/main/duke/Storage.class
Binary file not shown.
Binary file added src/test/out/production/main/duke/Ui.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added src/test/out/production/main/duke/task/Task.class
Binary file not shown.
Binary file not shown.
Binary file added src/test/out/production/main/duke/task/ToDo.class
Binary file not shown.
Binary file added src/test/out/test/test/duke/ParserTest.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added src/test/out/test/test/duke/task/ToDoTest.class
Binary file not shown.

0 comments on commit bf5ab46

Please sign in to comment.