From dfa0814e8b72b8e3ffda566f7c388d8573d27914 Mon Sep 17 00:00:00 2001 From: aliciamichellew Date: Thu, 31 Aug 2023 23:34:26 +0800 Subject: [PATCH] Add JUnit test case --- .../java/kevin/parser/FileParserTest.java | 52 +++++++++++++++++++ src/test/java/kevin/parser/ParserTest.java | 52 +++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 src/test/java/kevin/parser/FileParserTest.java create mode 100644 src/test/java/kevin/parser/ParserTest.java diff --git a/src/test/java/kevin/parser/FileParserTest.java b/src/test/java/kevin/parser/FileParserTest.java new file mode 100644 index 0000000000..cea56e562a --- /dev/null +++ b/src/test/java/kevin/parser/FileParserTest.java @@ -0,0 +1,52 @@ +package kevin.parser; + +import kevin.exception.KevinException; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class FileParserTest { + @Test + public void parseLine_invalidCommand_exceptionThrown() { + String input = "invalidCommand"; + try { + FileParser fileParser = new FileParser(); + fileParser.parseLine(input); + } catch (Exception ex) { + assertTrue(ex instanceof KevinException); + } + } + + @Test + public void parseLine_invalidToDoInput_exceptionThrown() { + String input = "Todo - "; + try { + FileParser fileParser = new FileParser(); + fileParser.parseLine(input); + } catch (Exception ex) { + assertTrue(ex instanceof KevinException); + } + } + + @Test + public void parseLine_invalidDeadlineInput_exceptionThrown() { + String input = "Deadline - cs2103 - today"; + try { + FileParser fileParser = new FileParser(); + fileParser.parseLine(input); + } catch (Exception ex) { + assertTrue(ex instanceof KevinException); + } + } + + @Test + public void parseLine_invalidEventInput_exceptionThrown() { + String input = "Event - lecture - 2pm"; + try { + FileParser fileParser = new FileParser(); + fileParser.parseLine(input); + } catch (Exception ex) { + assertTrue(ex instanceof KevinException); + } + } +} diff --git a/src/test/java/kevin/parser/ParserTest.java b/src/test/java/kevin/parser/ParserTest.java new file mode 100644 index 0000000000..4775f04ed4 --- /dev/null +++ b/src/test/java/kevin/parser/ParserTest.java @@ -0,0 +1,52 @@ +package kevin.parser; + +import kevin.exception.KevinException; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class ParserTest { + @Test + public void prepareArguments_invalidCommand_exceptionThrown() { + String input = "invalidCommand"; + try { + Parser parser = new Parser(); + parser.prepareArguments(input); + } catch (Exception ex) { + assertTrue(ex instanceof KevinException); + } + } + + @Test + public void prepareArguments_invalidToDoInput_exceptionThrown() { + String input = "todo "; + try { + Parser parser = new Parser(); + parser.prepareArguments(input); + } catch (Exception ex) { + assertTrue(ex instanceof KevinException); + } + } + + @Test + public void prepareArguments_invalidDeadlineInput_exceptionThrown() { + String input = "deadline cs2103 by today"; + try { + Parser parser = new Parser(); + parser.prepareArguments(input); + } catch (Exception ex) { + assertTrue(ex instanceof KevinException); + } + } + + @Test + public void prepareArguments_invalidEventInput_exceptionThrown() { + String input = "event lecture /from 2pm"; + try { + Parser parser = new Parser(); + parser.prepareArguments(input); + } catch (Exception ex) { + assertTrue(ex instanceof KevinException); + } + } +}