Skip to content

Commit

Permalink
Add testing for parser
Browse files Browse the repository at this point in the history
  • Loading branch information
guanquann committed Mar 13, 2024
1 parent 3239db7 commit 0de5dc5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package seedu.address.logic.parser;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_AMY;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE;
Expand All @@ -11,6 +12,7 @@
import org.junit.jupiter.api.Test;

import seedu.address.logic.commands.AddOrderCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.order.Date;

public class AddOrderCommandParserTest {
Expand Down Expand Up @@ -48,6 +50,7 @@ public void parse_missingParts_failure() {
public void parse_invalidPreamble_failure() {
// negative index
assertParseFailure(parser, "-5" + NAME_DESC_AMY, MESSAGE_INVALID_FORMAT);
assertThrows(ParseException.class, () -> parser.parse("1"));

// zero index
assertParseFailure(parser, "0" + NAME_DESC_AMY, MESSAGE_INVALID_FORMAT);
Expand Down
20 changes: 20 additions & 0 deletions src/test/java/seedu/address/logic/parser/ParserUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,24 @@ public void parseTags_collectionWithValidTags_returnsTagSet() throws Exception {

assertEquals(expectedTagSet, actualTagSet);
}

@Test
public void parseDate_null_throwsNullPointerException() {
assertThrows(NullPointerException.class, () -> ParserUtil.parseDate(null));
}

@Test
public void parseDate_invalidValue_throwsParseException() {
assertThrows(ParseException.class, () -> ParserUtil.parseDate("2020-13-01"));
}

@Test
public void parseDate_validValueWithoutWhitespace_returnsDate() throws Exception {
assertEquals(ParserUtil.parseDate("2020-01-01").toString(), "2020-01-01");
}

@Test
public void parseDate_validValueWithWhitespace_returnsTrimmedDate() throws Exception {
assertEquals(ParserUtil.parseDate(WHITESPACE + "2020-01-01" + WHITESPACE).toString(), "2020-01-01");
}
}

0 comments on commit 0de5dc5

Please sign in to comment.