diff --git a/src/test/java/seedu/nuscents/parser/ParserTest.java b/src/test/java/seedu/nuscents/parser/ParserTest.java index c992e84855..cca3b143fe 100644 --- a/src/test/java/seedu/nuscents/parser/ParserTest.java +++ b/src/test/java/seedu/nuscents/parser/ParserTest.java @@ -6,8 +6,10 @@ import seedu.nuscents.data.exception.NuscentsException; import java.text.ParseException; +import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +import java.util.Date; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -16,26 +18,26 @@ public class ParserTest { @Test public void parseAllowance_validInput_success() throws NuscentsException, ParseException { - String arguments = "/amt 100 /date 15-10-2023 1500 /desc Birthday Gift /note From friends"; + String arguments = "/amt 100 /date 15-10-2023 /desc Birthday Gift /note From friends"; Allowance allowance = Parser.parseAllowance(arguments); assertEquals("100", allowance.getAmount()); + SimpleDateFormat formatter = new SimpleDateFormat("d-M-yyyy"); + String formattedDate = formatter.format(allowance.getDate()); + assertEquals("15-10-2023", formattedDate); assertEquals("Birthday Gift", allowance.getDescription()); assertEquals("From friends", allowance.getAdditionalInfo()); - LocalDateTime expectedDate = LocalDateTime.parse("15-10-2023 1500", - DateTimeFormatter.ofPattern("d-M-yyyy HHmm")); - assertEquals(expectedDate, allowance.getDate()); } @Test public void parseExpense_validInput_success() throws NuscentsException, ParseException { - String arguments = "/amt 50 /date 16-10-2023 1700 /desc Dinner /note Alone"; + String arguments = "/amt 50 /date 16-10-2023 /desc Dinner /note Alone"; Expense expense = Parser.parseExpense(arguments); assertEquals("50", expense.getAmount()); + SimpleDateFormat formatter = new SimpleDateFormat("d-M-yyyy"); + String formattedDate = formatter.format(expense.getDate()); + assertEquals("16-10-2023", formattedDate); assertEquals("Dinner", expense.getDescription()); assertEquals("Alone", expense.getAdditionalInfo()); - LocalDateTime expectedDate = LocalDateTime.parse("16-10-2023 1700", - DateTimeFormatter.ofPattern("d-M-yyyy HHmm")); - assertEquals(expectedDate, expense.getDate()); }