forked from nus-cs2103-AY2021S1/ip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add JUnit tests for Parser and TaskList, edit exception throwing
- Loading branch information
1 parent
a12f533
commit 64ed090
Showing
16 changed files
with
243 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package duke; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class ParserTest { | ||
|
||
@Test | ||
public void parse_unknownCommand_exceptionThrown() { | ||
try { | ||
Parser.parse("unknown"); | ||
} catch (DukeException e) { | ||
assertEquals("Sorry, I don't understand what you just said.", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void parse_doneWithNoTaskIndex_exceptionThrown() { | ||
try { | ||
Parser.parse("done "); | ||
} catch (DukeException e) { | ||
assertEquals("Error! 'done' description cannot be empty.", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void parse_doneWithNonIntegerValue_exceptionThrown() { | ||
|
||
} | ||
|
||
@Test | ||
public void parse_todoWithNoDescription_exceptionThrown() { | ||
try { | ||
Parser.parse("todo "); | ||
} catch (DukeException e) { | ||
assertEquals("Error! 'todo' description cannot be empty.", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void parse_deadlineWithNoDescription_exceptionThrown() { | ||
try { | ||
Parser.parse("deadline "); | ||
} catch (DukeException e) { | ||
assertEquals("Error! 'deadline' description cannot be empty.", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void parse_deadlineWithNoTaskDescription_exceptionThrown() { | ||
try { | ||
Parser.parse("deadline /by 2020-12-12 1000"); | ||
} catch (DukeException e) { | ||
assertEquals("Error! No task description provided.", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void parse_deadlineWithNoDateTime_exceptionThrown() { | ||
try { | ||
Parser.parse("deadline this"); | ||
} catch (DukeException e) { | ||
assertEquals("Error! '/by' date not found.", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void parse_deadlineWithWrongDateTimeFormat_exceptionThrown() { | ||
try { | ||
Parser.parse("deadline this /by 2020/12/12 10:00"); | ||
} catch (DukeException e) { | ||
assertEquals("Error! Date/time is in the wrong format.", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void parse_deadlineWithInvalidDateTime_exceptionThrown() { | ||
try { | ||
Parser.parse("deadline this /by 2020-13-12 3300"); | ||
} catch (DukeException e) { | ||
assertEquals("Error! Date/time is invalid.", e.getMessage()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package duke; | ||
|
||
import duke.task.Task; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
public class TaskListTest { | ||
|
||
@Test | ||
public void listContents_emptyList_exceptionThrown() { | ||
try { | ||
TaskList tasks = new TaskList(); | ||
tasks.listContents(); | ||
} catch (DukeException e) { | ||
assertEquals("Your list is empty.", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void listContents_nonEmptyList_success() { | ||
try { | ||
ArrayList<Task> list = new ArrayList<>(); | ||
list.add(new ToDoStub("test")); | ||
TaskList tasks = new TaskList(list); | ||
String expected = "Here is your list:\n1.test"; | ||
assertEquals(tasks.listContents(), expected); | ||
} catch (DukeException e) { | ||
fail(); | ||
} | ||
} | ||
} |
Oops, something went wrong.