Skip to content

Commit

Permalink
Update ParserTest.java to use the simple date format
Browse files Browse the repository at this point in the history
  • Loading branch information
lckjosh committed Oct 17, 2023
1 parent d349b11 commit 564051a
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/test/java/seedu/nuscents/parser/ParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}


Expand Down

0 comments on commit 564051a

Please sign in to comment.