Skip to content

Commit

Permalink
Add jUnit testing
Browse files Browse the repository at this point in the history
  • Loading branch information
simonteozw committed Aug 26, 2020
1 parent 89784c3 commit dfa7ebf
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ bin/
/text-ui-test/ACTUAL.txt
text-ui-test/EXPECTED-UNIX.TXT

/src/out

# Ignore all .class files
*.class
4 changes: 1 addition & 3 deletions src/main/java/Duke.java → src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package duke;
import java.util.Scanner;
import duke.TaskList;
import duke.Parser;
import duke.Ui;

public class Duke {
public static void main(String[] args) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/duke/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Storage {

public Storage() {}

private String allTasksCombined(ArrayList<Task> items) {
String allTasksCombined(ArrayList<Task> items) {
String res = "";
for (Task item : items) {
res += String.format("%s", item.saveString());
Expand All @@ -28,7 +28,7 @@ private String allTasksCombined(ArrayList<Task> items) {
return res;
}

private Task stringToTask(String str) throws InvalidTypeException, InvalidDataException {
Task stringToTask(String str) throws InvalidTypeException, InvalidDataException {
String[] info = str.split("\\|");
if (info.length < 3) {
throw new InvalidDataException();
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/duke/TaskList.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package duke;

import java.util.ArrayList;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

public class TaskList {
private final String line = "---------------------------------------------";
private ArrayList<Task> items;
private int total;
Storage storage;
Expand All @@ -16,7 +13,7 @@ public TaskList() {
this.items = storage.readData();
this.total = items.size();
}

public void bye() {
try {
storage.writeData(this.items);
Expand Down
48 changes: 48 additions & 0 deletions src/test/java/duke/DukeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package duke;

import org.junit.jupiter.api.Test;

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

public class DukeTest {

TaskList t = new TaskList();

Storage s = new Storage();

@Test
public void invalidCommandTest() {
try {
Parser.handleInput("example hello");
} catch (InvalidTypeException e) {
assertEquals("OOPS!!! I'm sorry, but I don't know what that means :-(",
e.getMessage());
} catch (InvalidDescriptionException e) {
assertEquals("OOPS!!! The description of a task cannot be empty",
e.getMessage());
}
}

@Test
public void invalidIndexTest() {
try {
t.completeTask(-1);
} catch (InvalidIndexException e) {
assertEquals("OOPS!!! The index you have chosen is out of bounds",
e.getMessage());
}
}

@Test
public void invalidDataTest() {
try {
s.stringToTask("example hello");
} catch (InvalidTypeException e) {
assertEquals("OOPS!!! I'm sorry, but I don't know what that means :-(",
e.getMessage());
} catch (InvalidDataException e) {
assertEquals("OOPS!!! The data here is invalid!",
e.getMessage());
}
}
}

0 comments on commit dfa7ebf

Please sign in to comment.