Skip to content

Commit

Permalink
Update test cases for Task class
Browse files Browse the repository at this point in the history
  • Loading branch information
MAOXIONGKAI committed Sep 18, 2024
1 parent a8ad60a commit 3e4fb74
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions src/test/java/gopher/task/TaskTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gopher.task;

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

import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -111,4 +112,77 @@ public void toStringTest() {
assertEquals("[E][ ] Event 3 (from Aug 30 2024 00:00 to Sep 02 2024 00:00)",
event.toString());
}

@Test
public void update_validCommand_updateSuccess()
throws InvalidTokenException, InvalidDurationException {
Task todo = createTask("todo Event 1");
todo.update(new String[]{"update", "1", "Hello"});
assertEquals("[T][ ] Hello",
todo.toString());

Task deadline = createTask("deadline Event 2 /by 2024-08-30");
deadline.update(new String[]{"update", "2", "Goodbye World", "/by", "2025-01-01"});
assertEquals("[D][ ] Goodbye World (by Jan 01 2025 00:00)",
deadline.toString());

Task event = createTask("event Event 3 /from 2024-08-30 /to 2024-09-02");
event.update(new String[]{"update", "3", "Orbital Splashdown", "/from", "2024-01-01",
"/to", "2025-01-01"});
assertEquals("[E][ ] Orbital Splashdown (from Jan 01 2024 00:00 to Jan 01 2025 00:00)",
event.toString());
}

@Test
public void of_unknownCommand_exceptionThrown() {
assertThrows(UnknownCommandException.class, () -> {
Task.of("hello");
});
}

@Test
public void of_emptyDescription_exceptionThrown() {
assertThrows(EmptyTaskDescriptionException.class, () -> {
Task.of("todo");
});
}

@Test
public void of_missingByTokenWhenCreatingDeadline_exceptionThrown() {
assertThrows(MissingTokenException.class, () -> {
Task.of("deadline Goodbye World 2024-09-11");
});
}

@Test
public void of_invalidDurationForEventTask_exceptionThrown() {
assertThrows(InvalidDurationException.class, () -> {
Task.of("event hello /from 2024-01-01 /to 2023-01-01");
});
}

@Test
public void of_fromTokenUsedToCreateDeadline_exceptionThrown() {
assertThrows(InvalidTokenException.class, () -> {
Task.of("deadline hello /from 2024-01-01");
});
}

@Test
public void update_byTokenUsedToUpdateEvent_exceptionThrown() {
Task event = createTask("event hello /from 2020-01-01 /to 2021-01-01");
assertThrows(InvalidTokenException.class, () -> {
String[] tokens = new String[]{"update", "4", "/by", "2024-09-11"};
event.update(tokens);
});
}

@Test
public void update_invalidDuration_exceptionThrown() {
Task event = createTask("event hello /from 2020-01-01 /to 2021-01-01");
assertThrows(InvalidDurationException.class, () -> {
String[] tokens = new String[]{"update", "4", "/from", "2024-01-01"};
event.update(tokens);
});
}
}

0 comments on commit 3e4fb74

Please sign in to comment.