Skip to content

Commit

Permalink
Complete A-JUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoukerrr committed Aug 23, 2021
1 parent 7a37e82 commit 14a83ae
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/main/java/duke/Deadline.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ public Deadline(String[] input) {
this.deadline = LocalDate.parse(input[3]);
}

public String getDate() {
return this.deadline.format(DateTimeFormatter.ofPattern("MMM d yyyy"));
}

@Override
public String toString() {
return "[D]" + super.toString() + "(by: "
+ this.deadline.format(DateTimeFormatter.ofPattern("MMM d yyyy" + ")"));
+ this.deadline.format(DateTimeFormatter.ofPattern("MMM d yyyy")) + ")";
}

@Override
Expand Down
1 change: 1 addition & 0 deletions src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

public class Duke {
public static List todoList;

public static void greet() {
String message = "Hello! I'm Duke\nWhat can I do for you?";
System.out.println(message);
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/duke/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import duke.Task;

public class Event extends Task {
String time;
private String time;

public Event(String name) throws DukeEventException {
super(name.substring(0, name.indexOf(" /at ") + 1));
Expand All @@ -19,6 +19,10 @@ public Event(String[] input) {
this.time = input[3];
}

public String getTime() {
return this.time;
}

@Override
public String toString() {
return "[E]" + super.toString() + "(at: " + this.time + ")";
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/duke/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public Task(String name, Boolean done) {
this.done = done;
}

public String getName() {
return this.name;
}

public void markAsDone() {
this.done = true;
}
Expand Down
48 changes: 48 additions & 0 deletions src/test/java/DukeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import duke.*;
import org.junit.jupiter.api.Test;

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

public class DukeTest {
@Test
public void TodoNormalTest(){
try {
Todo a = new Todo("a");
assertEquals("a", a.getName());
} catch (DukeTodoException e) {
assertEquals(null, e);
}
}

@Test
public void TodoExceptionTest(){
try {
Todo a = new Todo("");
assertEquals("", a.getName());
} catch (DukeTodoException e) {
assertEquals("OOPS!!! The description of a deadline cannot be empty.", e.getMessage());
}
}

@Test
public void EventNormalTest(){
try {
Event a = new Event("project meeting /at Mon 2-4pm");
assertEquals("project meeting ", a.getName());
assertEquals("Mon 2-4pm", a.getTime());
} catch (DukeEventException e) {
assertEquals(null, e);
}
}

@Test
public void DeadlineNormalTest(){
try {
Deadline a = new Deadline("return book /by 2019-10-15");
assertEquals("return book ", a.getName());
assertEquals("Oct 15 2019", a.getDate());
} catch (DukeDeadlineException e) {
assertEquals(null, e.getMessage());
}
}
}

0 comments on commit 14a83ae

Please sign in to comment.