forked from nus-cs2113-AY2324S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from lckjosh/branch-add-transaction-test
Add JUnit testing for adding a transaction
- Loading branch information
Showing
4 changed files
with
97 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package seedu.nuscents.parser; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import seedu.nuscents.data.Allowance; | ||
import seedu.nuscents.data.Expense; | ||
import seedu.nuscents.data.exception.NuscentsException; | ||
|
||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
public class ParserTest { | ||
|
||
@Test | ||
public void parseAllowance_validInput_success() throws NuscentsException, ParseException { | ||
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()); | ||
} | ||
|
||
@Test | ||
public void parseExpense_validInput_success() throws NuscentsException, ParseException { | ||
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()); | ||
} | ||
|
||
|
||
@Test | ||
public void parseAllowance_missingArguments_exceptionThrown() { | ||
String input = "allowance /amt 100 /desc Pocket Money"; | ||
Exception exception = assertThrows(NuscentsException.class, () -> { | ||
Parser.parseCommand(input, null); | ||
}); | ||
assertEquals("OOPS!!! Invalid input format for adding an allowance.", exception.getMessage()); | ||
} | ||
|
||
@Test | ||
public void parseExpense_missingArguments_exceptionThrown() { | ||
String input = "expense /amt 50 /desc Dinner"; | ||
Exception exception = assertThrows(NuscentsException.class, () -> { | ||
Parser.parseCommand(input, null); | ||
}); | ||
assertEquals("OOPS!!! Invalid input format for adding an expense.", exception.getMessage()); | ||
} | ||
|
||
@Test | ||
public void parseAllowance_invalidDateTime_exceptionThrown() { | ||
String input = "allowance /amt 100 /date 15/10/2023 /desc Lunch"; | ||
Exception exception = assertThrows(NuscentsException.class, () -> { | ||
Parser.parseCommand(input, null); | ||
}); | ||
assertEquals("OOPS!!! The format of the date is invalid.", exception.getMessage()); | ||
} | ||
|
||
@Test | ||
public void parseExpense_invalidDateTime_exceptionThrown() { | ||
String input = "expense /amt 50 /date 16.10.2023 /desc Dinner"; | ||
Exception exception = assertThrows(NuscentsException.class, () -> { | ||
Parser.parseCommand(input, null); | ||
}); | ||
assertEquals("OOPS!!! The format of the date is invalid.", exception.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