Skip to content

Commit

Permalink
Finished JUnit Testing
Browse files Browse the repository at this point in the history
  • Loading branch information
loose-bus-change committed Aug 29, 2021
1 parent ae519f8 commit 86b9868
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/main/java/duke/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

public class Ui {
Scanner scan;
private String str;
private static TaskList listOfTasks;
private static Storage storage;

Expand All @@ -13,6 +14,10 @@ public Ui(TaskList t, Storage s) {
this.storage = s;
}

public Ui() {
str = "There has been a loading error";
}

public String input() {
if (scan.hasNextLine()) {
String str = scan.nextLine();
Expand All @@ -22,6 +27,6 @@ public String input() {
}

public String showLoadingError() {
return "There has been a loading error";
return this.str;
}
}
30 changes: 30 additions & 0 deletions src/test/java/duke/TaskListTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import duke.TaskList;
import duke.Task;
import org.junit.Test;

import java.time.LocalDate;

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


public class TaskListTest {
@Test
public void confirmTaskAdded() {
TaskList temp = new TaskList("./test/junit.txt");
LocalDate d = LocalDate.parse("2015-10-20");
String desc = "read a book";
temp.addDeadline(desc, d);
Task task = temp.get(0);
assertEquals("[D][ ] read a book by: 2015-10-20", task.toString());
}

@Test
public void checkNumberOfTasks() {
TaskList temp = new TaskList("./test/junit.txt");
LocalDate d1 = LocalDate.parse("2015-10-20");
for (int i = 0; i < 10; i++) {
temp.addDeadline("read a book", d1);
}
assertEquals(10 , temp.size());
}
}
12 changes: 12 additions & 0 deletions src/test/java/duke/UiTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import duke.Ui;
import org.junit.Test;

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

public class UiTest {
@Test
public void showErrorTest() {
Ui u = new Ui();
assertEquals("There has been a loading error", u.showLoadingError());
}
}

0 comments on commit 86b9868

Please sign in to comment.