diff --git a/docs/UserGuide.md b/docs/UserGuide.md index 9bfdc512de..477cfcae20 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -28,18 +28,19 @@ command to run the application. 11. Check Splitted Expenses 12. Settle Splitted Expenses 13. Find Expense -14. Add Recurring Bill -15. List Recurring Bills -16. Remove Recurring Bill -17. Add Expense to a Recurring Bill -18. View Expenses in a Recurring Bill -19. Add Expenses in a Recurring Bill to Overall Expenses -20. Change Currency -21. Set Budget -22. Get Budget -23. Print Budget -24. Get Graphical Insights for expenses -25. Get Graphical Insights for savings +14. Recurring Bill Description +15. Add Recurring Bill +16. List Recurring Bills +17. Remove Recurring Bill +18. Add Expense to a Recurring Bill +19. View Expenses in a Recurring Bill +20. Add Expenses in a Recurring Bill to Overall Expenses +21. Change Currency +22. Set Budget +23. Get Budget +24. Print Budget +25. Get Graphical Insights for expenses +26. Get Graphical Insights for savings ### Display Commands : `menu` Displays the corresponding features of BudgetBuddy @@ -272,6 +273,17 @@ Examples of usage : `find expenses d/coffee morethan/200 lessthan/ ` : Finds all expenses with the word "coffee" and amount higher than $200 `find expenses d/coffee morethan/200 lessthan/400 ` : Finds all expenses with the word "coffee" and amount higher than $200, but lesser than $400 +### Recurring Bill Description +The next few features in the user guide would be related to the Recurring Bill Feature. The commands associated to +this overall feature would start with the `rec` command, followed by the relevant `commandType` and parameters. This +feature allows user to create and manage multiple lists of expenses **separate** from the user's overall expenses +, which can be added to the users overall expenses. + +The term **recurring** here is to indicate that a user is able to **add** a set of pre-defined expenses to their +overall expenses at any given point in time. Hence, this could range from subscription payments, a future grocery list, +etc. + + ### Add Recurring Bill : `rec newlist` Adds a new recurring Bill. @@ -295,6 +307,7 @@ Format : `rec viewlists` * This command is **space sensitive**, in particular, the space between `rec` and `viewlists` must be **exactly** one space apart for the command to be recognised +* **Note** Anything typed after `rec viewlists` will be ignored. Examples of Output : @@ -313,7 +326,7 @@ Removes a recurring bill Format : `rec removelist LISTNUMBER` * `LISTNUMBER` refers to the associated list number of recurring bill when doing a `rec viewlists` -* `LISTNUMBER` must be a **valid** integer, and should be a **valid** list number +* `LISTNUMBER` must be a **valid** integer > 0, and should be a **valid** list number Examples of usage : @@ -330,7 +343,10 @@ Format : `rec newexpense to/LISTNUMBER c/CATEGORY a/AMOUNT d/DESCRIPTION` * `AMOUNT` refers to the amount value of the expense you wish to add * `DESCRIPTION` refers to the description of the expense you wish to add * `LISTNUMBER` must be a **valid** integer, and should be a **valid** list number -* `CATEGORY`, `AMOUNT` and `DESCRIPTION` follows the same constraints as if you were to add a normal expense +* `CATEGORY`, `AMOUNT` and `DESCRIPTION` follows the same constraints as if you were to add a normal expense. +* `to/, c/, a/, d/` must be placed in the **right order** +* **Note** Although the user is able to combine the prefixes without any spaces, etc. +`rec newexpense to/1c/Entertainmenta/200d/movies`, it is strongly recommended to ensure spaces for clarity. Examples of usage : `rec newexpense to/1 c/Entertainment a/200 d/movies` : Adds a new expense to the 1st recurring bill diff --git a/src/main/java/seedu/budgetbuddy/BudgetBuddy.java b/src/main/java/seedu/budgetbuddy/BudgetBuddy.java index 82c30d4783..30ca65b9ae 100644 --- a/src/main/java/seedu/budgetbuddy/BudgetBuddy.java +++ b/src/main/java/seedu/budgetbuddy/BudgetBuddy.java @@ -2,7 +2,7 @@ import seedu.budgetbuddy.command.Command; import seedu.budgetbuddy.commons.ExpenseList; -import seedu.budgetbuddy.commons.RecurringExpensesList; +import seedu.budgetbuddy.commons.RecurringExpenseLists; import seedu.budgetbuddy.commons.SavingList; import seedu.budgetbuddy.commons.SplitExpenseList; import seedu.budgetbuddy.exception.InvalidRecurringExpensesFileException; @@ -17,7 +17,7 @@ public class BudgetBuddy { private ExpenseList expenses; private SavingList savings; private SplitExpenseList splitexpenses; - private RecurringExpensesList expensesList; + private RecurringExpenseLists recurringExpenseLists; private Storage expensesStorage; private Storage savingsStorage; private Storage recurringExpensesStorage; @@ -30,7 +30,7 @@ public BudgetBuddy() { parser = new Parser(); expenses = new ExpenseList(); savings = new SavingList(); - expensesList = new RecurringExpensesList(); + recurringExpenseLists = new RecurringExpenseLists(); splitexpenses = new SplitExpenseList(); expensesStorage = new Storage("./data/ExpenseFile.txt"); savingsStorage = new Storage("./data/SavingsFile.txt"); @@ -40,7 +40,7 @@ public BudgetBuddy() { } public void handleCommands(String input) { - Command command = parser.parseCommand(expenses, savings, splitexpenses, expensesList, input); + Command command = parser.parseCommand(expenses, savings, splitexpenses, recurringExpenseLists, input); if (command != null) { @@ -52,7 +52,8 @@ public void handleCommands(String input) { try { expensesStorage.saveExpenses(expenses.getExpenses()); savingsStorage.saveSavings(savings.getSavings()); - recurringExpensesStorage.saveRecurringExpenses(expensesList); + recurringExpensesStorage.saveRecurringExpenses(recurringExpenseLists); + defaultCurrency.saveCurrency(); } catch (IOException e) { System.out.println("Error saving to file."); @@ -70,7 +71,7 @@ public void run() { defaultCurrency.loadCurrency(); this.expenses.getExpenses().addAll(expensesStorage.loadExpenses()); this.savings.getSavings().addAll(savingsStorage.loadSavings()); - this.expensesList = recurringExpensesStorage.loadRecurringExpensesList(); + this.recurringExpenseLists = recurringExpensesStorage.loadRecurringExpensesList(); } catch (FileNotFoundException e) { diff --git a/src/main/java/seedu/budgetbuddy/Parser.java b/src/main/java/seedu/budgetbuddy/Parser.java index 7a96d1d9d7..f009f63c06 100644 --- a/src/main/java/seedu/budgetbuddy/Parser.java +++ b/src/main/java/seedu/budgetbuddy/Parser.java @@ -23,7 +23,7 @@ import seedu.budgetbuddy.commandcreator.GetBudgetCommandCreator; import seedu.budgetbuddy.commons.SavingList; import seedu.budgetbuddy.commons.ExpenseList; -import seedu.budgetbuddy.commons.RecurringExpensesList; +import seedu.budgetbuddy.commons.RecurringExpenseLists; import seedu.budgetbuddy.commons.SplitExpenseList; import seedu.budgetbuddy.commons.CurrencyConverter; @@ -175,7 +175,7 @@ public Boolean isGetSavingsInsightsCommand(String input) { * input is invalid. */ public Command parseCommand(ExpenseList expenses, SavingList savings, SplitExpenseList - splitexpenses, RecurringExpensesList expensesList, String input) { + splitexpenses, RecurringExpenseLists expensesList, String input) { if(isMenuCommand(input)) { LOGGER.log(Level.INFO, "Confirmed that input is a menu command"); diff --git a/src/main/java/seedu/budgetbuddy/Storage.java b/src/main/java/seedu/budgetbuddy/Storage.java index 903cd922c5..36b90fff73 100644 --- a/src/main/java/seedu/budgetbuddy/Storage.java +++ b/src/main/java/seedu/budgetbuddy/Storage.java @@ -4,7 +4,7 @@ import seedu.budgetbuddy.commons.SplitExpense; import seedu.budgetbuddy.commons.ExpenseList; import seedu.budgetbuddy.commons.Expense; -import seedu.budgetbuddy.commons.RecurringExpensesList; +import seedu.budgetbuddy.commons.RecurringExpenseLists; import seedu.budgetbuddy.commons.RecurringExpenseList; import seedu.budgetbuddy.commons.DefaultCurrency; @@ -82,7 +82,7 @@ public void parseRecurringExpensesFile(ArrayList recurringExpenses, int indexOfStartOfListName = indexOfStartExclamation + 3; int indexOfEndExclamation = line.indexOf("!!!", 4); - int indexOfEndOfListName = indexOfEndExclamation - 1; + int indexOfEndOfListName = indexOfEndExclamation; String name = line.substring(indexOfStartOfListName, indexOfEndOfListName).trim(); ExpenseList expenses = new RecurringExpenseList(name, new ArrayList<>()); @@ -109,7 +109,7 @@ public void parseRecurringExpensesFile(ArrayList recurringExpenses, } } - public RecurringExpensesList loadRecurringExpensesList() throws IOException{ + public RecurringExpenseLists loadRecurringExpensesList() throws IOException{ File file = new File(filePath); ArrayList recurringExpenses = new ArrayList<>(); @@ -126,30 +126,30 @@ public RecurringExpensesList loadRecurringExpensesList() throws IOException{ scanner.close(); - RecurringExpensesList recurringExpensesList = new RecurringExpensesList(recurringExpenses); - return recurringExpensesList; + RecurringExpenseLists recurringExpenseLists = new RecurringExpenseLists(recurringExpenses); + return recurringExpenseLists; } catch (Exception e) { LOGGER.log(Level.INFO, "Exception successfully caught. Error has been handled"); System.out.println(e.getMessage()); System.out.println("You Recurring Expenses File is corrupted, resetting the file...."); resetRecurringExpensesListFile(); - return new RecurringExpensesList(); + return new RecurringExpenseLists(); } } - public void saveRecurringExpenses(RecurringExpensesList recurringExpensesList) + public void saveRecurringExpenses(RecurringExpenseLists recurringExpenseLists) throws InvalidRecurringExpensesFileException, IOException { ensureDirectoryExists(); try { FileWriter writer = new FileWriter(filePath, false); - int numberOfRecurringExpenseList = recurringExpensesList.getSize(); + int numberOfRecurringExpenseList = recurringExpenseLists.getSize(); for (int i = 0; i < numberOfRecurringExpenseList; i++) { int listNumber = i + 1; - ExpenseList expenseList = recurringExpensesList.getExpenseListAtListNumber(listNumber); + ExpenseList expenseList = recurringExpenseLists.getExpenseListAtListNumber(listNumber); ArrayList expenses = expenseList.getExpenses(); String listName = expenseList.getName(); diff --git a/src/main/java/seedu/budgetbuddy/command/ChangeCurrencyCommand.java b/src/main/java/seedu/budgetbuddy/command/ChangeCurrencyCommand.java index 76b0a9465d..d422447360 100644 --- a/src/main/java/seedu/budgetbuddy/command/ChangeCurrencyCommand.java +++ b/src/main/java/seedu/budgetbuddy/command/ChangeCurrencyCommand.java @@ -4,7 +4,7 @@ import seedu.budgetbuddy.commons.DefaultCurrency; import seedu.budgetbuddy.commons.ExpenseList; import seedu.budgetbuddy.commons.SavingList; -import seedu.budgetbuddy.commons.RecurringExpensesList; +import seedu.budgetbuddy.commons.RecurringExpenseLists; import java.util.Currency; @@ -13,15 +13,15 @@ public class ChangeCurrencyCommand extends Command { private Currency newCurrency; private SavingList savings; private ExpenseList expenses; - private RecurringExpensesList recurringExpensesList; + private RecurringExpenseLists recurringExpenseLists; private CurrencyConverter currencyConverter; public ChangeCurrencyCommand(Currency newCurrency, SavingList savings, ExpenseList expenses, - RecurringExpensesList recurringExpensesList, CurrencyConverter currencyConverter) { + RecurringExpenseLists recurringExpenseLists, CurrencyConverter currencyConverter) { this.newCurrency = newCurrency; this.savings = savings; this.expenses = expenses; - this.recurringExpensesList = recurringExpensesList; + this.recurringExpenseLists = recurringExpenseLists; this.currencyConverter = currencyConverter; } @@ -29,7 +29,7 @@ public ChangeCurrencyCommand(Currency newCurrency, SavingList savings, ExpenseLi public void execute() { currencyConverter.convertSavingCurrency(newCurrency, savings); currencyConverter.convertExpenseCurrency(newCurrency, expenses); - currencyConverter.convertRecurringExpensesCurrency(newCurrency, recurringExpensesList); + currencyConverter.convertRecurringExpensesCurrency(newCurrency, recurringExpenseLists); currencyConverter.convertBudgetCurrency(newCurrency, expenses); DefaultCurrency.setDefaultCurrency(newCurrency); } diff --git a/src/main/java/seedu/budgetbuddy/command/RecurringExpenseCommand.java b/src/main/java/seedu/budgetbuddy/command/RecurringExpenseCommand.java index 4c68b39e7e..c372394683 100644 --- a/src/main/java/seedu/budgetbuddy/command/RecurringExpenseCommand.java +++ b/src/main/java/seedu/budgetbuddy/command/RecurringExpenseCommand.java @@ -2,7 +2,7 @@ import seedu.budgetbuddy.commons.Expense; import seedu.budgetbuddy.commons.ExpenseList; -import seedu.budgetbuddy.commons.RecurringExpensesList; +import seedu.budgetbuddy.commons.RecurringExpenseLists; import seedu.budgetbuddy.Ui; import seedu.budgetbuddy.exception.BudgetBuddyException; @@ -12,7 +12,7 @@ public class RecurringExpenseCommand extends Command{ private static final Logger LOGGER = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); - private RecurringExpensesList recurringExpensesList; + private RecurringExpenseLists recurringExpenseLists; private ExpenseList overallExpenses; private String initialListName; @@ -29,12 +29,12 @@ public class RecurringExpenseCommand extends Command{ * Constructs a RecurringExpenseCommand for operations that only require the recurringExpensesList. * This constructor is used when the commandType is `viewlists` * - * @param recurringExpensesList The overall recurringExpensesList containing the list of ExpenseList + * @param recurringExpenseLists The overall recurringExpensesList containing the list of ExpenseList * @param commandType The commandType of the RecurringExpenseCommand */ - public RecurringExpenseCommand(RecurringExpensesList recurringExpensesList, String commandType) { + public RecurringExpenseCommand(RecurringExpenseLists recurringExpenseLists, String commandType) { this.commandType = commandType; - this.recurringExpensesList = recurringExpensesList; + this.recurringExpenseLists = recurringExpenseLists; } /** @@ -43,14 +43,14 @@ public RecurringExpenseCommand(RecurringExpensesList recurringExpensesList, Stri * This constructor is used when the commandType is `newlist` * * @param initialListName The name of the new RecurringExpenseList to create - * @param recurringExpensesList The overall recurringExpensesList containing the list of ExpenseList + * @param recurringExpenseLists The overall recurringExpensesList containing the list of ExpenseList * @param commandType The commandType of the RecurringExpenseCommand */ public RecurringExpenseCommand(String initialListName, - RecurringExpensesList recurringExpensesList, String commandType) { + RecurringExpenseLists recurringExpenseLists, String commandType) { this.initialListName = initialListName; this.commandType = commandType; - this.recurringExpensesList = recurringExpensesList; + this.recurringExpenseLists = recurringExpenseLists; } /** @@ -58,14 +58,14 @@ public RecurringExpenseCommand(String initialListName, * This constructor is used when the commandType is either `viewexpenses` or `removelist` * * @param listNumber The listNumber associated to the listName printed during a `viewlists` command - * @param recurringExpensesList The overall recurringExpensesList containing the list of ExpenseList + * @param recurringExpenseLists The overall recurringExpensesList containing the list of ExpenseList * @param commandType The commandType of the RecurringExpenseCommand */ public RecurringExpenseCommand(int listNumber, - RecurringExpensesList recurringExpensesList, String commandType) { + RecurringExpenseLists recurringExpenseLists, String commandType) { this.listNumber = listNumber; this.commandType = commandType; - this.recurringExpensesList = recurringExpensesList; + this.recurringExpenseLists = recurringExpenseLists; } @@ -75,14 +75,14 @@ public RecurringExpenseCommand(int listNumber, * This constructor is used when the commandType is `addrec` * * @param listNumber The listNumber associated to the listName printed during a `viewlists` command - * @param recurringExpensesList The overall recurringExpensesList containing the list of ExpenseList + * @param recurringExpenseLists The overall recurringExpensesList containing the list of ExpenseList * @param overallExpenses The overall ExpenseList containing all the user's expenses * @param commandType The commandType of the RecurringExpenseCommand */ - public RecurringExpenseCommand(int listNumber, RecurringExpensesList recurringExpensesList, + public RecurringExpenseCommand(int listNumber, RecurringExpenseLists recurringExpenseLists, ExpenseList overallExpenses, String commandType) { - this.recurringExpensesList = recurringExpensesList; + this.recurringExpenseLists = recurringExpenseLists; this.overallExpenses = overallExpenses; this.listNumber = listNumber; this.commandType = commandType; @@ -94,16 +94,16 @@ public RecurringExpenseCommand(int listNumber, RecurringExpensesList recurringEx * This constructor is used when the commandType is `newexpense` * * @param listNumber The listNumber associated to the listName printed during a `viewlists` command - * @param recurringExpensesList The overall recurringExpensesList containing the list of ExpenseList + * @param recurringExpenseLists The overall recurringExpensesList containing the list of ExpenseList * @param category The category of the new expense user wishes to add * @param amount The amount of the new expense user wishes to add * @param description The description of the new expense user wishes to add * @param commandType The commandType of the RecurringExpenseCommand */ - public RecurringExpenseCommand(int listNumber, RecurringExpensesList recurringExpensesList, String category, + public RecurringExpenseCommand(int listNumber, RecurringExpenseLists recurringExpenseLists, String category, Double amount, String description, String commandType) { - this.recurringExpensesList = recurringExpensesList; + this.recurringExpenseLists = recurringExpenseLists; this.listNumber = listNumber; this.category = category; this.amount = amount; @@ -117,7 +117,7 @@ public RecurringExpenseCommand(int listNumber, RecurringExpensesList recurringEx * @param listName The name of the new list */ private void addNewList(String listName) { - recurringExpensesList.addNewRecurringList(listName); + recurringExpenseLists.addNewRecurringList(listName); } /** @@ -127,13 +127,13 @@ private void addNewList(String listName) { */ private void removeList(int listNumber) { - if (listNumber == 0 || listNumber > recurringExpensesList.getSize()) { + if (listNumber <= 0 || listNumber > recurringExpenseLists.getSize()) { System.out.println("Invalid List Number. Choose a List Number from 1 onwards"); - System.out.println("Number of Lists you have currently : " + recurringExpensesList.getSize()); + System.out.println("Number of Lists you have currently : " + recurringExpenseLists.getSize()); return; } - recurringExpensesList.removeList(listNumber); + recurringExpenseLists.removeList(listNumber); } @@ -148,19 +148,24 @@ private void removeList(int listNumber) { */ private void addExpenseToList(int listNumber, String category, Double amount, String description) { - if (listNumber <= 0 || listNumber > recurringExpensesList.getSize()) { + if (listNumber <= 0 || listNumber > recurringExpenseLists.getSize()) { System.out.println("Invalid List Number. Choose a List Number from 1 onwards"); - System.out.println("Number of Lists you have currently : " + recurringExpensesList.getSize()); + System.out.println("Number of Lists you have currently : " + recurringExpenseLists.getSize()); return; } - ExpenseList expenses = recurringExpensesList.getExpenseListAtListNumber(listNumber); + ExpenseList expenses = recurringExpenseLists.getExpenseListAtListNumber(listNumber); try { expenses.addExpense(category, amount.toString(), description); ui.printDivider(); System.out.println("Successfully Added Expense to " + expenses.getName()); + System.out.println("|Details of Expense"); + System.out.println("--------------------"); + System.out.println("|Category : " + category); + System.out.println("|Amount : " + amount); + System.out.println("|Description : " + description); ui.printDivider(); } catch (BudgetBuddyException e) { @@ -176,21 +181,28 @@ private void addExpenseToList(int listNumber, String category, Double amount, St * into the provided `overallExpenses` * * @param listNumber The list position of the ExpenseList in recurringExpensesList - * @param recurringExpensesList The overall recurringExpensesList + * @param recurringExpenseLists The overall recurringExpensesList * @param overallExpenses The overall expenses */ - private void addRecurringExpensesToExpenses(int listNumber, RecurringExpensesList recurringExpensesList + private void addRecurringExpensesToExpenses(int listNumber, RecurringExpenseLists recurringExpenseLists , ExpenseList overallExpenses) { - if (listNumber <= 0 || listNumber > recurringExpensesList.getSize()) { + if (listNumber <= 0 || listNumber > recurringExpenseLists.getSize()) { System.out.println("Invalid List Number. Choose a List Number from 1 onwards"); - System.out.println("Number of Lists you have currently : " + recurringExpensesList.getSize()); + System.out.println("Number of Lists you have currently : " + recurringExpenseLists.getSize()); return; } - ExpenseList expenseList = recurringExpensesList.getExpenseListAtListNumber(listNumber); + ExpenseList expenseList = recurringExpenseLists.getExpenseListAtListNumber(listNumber); ArrayList expenses = expenseList.getExpenses(); + if (expenses.isEmpty()) { + ui.printDivider(); + System.out.println("There are no expenses present in \"" + expenseList.getName() + + "\" nothing has been added to the overall expenses"); + ui.printDivider(); + return; + } for (Expense expense : expenses) { String category = expense.getCategory(); Double amount = expense.getAmount(); @@ -205,7 +217,6 @@ private void addRecurringExpensesToExpenses(int listNumber, RecurringExpensesLis ui.printDivider(); System.out.println("You Recurring Expenses in " + expenseList.getName() + " has been added to your overall Expenses"); - ui.printDivider(); } @@ -215,17 +226,17 @@ private void addRecurringExpensesToExpenses(int listNumber, RecurringExpensesLis * `recurringExpensesList` * * @param listNumber The list position of the ExpenseList in recurringExpensesList - * @param recurringExpensesList The recurringExpensesList to obtain ExpenseList from + * @param recurringExpenseLists The recurringExpensesList to obtain ExpenseList from */ - private void printExpensesAtIndex(int listNumber, RecurringExpensesList recurringExpensesList) { + private void printExpensesAtIndex(int listNumber, RecurringExpenseLists recurringExpenseLists) { - if (listNumber <= 0 || listNumber > recurringExpensesList.getSize()) { + if (listNumber <= 0 || listNumber > recurringExpenseLists.getSize()) { System.out.println("Invalid List Number. Choose a List Number from 1 onwards"); - System.out.println("Number of Lists you have currently : " + recurringExpensesList.getSize()); + System.out.println("Number of Lists you have currently : " + recurringExpenseLists.getSize()); return; } - ExpenseList expenseList = recurringExpensesList.getExpenseListAtListNumber(listNumber); + ExpenseList expenseList = recurringExpenseLists.getExpenseListAtListNumber(listNumber); expenseList.listExpenses(null); } @@ -235,7 +246,7 @@ private void printExpensesAtIndex(int listNumber, RecurringExpensesList recurrin * Prints the names of all ExpenseList in the recurringExpensesList */ private void printList() { - recurringExpensesList.printAllRecurringLists(); + recurringExpenseLists.printAllRecurringLists(); } public void execute(){ @@ -253,10 +264,10 @@ public void execute(){ addExpenseToList(this.listNumber, this.category, this.amount, this.description); break; case "addrec": - addRecurringExpensesToExpenses(this.listNumber, this.recurringExpensesList, this.overallExpenses); + addRecurringExpensesToExpenses(this.listNumber, this.recurringExpenseLists, this.overallExpenses); break; case "viewexpenses": - printExpensesAtIndex(this.listNumber, this.recurringExpensesList); + printExpensesAtIndex(this.listNumber, this.recurringExpenseLists); break; default: break; diff --git a/src/main/java/seedu/budgetbuddy/commandcreator/ChangeCurrencyCommandCreator.java b/src/main/java/seedu/budgetbuddy/commandcreator/ChangeCurrencyCommandCreator.java index 216344ba26..76d8ce7c5f 100644 --- a/src/main/java/seedu/budgetbuddy/commandcreator/ChangeCurrencyCommandCreator.java +++ b/src/main/java/seedu/budgetbuddy/commandcreator/ChangeCurrencyCommandCreator.java @@ -2,7 +2,7 @@ import seedu.budgetbuddy.commons.CurrencyConverter; import seedu.budgetbuddy.commons.ExpenseList; -import seedu.budgetbuddy.commons.RecurringExpensesList; +import seedu.budgetbuddy.commons.RecurringExpenseLists; import seedu.budgetbuddy.commons.SavingList; import seedu.budgetbuddy.command.ChangeCurrencyCommand; import seedu.budgetbuddy.command.Command; @@ -16,17 +16,17 @@ public class ChangeCurrencyCommandCreator extends CommandCreator { private static final Logger LOGGER = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); private ExpenseList expenses; private SavingList savings; - private RecurringExpensesList recurringExpensesList; + private RecurringExpenseLists recurringExpenseLists; private String input; private CurrencyConverter newCurrency; public ChangeCurrencyCommandCreator(String input, SavingList savings, ExpenseList expenses - ,RecurringExpensesList recurringExpensesList, CurrencyConverter newCurrency) { + , RecurringExpenseLists recurringExpenseLists, CurrencyConverter newCurrency) { this.input = input; this.savings = savings; this.expenses = expenses; - this.recurringExpensesList = recurringExpensesList; + this.recurringExpenseLists = recurringExpenseLists; this.newCurrency = newCurrency; } @@ -42,7 +42,7 @@ public ChangeCurrencyCommandCreator(String input, SavingList savings, ExpenseLis * @return A ChangeCurrencyCommand if the input is valid; otherwise, null. */ public Command handleChangeCurrencyCommand(String input, SavingList savingList, ExpenseList expenseList, - RecurringExpensesList recurringExpensesList, + RecurringExpenseLists recurringExpenseLists, CurrencyConverter currencyConverter) { if (input.toLowerCase().startsWith("change currency")) { String[] parts = input.split(" "); @@ -56,7 +56,7 @@ public Command handleChangeCurrencyCommand(String input, SavingList savingList, Currency newCurrency = Currency.getInstance(currencyCode.toUpperCase()); assert newCurrency != null : "Currency code should be valid"; LOGGER.log(Level.INFO, "Default currency changed to " + newCurrency); - return new ChangeCurrencyCommand(newCurrency, savingList, expenseList, recurringExpensesList, + return new ChangeCurrencyCommand(newCurrency, savingList, expenseList, recurringExpenseLists, currencyConverter); } catch (IllegalArgumentException e) { LOGGER.log(Level.WARNING, "Invalid currency code: " + currencyCode); @@ -73,6 +73,6 @@ public Command handleChangeCurrencyCommand(String input, SavingList savingList, } @Override public Command createCommand() { - return handleChangeCurrencyCommand(input, savings, expenses, recurringExpensesList, newCurrency); + return handleChangeCurrencyCommand(input, savings, expenses, recurringExpenseLists, newCurrency); } } diff --git a/src/main/java/seedu/budgetbuddy/commandcreator/RecurringExpenseCommandCreator.java b/src/main/java/seedu/budgetbuddy/commandcreator/RecurringExpenseCommandCreator.java index 49f7f36f3d..be41528409 100644 --- a/src/main/java/seedu/budgetbuddy/commandcreator/RecurringExpenseCommandCreator.java +++ b/src/main/java/seedu/budgetbuddy/commandcreator/RecurringExpenseCommandCreator.java @@ -1,7 +1,7 @@ package seedu.budgetbuddy.commandcreator; import seedu.budgetbuddy.commons.ExpenseList; -import seedu.budgetbuddy.commons.RecurringExpensesList; +import seedu.budgetbuddy.commons.RecurringExpenseLists; import seedu.budgetbuddy.command.Command; import seedu.budgetbuddy.command.RecurringExpenseCommand; import seedu.budgetbuddy.exception.BudgetBuddyException; @@ -16,21 +16,21 @@ public class RecurringExpenseCommandCreator extends CommandCreator{ private static final String AMOUNT_PREFIX = "a/"; private static final String DESCRIPTION_PREFIX = "d/"; private String input; - private RecurringExpensesList recurringExpensesList; + private RecurringExpenseLists recurringExpenseLists; private ExpenseList expenses; /** * Constructs a RecurringExpenseCommandCreator with the provided input, recurringExpensesList and expenses * @param input The user input - * @param recurringExpensesList The RecurringExpensesList containing a list of ExpenseList + * @param recurringExpenseLists The RecurringExpensesList containing a list of ExpenseList * @param expenses The ExpenseList containing user's overall expenses */ - public RecurringExpenseCommandCreator(String input, RecurringExpensesList recurringExpensesList + public RecurringExpenseCommandCreator(String input, RecurringExpenseLists recurringExpenseLists , ExpenseList expenses) { this. input = input; - this.recurringExpensesList = recurringExpensesList; + this.recurringExpenseLists = recurringExpenseLists; this.expenses = expenses; } @@ -59,7 +59,7 @@ public Command createViewExpensesCommand(String[] commandParts) { try { String listNumberAsString = commandParts[2]; int listNumber = Integer.parseInt(listNumberAsString); - return new RecurringExpenseCommand(listNumber, recurringExpensesList, "viewexpenses"); + return new RecurringExpenseCommand(listNumber, recurringExpenseLists, "viewexpenses"); } catch (NumberFormatException e) { LOGGER.log(Level.WARNING, "An invalid integer has been detected"); System.out.println("Please input a valid Integer"); @@ -86,7 +86,7 @@ public Command createAddListToOverallExpensesCommand(String[] commandParts) { try { String listNumberAsString = commandParts[2]; int listNumber = Integer.parseInt(listNumberAsString); - return new RecurringExpenseCommand(listNumber, recurringExpensesList, expenses, "addrec"); + return new RecurringExpenseCommand(listNumber, recurringExpenseLists, expenses, "addrec"); } catch (NumberFormatException e) { LOGGER.log(Level.WARNING, "An invalid integer has been detected"); System.out.println("Please input a valid Integer"); @@ -127,7 +127,7 @@ private String parseDescription(String input) throws BudgetBuddyException { int endIndexOfDescription = input.length(); - String description = input.substring(startIndexOfDescription,endIndexOfDescription); + String description = input.substring(startIndexOfDescription,endIndexOfDescription).trim(); if(description.trim().isEmpty()) { LOGGER.log(Level.WARNING, "Empty Description Detected, throwing BudgetBuddyException"); @@ -150,7 +150,7 @@ private Double parseAmount(String input) throws NumberFormatException, BudgetBud int startIndexOfAmount = indexOfAmountPrefix + AMOUNT_PREFIX.length(); int indexOfDescriptionPrefix = input.indexOf(DESCRIPTION_PREFIX); - int endIndexOfAmount = indexOfDescriptionPrefix - 1; + int endIndexOfAmount = indexOfDescriptionPrefix; String amountAsString = input.substring(startIndexOfAmount, endIndexOfAmount); @@ -176,9 +176,9 @@ private String parseCategory(String input) throws BudgetBuddyException{ int startIndexOfCategory = indexOfCategoryPrefix + CATEGORY_PREFIX.length(); int indexOfAmountPrefix = input.indexOf(AMOUNT_PREFIX); - int endIndexOfCategory = indexOfAmountPrefix - 1; + int endIndexOfCategory = indexOfAmountPrefix; - String category = input.substring(startIndexOfCategory, endIndexOfCategory); + String category = input.substring(startIndexOfCategory, endIndexOfCategory).trim(); if(category.trim().isEmpty()) { throw new BudgetBuddyException("Please Ensure Category is NOT empty"); @@ -200,9 +200,9 @@ private int parseListNumber(String input) throws NumberFormatException, BudgetBu int startIndexOfListNumber = indexOfListNumberPrefix + LISTNUMBER_PREFIX.length(); int indexOfCategoryPrefix = input.indexOf(CATEGORY_PREFIX); - int endIndexOfListNumber = indexOfCategoryPrefix - 1; + int endIndexOfListNumber = indexOfCategoryPrefix; - String listNumberAsString = input.substring(startIndexOfListNumber, endIndexOfListNumber); + String listNumberAsString = input.substring(startIndexOfListNumber, endIndexOfListNumber).trim(); if(listNumberAsString.trim().isEmpty()) { throw new BudgetBuddyException("Please Ensure List Number is NOT empty"); @@ -213,6 +213,43 @@ private int parseListNumber(String input) throws NumberFormatException, BudgetBu return listNumber; } + private void checkForOutOfOrderParameters(String input) throws BudgetBuddyException{ + assert (input.contains(LISTNUMBER_PREFIX) && input.contains(CATEGORY_PREFIX) + && input.contains(AMOUNT_PREFIX) && input.contains(DESCRIPTION_PREFIX)) + : "Input has all required prefixes"; + + int indexOfListNumberPrefix = input.indexOf(LISTNUMBER_PREFIX); + int indexOfCategoryPrefix = input.indexOf(CATEGORY_PREFIX); + int indexOfAmountPrefix = input.indexOf(AMOUNT_PREFIX); + int indexOfDescriptionPrefix = input.indexOf(DESCRIPTION_PREFIX); + + if (indexOfListNumberPrefix > indexOfCategoryPrefix) { + throw new BudgetBuddyException("Please Ensure your prefixes are in the right order"); + } + + if (indexOfCategoryPrefix > indexOfAmountPrefix) { + throw new BudgetBuddyException("Please Ensure your prefixes are in the right order"); + } + + if (indexOfAmountPrefix > indexOfDescriptionPrefix) { + throw new BudgetBuddyException("Please Ensure your prefixes are in the right order"); + } + } + + private void checkForDuplicateParameters(String input) throws BudgetBuddyException { + + assert (input.contains(LISTNUMBER_PREFIX) && input.contains(CATEGORY_PREFIX) + && input.contains(AMOUNT_PREFIX) && input.contains(DESCRIPTION_PREFIX)) + : "Input has all required prefixes"; + + String[] parameters = {LISTNUMBER_PREFIX, CATEGORY_PREFIX, AMOUNT_PREFIX, DESCRIPTION_PREFIX}; + + for (String parameter : parameters) { + if (input.indexOf(parameter) != input.lastIndexOf(parameter)) { + throw new BudgetBuddyException("Please ensure that you do not have any duplicate parameters"); + } + } + } /** * Creates a RecurringExpenseCommand to add an expense into a specific ExpenseList in recurringExpensesList @@ -223,15 +260,14 @@ private int parseListNumber(String input) throws NumberFormatException, BudgetBu public Command createAddExpenseToListCommand(String input) { try { checkForInvalidParameters(input); + checkForDuplicateParameters(input); checkForInvalidCharacters(input); - } catch (IllegalArgumentException e) { + checkForOutOfOrderParameters(input); + } catch (IllegalArgumentException | BudgetBuddyException e) { System.out.println(e.getMessage()); System.out.println("Command Format : rec newexpense to/ LISTNUMBER c/ CATEGORY" + " a/ AMOUNT d/ DESCRIPTION"); return null; - } catch (BudgetBuddyException e) { - System.out.println(e.getMessage()); - return null; } try { @@ -240,7 +276,7 @@ public Command createAddExpenseToListCommand(String input) { Double amount = parseAmount(input); String description = parseDescription(input); - return new RecurringExpenseCommand(listNumber, recurringExpensesList, category, + return new RecurringExpenseCommand(listNumber, recurringExpenseLists, category, amount, description, "newexpense"); } catch (BudgetBuddyException e) { LOGGER.log(Level.INFO, "Successfully caught BudgetBuddy Exception. Handling Error"); @@ -250,7 +286,7 @@ public Command createAddExpenseToListCommand(String input) { return null; } catch (NumberFormatException e) { LOGGER.log(Level.INFO, "Successfully caught NumberFormatException. Handling Error"); - System.out.println("Please ensure that listNumber and Amount are valid Numbers"); + System.out.println("Please ensure that listNumber and Amount are valid Numbers/Monetary amounts"); System.out.println("Command Format : rec newexpense to/ LISTNUMBER c/ CATEGORY" + " a/ AMOUNT d/ DESCRIPTION"); return null; @@ -269,7 +305,7 @@ public Command createRemoveListCommand(String[] commandParts) { try { String listNumberAsString = commandParts[2]; int listNumber = Integer.parseInt(listNumberAsString); - return new RecurringExpenseCommand(listNumber, recurringExpensesList, "removelist"); + return new RecurringExpenseCommand(listNumber, recurringExpenseLists, "removelist"); } catch (ArrayIndexOutOfBoundsException e) { LOGGER.log(Level.INFO, "Successfully caught Exception. Handling Error"); System.out.println("List Number Cannot be Empty"); @@ -290,31 +326,42 @@ public Command createRemoveListCommand(String[] commandParts) { * @return A RecurringExpenseCommand */ public Command createViewListCommand() { - return new RecurringExpenseCommand(recurringExpensesList, "viewlists"); + return new RecurringExpenseCommand(recurringExpenseLists, "viewlists"); } /** * Creates a RecurringExpenseCommand to add a new RecurringExpenseList into recurringExpensesList - * This method uses the provided `commandParts` to extract the listName of the new RecurringExpenseList * - * @param commandParts The split parts of the user input + * @param input The user input * @return RecurringExpenseCommand if listName is valid, returns null if the listName extracted is empty */ - public Command createNewListCommand(String[] commandParts) { + public Command createNewListCommand(String input) { + assert (input.startsWith("rec newlist")) : "Input must start with rec newlist "; + try { - String listName = commandParts[2]; checkForInvalidCharacters(input); - return new RecurringExpenseCommand(listName, recurringExpensesList, "newlist"); + int indexOfNewListCommandType = input.indexOf("newlist"); + int indexOfListName = indexOfNewListCommandType + "newlist".length(); + int endIndexOfListName = input.length(); + + String listName = input.substring(indexOfListName, endIndexOfListName).trim(); + + if (listName.isEmpty()) { + System.out.println("Please Ensure the LISTNAME is not empty"); + return null; + } + + return new RecurringExpenseCommand(listName, this.recurringExpenseLists, "newlist"); + } catch (ArrayIndexOutOfBoundsException e) { - LOGGER.log(Level.INFO, "Successfully caught Exception. Handling Error"); - System.out.println("Please Input a Valid listName"); - System.out.println("Command Format : rec newlist [listName]"); + System.out.println("Something went wrong"); return null; } catch (BudgetBuddyException e) { - LOGGER.log(Level.INFO, "Successfully caught Exception. Handling Error"); + LOGGER.log(Level.INFO, "BudgetBuddyException has been caught and handled"); System.out.println(e.getMessage()); return null; } + } /** @@ -326,25 +373,31 @@ public Command createNewListCommand(String[] commandParts) { * returns null if commandType is not valid */ public Command handleRecCommand(String input){ - String[] commandParts = input.split(" "); - String commandType = commandParts[1]; - commandType = commandType.trim(); - - switch(commandType) { - case "newlist": - return createNewListCommand(commandParts); - case "viewlists": - return createViewListCommand(); - case "removelist": - return createRemoveListCommand(commandParts); - case "newexpense": - return createAddExpenseToListCommand(input); - case "addrec": - return createAddListToOverallExpensesCommand(commandParts); - case "viewexpenses": - return createViewExpensesCommand(commandParts); - default: - System.out.println("This Command Type does not exist for \"rec\""); + + try { + String[] commandParts = input.split(" "); + String commandType = commandParts[1]; + commandType = commandType.trim(); + + switch(commandType) { + case "newlist": + return createNewListCommand(this.input); + case "viewlists": + return createViewListCommand(); + case "removelist": + return createRemoveListCommand(commandParts); + case "newexpense": + return createAddExpenseToListCommand(input); + case "addrec": + return createAddListToOverallExpensesCommand(commandParts); + case "viewexpenses": + return createViewExpensesCommand(commandParts); + default: + System.out.println("This Command Type does not exist for \"rec\""); + return null; + } + } catch (IndexOutOfBoundsException e) { + System.out.println("Please do not leave the command type empty"); return null; } diff --git a/src/main/java/seedu/budgetbuddy/commons/CurrencyConverter.java b/src/main/java/seedu/budgetbuddy/commons/CurrencyConverter.java index ee6fc257a8..11f2f7c24d 100644 --- a/src/main/java/seedu/budgetbuddy/commons/CurrencyConverter.java +++ b/src/main/java/seedu/budgetbuddy/commons/CurrencyConverter.java @@ -171,8 +171,9 @@ public void convertSplitExpenseCurrency(Currency newCurrency, SplitExpenseList s System.out.println("Default currency for Split Expenses changed to " + newCurrency); } - public void convertRecurringExpensesCurrency(Currency newCurrency, RecurringExpensesList recurringExpensesList) { - if (recurringExpensesList == null) { + public void convertRecurringExpensesCurrency(Currency newCurrency, RecurringExpenseLists recurringExpenseLists) { + if (recurringExpenseLists == null) { + throw new IllegalArgumentException("SavingList cannot be null"); } @@ -181,11 +182,11 @@ public void convertRecurringExpensesCurrency(Currency newCurrency, RecurringExpe return; } - int numberOfExpenseList = recurringExpensesList.getSize(); + int numberOfExpenseList = recurringExpenseLists.getSize(); for (int i = 0; i < numberOfExpenseList; i++) { int arrayIndexAsListNumber = i + 1; - ExpenseList reccuringExpenseList = recurringExpensesList.getExpenseListAtListNumber(arrayIndexAsListNumber); + ExpenseList reccuringExpenseList = recurringExpenseLists.getExpenseListAtListNumber(arrayIndexAsListNumber); convertExpenseCurrency(newCurrency, reccuringExpenseList); } diff --git a/src/main/java/seedu/budgetbuddy/commons/RecurringExpensesList.java b/src/main/java/seedu/budgetbuddy/commons/RecurringExpenseLists.java similarity index 96% rename from src/main/java/seedu/budgetbuddy/commons/RecurringExpensesList.java rename to src/main/java/seedu/budgetbuddy/commons/RecurringExpenseLists.java index 57f2af0329..0506e99af0 100644 --- a/src/main/java/seedu/budgetbuddy/commons/RecurringExpensesList.java +++ b/src/main/java/seedu/budgetbuddy/commons/RecurringExpenseLists.java @@ -9,19 +9,19 @@ * This class provides methods to add, remove and manage the list of ExpenseList * */ -public class RecurringExpensesList { +public class RecurringExpenseLists { protected ArrayList recurringExpenses; Ui ui = new Ui(); - public RecurringExpensesList(ArrayList recurringExpenses) { + public RecurringExpenseLists(ArrayList recurringExpenses) { this.recurringExpenses = recurringExpenses; } /** * Constructs an RecurringExpensesList object with an empty ArrayList */ - public RecurringExpensesList() { + public RecurringExpenseLists() { this.recurringExpenses = new ArrayList<>(); } diff --git a/src/test/java/seedu/budgetbuddy/ChangeCurrencyCommandCreatorTest.java b/src/test/java/seedu/budgetbuddy/ChangeCurrencyCommandCreatorTest.java index 7faa52512c..1fd4f7e56a 100644 --- a/src/test/java/seedu/budgetbuddy/ChangeCurrencyCommandCreatorTest.java +++ b/src/test/java/seedu/budgetbuddy/ChangeCurrencyCommandCreatorTest.java @@ -6,7 +6,7 @@ import seedu.budgetbuddy.commandcreator.ChangeCurrencyCommandCreator; import seedu.budgetbuddy.commons.CurrencyConverter; import seedu.budgetbuddy.commons.ExpenseList; -import seedu.budgetbuddy.commons.RecurringExpensesList; +import seedu.budgetbuddy.commons.RecurringExpenseLists; import seedu.budgetbuddy.commons.SavingList; import seedu.budgetbuddy.exception.BudgetBuddyException; @@ -20,7 +20,7 @@ public class ChangeCurrencyCommandCreatorTest { public void handleChangeCurrencyCommand_changeCurrencyToUSD_success() throws BudgetBuddyException { SavingList savingList = new SavingList(); ExpenseList expenseList = new ExpenseList(); - RecurringExpensesList recurringExpensesList = new RecurringExpensesList(); + RecurringExpenseLists recurringExpenseLists = new RecurringExpenseLists(); CurrencyConverter currencyConverter = new CurrencyConverter(); savingList.addSaving("Salary", "1000"); @@ -28,10 +28,10 @@ public void handleChangeCurrencyCommand_changeCurrencyToUSD_success() throws Bud String input = "change currency USD"; ChangeCurrencyCommandCreator changeCurrencyCommandCreator = new ChangeCurrencyCommandCreator(input, savingList, - expenseList, recurringExpensesList, currencyConverter); + expenseList, recurringExpenseLists, currencyConverter); Command command = changeCurrencyCommandCreator.handleChangeCurrencyCommand(input, savingList, - expenseList, recurringExpensesList, currencyConverter); + expenseList, recurringExpenseLists, currencyConverter); assertEquals(ChangeCurrencyCommand.class, command.getClass()); } @@ -40,17 +40,17 @@ public void handleChangeCurrencyCommand_changeCurrencyToUSD_success() throws Bud public void handleChangeCurrencyCommand_changeCurrency_invalidCurrencyCode() throws BudgetBuddyException { SavingList savingList = new SavingList(); ExpenseList expenseList = new ExpenseList(); - RecurringExpensesList recurringExpensesList = new RecurringExpensesList(); + RecurringExpenseLists recurringExpenseLists = new RecurringExpenseLists(); CurrencyConverter currencyConverter = new CurrencyConverter(); savingList.addSaving("Salary", "1000"); String input = "change currency abc"; ChangeCurrencyCommandCreator changeCurrencyCommandCreator = new ChangeCurrencyCommandCreator(input, savingList, - expenseList, recurringExpensesList, currencyConverter); + expenseList, recurringExpenseLists, currencyConverter); Command command = changeCurrencyCommandCreator.handleChangeCurrencyCommand(input, savingList, - expenseList, recurringExpensesList, currencyConverter); + expenseList, recurringExpenseLists, currencyConverter); assertNull(command); } @@ -58,17 +58,17 @@ public void handleChangeCurrencyCommand_changeCurrency_invalidCurrencyCode() thr public void handleChangeCurrencyCommand_changeCurrency_invalidCommandFormat() throws BudgetBuddyException { SavingList savingList = new SavingList(); ExpenseList expenseList = new ExpenseList(); - RecurringExpensesList recurringExpensesList = new RecurringExpensesList(); + RecurringExpenseLists recurringExpenseLists = new RecurringExpenseLists(); CurrencyConverter currencyConverter = new CurrencyConverter(); savingList.addSaving("Salary", "1000"); String input = "change currency abc asd"; ChangeCurrencyCommandCreator changeCurrencyCommandCreator = new ChangeCurrencyCommandCreator(input, savingList, - expenseList, recurringExpensesList, currencyConverter); + expenseList, recurringExpenseLists, currencyConverter); Command command = changeCurrencyCommandCreator.handleChangeCurrencyCommand(input, savingList, - expenseList, recurringExpensesList, currencyConverter); + expenseList, recurringExpenseLists, currencyConverter); assertNull(command); } } diff --git a/src/test/java/seedu/budgetbuddy/ParserTest.java b/src/test/java/seedu/budgetbuddy/ParserTest.java index 938e47bcd5..0fafdd56c4 100644 --- a/src/test/java/seedu/budgetbuddy/ParserTest.java +++ b/src/test/java/seedu/budgetbuddy/ParserTest.java @@ -6,7 +6,7 @@ import seedu.budgetbuddy.command.MenuCommand; import seedu.budgetbuddy.command.RecurringExpenseCommand; import seedu.budgetbuddy.commons.ExpenseList; -import seedu.budgetbuddy.commons.RecurringExpensesList; +import seedu.budgetbuddy.commons.RecurringExpenseLists; import seedu.budgetbuddy.commons.SavingList; import seedu.budgetbuddy.commons.SplitExpenseList; @@ -23,7 +23,7 @@ public void parseCommand_invalidCommand_returnsNull() { Parser parser = new Parser(); ExpenseList expenses = new ExpenseList(); SavingList savings = new SavingList(); - RecurringExpensesList expensesList = new RecurringExpensesList(); + RecurringExpenseLists expensesList = new RecurringExpenseLists(); SplitExpenseList splitExpenseList = new SplitExpenseList(); Command invalidCommand = parser.parseCommand(expenses, savings, splitExpenseList, expensesList, "NotaCommand"); @@ -36,7 +36,7 @@ public void parseCommand_menuCommand_returnsMenuCommand() { Parser parser = new Parser(); ExpenseList expenses = new ExpenseList(); SavingList savings = new SavingList(); - RecurringExpensesList expensesList = new RecurringExpensesList(); + RecurringExpenseLists expensesList = new RecurringExpenseLists(); SplitExpenseList splitExpenseList = new SplitExpenseList(); String input = "menu 1"; @@ -51,7 +51,7 @@ public void parseCommand_findExpensesCommand_returnsFindExpensesCommand() { Parser parser = new Parser(); ExpenseList expenses = new ExpenseList(); SavingList savings = new SavingList(); - RecurringExpensesList expensesList = new RecurringExpensesList(); + RecurringExpenseLists expensesList = new RecurringExpenseLists(); SplitExpenseList splitExpenseList = new SplitExpenseList(); String input = "find expenses d/hello morethan/200 lessthan/300"; @@ -66,7 +66,7 @@ public void parseCommand_recCommand_returnsRecurringExpenseCommand() { Parser parser = new Parser(); ExpenseList expenses = new ExpenseList(); SavingList savings = new SavingList(); - RecurringExpensesList expensesList = new RecurringExpensesList(); + RecurringExpenseLists expensesList = new RecurringExpenseLists(); SplitExpenseList splitExpenseList = new SplitExpenseList(); String input = "rec newlist listname"; diff --git a/src/test/java/seedu/budgetbuddy/RecurringExpenseCommandCreatorTest.java b/src/test/java/seedu/budgetbuddy/RecurringExpenseCommandCreatorTest.java index 86de3fdb97..772e15f02d 100644 --- a/src/test/java/seedu/budgetbuddy/RecurringExpenseCommandCreatorTest.java +++ b/src/test/java/seedu/budgetbuddy/RecurringExpenseCommandCreatorTest.java @@ -6,7 +6,7 @@ import seedu.budgetbuddy.commandcreator.CommandCreator; import seedu.budgetbuddy.commandcreator.RecurringExpenseCommandCreator; import seedu.budgetbuddy.commons.ExpenseList; -import seedu.budgetbuddy.commons.RecurringExpensesList; +import seedu.budgetbuddy.commons.RecurringExpenseLists; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertInstanceOf; @@ -17,7 +17,7 @@ public class RecurringExpenseCommandCreatorTest { @Test public void handleRecCommand_invalidCommandType_returnsNull() { ExpenseList expenseList = new ExpenseList(); - RecurringExpensesList expensesList = new RecurringExpensesList(); + RecurringExpenseLists expensesList = new RecurringExpenseLists(); String input = "rec invalid Entertainment"; CommandCreator commandCreator = new RecurringExpenseCommandCreator(input, expensesList, expenseList); @@ -28,7 +28,7 @@ public void handleRecCommand_invalidCommandType_returnsNull() { @Test public void handleRecCommand_newListCommandWithValidInput_createsRecurringExpenseCommand() { ExpenseList expenseList = new ExpenseList(); - RecurringExpensesList expensesList = new RecurringExpensesList(); + RecurringExpenseLists expensesList = new RecurringExpenseLists(); String input = "rec newlist Entertainment"; CommandCreator commandCreator = new RecurringExpenseCommandCreator(input, expensesList, expenseList); @@ -41,7 +41,7 @@ public void handleRecCommand_newListCommandWithValidInput_createsRecurringExpens @Test public void handleRecCommand_newListCommandWithInvalidInput_returnsNull() { ExpenseList expenseList = new ExpenseList(); - RecurringExpensesList expensesList = new RecurringExpensesList(); + RecurringExpenseLists expensesList = new RecurringExpenseLists(); String input = "rec newlist"; CommandCreator commandCreator = new RecurringExpenseCommandCreator(input, expensesList, expenseList); @@ -53,7 +53,7 @@ public void handleRecCommand_newListCommandWithInvalidInput_returnsNull() { @Test public void handleRecCommand_removeListCommandWithValidInput_createsRecurringExpenseCommand() { ExpenseList expenseList = new ExpenseList(); - RecurringExpensesList expensesList = new RecurringExpensesList(); + RecurringExpenseLists expensesList = new RecurringExpenseLists(); expensesList.addNewRecurringList("Entertainment"); String input = "rec removelist 1"; @@ -67,7 +67,7 @@ public void handleRecCommand_removeListCommandWithValidInput_createsRecurringExp @Test public void handleRecCommand_removeListCommandWithInvalidInput_returnsNull() { ExpenseList expenseList = new ExpenseList(); - RecurringExpensesList expensesList = new RecurringExpensesList(); + RecurringExpenseLists expensesList = new RecurringExpenseLists(); String input = "rec removelist string"; CommandCreator commandCreator = new RecurringExpenseCommandCreator(input, expensesList, expenseList); @@ -79,7 +79,7 @@ public void handleRecCommand_removeListCommandWithInvalidInput_returnsNull() { @Test public void handleRecCommand_removeListCommandWithEmptyInput_returnsNull() { ExpenseList expenseList = new ExpenseList(); - RecurringExpensesList expensesList = new RecurringExpensesList(); + RecurringExpenseLists expensesList = new RecurringExpenseLists(); String input = "rec removelist"; CommandCreator commandCreator = new RecurringExpenseCommandCreator(input, expensesList, expenseList); @@ -91,7 +91,7 @@ public void handleRecCommand_removeListCommandWithEmptyInput_returnsNull() { @Test public void handleRecCommand_viewListsCommand_returnsRecurringExpenseCommand() { ExpenseList expenseList = new ExpenseList(); - RecurringExpensesList expensesList = new RecurringExpensesList(); + RecurringExpenseLists expensesList = new RecurringExpenseLists(); String input = "rec viewlists"; CommandCreator commandCreator = new RecurringExpenseCommandCreator(input, expensesList, expenseList); @@ -104,7 +104,7 @@ public void handleRecCommand_viewListsCommand_returnsRecurringExpenseCommand() { @Test public void handleRecCommand_addRecCommandWithEmptyInput_returnsNull() { ExpenseList expenseList = new ExpenseList(); - RecurringExpensesList expensesList = new RecurringExpensesList(); + RecurringExpenseLists expensesList = new RecurringExpenseLists(); expensesList.addNewRecurringList("Entertainment"); String input = "rec addrec"; @@ -117,7 +117,7 @@ public void handleRecCommand_addRecCommandWithEmptyInput_returnsNull() { @Test public void handleRecCommand_addRecCommandWithValidInput_createsRecurringExpenseCommand() { ExpenseList expenseList = new ExpenseList(); - RecurringExpensesList expensesList = new RecurringExpensesList(); + RecurringExpenseLists expensesList = new RecurringExpenseLists(); expensesList.addNewRecurringList("Entertainment"); String input = "rec addrec 1"; @@ -131,7 +131,7 @@ public void handleRecCommand_addRecCommandWithValidInput_createsRecurringExpense @Test public void handleRecCommand_addRecCommandWithInvalidInput_returnsNull() { ExpenseList expenseList = new ExpenseList(); - RecurringExpensesList expensesList = new RecurringExpensesList(); + RecurringExpenseLists expensesList = new RecurringExpenseLists(); String input = "rec addrec sdefwre"; CommandCreator commandCreator = new RecurringExpenseCommandCreator(input, expensesList, expenseList); @@ -143,7 +143,7 @@ public void handleRecCommand_addRecCommandWithInvalidInput_returnsNull() { @Test public void handleRecCommand_viewExpensesCommandWithEmptyInput_returnsNull() { ExpenseList expenseList = new ExpenseList(); - RecurringExpensesList expensesList = new RecurringExpensesList(); + RecurringExpenseLists expensesList = new RecurringExpenseLists(); expensesList.addNewRecurringList("Entertainment"); String input = "rec viewexpenses"; @@ -156,7 +156,7 @@ public void handleRecCommand_viewExpensesCommandWithEmptyInput_returnsNull() { @Test public void handleRecCommand_viewExpensesCommandWithValidInput_createsRecurringExpenseCommand() { ExpenseList expenseList = new ExpenseList(); - RecurringExpensesList expensesList = new RecurringExpensesList(); + RecurringExpenseLists expensesList = new RecurringExpenseLists(); expensesList.addNewRecurringList("Entertainment"); String input = "rec viewexpenses 1"; @@ -170,7 +170,7 @@ public void handleRecCommand_viewExpensesCommandWithValidInput_createsRecurringE @Test public void handleRecCommand_viewExpensesCommandWithInvalidInput_returnsNull() { ExpenseList expenseList = new ExpenseList(); - RecurringExpensesList expensesList = new RecurringExpensesList(); + RecurringExpenseLists expensesList = new RecurringExpenseLists(); expensesList.addNewRecurringList("Entertainment"); String input = "rec viewexpenses fdgder"; @@ -184,7 +184,7 @@ public void handleRecCommand_viewExpensesCommandWithInvalidInput_returnsNull() { @Test public void handleRecCommand_newExpenseCommandWithValidInput_createsRecurringExpenseCommand() { ExpenseList expenseList = new ExpenseList(); - RecurringExpensesList expensesList = new RecurringExpensesList(); + RecurringExpenseLists expensesList = new RecurringExpenseLists(); expensesList.addNewRecurringList("Entertainment"); String input = "rec newexpense to/1 c/Entertainment a/100 d/Movies"; @@ -198,7 +198,7 @@ public void handleRecCommand_newExpenseCommandWithValidInput_createsRecurringExp @Test public void handleRecCommand_newExpenseCommandWithInvalidAmount_returnsNull() { ExpenseList expenseList = new ExpenseList(); - RecurringExpensesList expensesList = new RecurringExpensesList(); + RecurringExpenseLists expensesList = new RecurringExpenseLists(); expensesList.addNewRecurringList("Entertainment"); String input = "rec newexpense to/1 c/Entertainment a/sdsdfsdf d/Movies"; @@ -211,7 +211,7 @@ public void handleRecCommand_newExpenseCommandWithInvalidAmount_returnsNull() { @Test public void handleRecCommand_newExpenseToListCommandWithInvalidInput_returnsNull() { ExpenseList expenseList = new ExpenseList(); - RecurringExpensesList expensesList = new RecurringExpensesList(); + RecurringExpenseLists expensesList = new RecurringExpenseLists(); String input = "rec newexpense to/ "; CommandCreator commandCreator = new RecurringExpenseCommandCreator(input, expensesList, expenseList); @@ -223,7 +223,7 @@ public void handleRecCommand_newExpenseToListCommandWithInvalidInput_returnsNull @Test public void handleRecCommand_newExpenseToListCommandWithEmptyCategory_returnsNull() { ExpenseList expenseList = new ExpenseList(); - RecurringExpensesList expensesList = new RecurringExpensesList(); + RecurringExpenseLists expensesList = new RecurringExpenseLists(); String input = "rec newexpense to/1 c/ a/200 d/ description"; CommandCreator commandCreator = new RecurringExpenseCommandCreator(input, expensesList, expenseList); @@ -235,7 +235,7 @@ public void handleRecCommand_newExpenseToListCommandWithEmptyCategory_returnsNul @Test public void handleRecCommand_newExpenseToListCommandWithEmptyAmount_returnsNull() { ExpenseList expenseList = new ExpenseList(); - RecurringExpensesList expensesList = new RecurringExpensesList(); + RecurringExpenseLists expensesList = new RecurringExpenseLists(); String input = "rec newexpense to/1 c/Entertainment a/ d/ description"; CommandCreator commandCreator = new RecurringExpenseCommandCreator(input, expensesList, expenseList); @@ -247,7 +247,7 @@ public void handleRecCommand_newExpenseToListCommandWithEmptyAmount_returnsNull( @Test public void handleRecCommand_newExpenseToListCommandWithEmptyDescription_returnsNull() { ExpenseList expenseList = new ExpenseList(); - RecurringExpensesList expensesList = new RecurringExpensesList(); + RecurringExpenseLists expensesList = new RecurringExpenseLists(); String input = "rec newexpense to/1 c/Entertainment a/200 d/"; CommandCreator commandCreator = new RecurringExpenseCommandCreator(input, expensesList, expenseList); @@ -259,7 +259,7 @@ public void handleRecCommand_newExpenseToListCommandWithEmptyDescription_returns @Test public void handleRecCommand_newExpenseToListCommandWithEmptyListNumber_returnsNull() { ExpenseList expenseList = new ExpenseList(); - RecurringExpensesList expensesList = new RecurringExpensesList(); + RecurringExpenseLists expensesList = new RecurringExpenseLists(); String input = "rec newexpense to/ c/Entertainment a/200 d/"; CommandCreator commandCreator = new RecurringExpenseCommandCreator(input, expensesList, expenseList); diff --git a/src/test/java/seedu/budgetbuddy/RecurringExpenseCommandTest.java b/src/test/java/seedu/budgetbuddy/RecurringExpenseCommandTest.java index 61628162a5..67cd1f7cf5 100644 --- a/src/test/java/seedu/budgetbuddy/RecurringExpenseCommandTest.java +++ b/src/test/java/seedu/budgetbuddy/RecurringExpenseCommandTest.java @@ -3,7 +3,7 @@ import org.junit.jupiter.api.Test; import seedu.budgetbuddy.command.RecurringExpenseCommand; import seedu.budgetbuddy.commons.ExpenseList; -import seedu.budgetbuddy.commons.RecurringExpensesList; +import seedu.budgetbuddy.commons.RecurringExpenseLists; import seedu.budgetbuddy.exception.BudgetBuddyException; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -16,19 +16,19 @@ public void execute_addRecCommand_addsTwoExpensesToExpenses() throws BudgetBuddy overallExpenses.addExpense("Entertainment", "200", "first"); overallExpenses.addExpense("Entertainment", "200", "second"); - RecurringExpensesList recurringExpensesList = new RecurringExpensesList(); - recurringExpensesList.addNewRecurringList("list1"); + RecurringExpenseLists recurringExpenseLists = new RecurringExpenseLists(); + recurringExpenseLists.addNewRecurringList("list1"); - RecurringExpenseCommand add = new RecurringExpenseCommand(1,recurringExpensesList + RecurringExpenseCommand add = new RecurringExpenseCommand(1, recurringExpenseLists ,"Entertainment", 200.00,"description", "newexpense" ); - RecurringExpenseCommand secondAdd = new RecurringExpenseCommand(1,recurringExpensesList + RecurringExpenseCommand secondAdd = new RecurringExpenseCommand(1, recurringExpenseLists ,"Entertainment", 500.00,"description", "newexpense" ); add.execute(); secondAdd.execute(); - RecurringExpenseCommand command = new RecurringExpenseCommand(1, recurringExpensesList + RecurringExpenseCommand command = new RecurringExpenseCommand(1, recurringExpenseLists , overallExpenses,"addrec"); command.execute(); @@ -44,19 +44,19 @@ public void execute_addRecCommandwithOutOfBoundsIndex_overallExpensesSizeUnchang overallExpenses.addExpense("Entertainment", "200", "first"); overallExpenses.addExpense("Entertainment", "200", "second"); - RecurringExpensesList recurringExpensesList = new RecurringExpensesList(); - recurringExpensesList.addNewRecurringList("list1"); + RecurringExpenseLists recurringExpenseLists = new RecurringExpenseLists(); + recurringExpenseLists.addNewRecurringList("list1"); - RecurringExpenseCommand add = new RecurringExpenseCommand(1,recurringExpensesList + RecurringExpenseCommand add = new RecurringExpenseCommand(1, recurringExpenseLists ,"Entertainment", 200.00,"description", "newexpense" ); - RecurringExpenseCommand secondAdd = new RecurringExpenseCommand(1,recurringExpensesList + RecurringExpenseCommand secondAdd = new RecurringExpenseCommand(1, recurringExpenseLists ,"Entertainment", 500.00,"description", "newexpense" ); add.execute(); secondAdd.execute(); - RecurringExpenseCommand command = new RecurringExpenseCommand(2, recurringExpensesList + RecurringExpenseCommand command = new RecurringExpenseCommand(2, recurringExpenseLists , overallExpenses,"addrec"); command.execute(); @@ -68,11 +68,11 @@ public void execute_addRecCommandwithOutOfBoundsIndex_overallExpensesSizeUnchang @Test public void execute_viewExpensesWithOutOfBoundsIndex_printsErrorMessageNoExceptionThrown() { - RecurringExpensesList recurringExpensesList = new RecurringExpensesList(); - recurringExpensesList.addNewRecurringList("list1"); + RecurringExpenseLists recurringExpenseLists = new RecurringExpenseLists(); + recurringExpenseLists.addNewRecurringList("list1"); - RecurringExpenseCommand command = new RecurringExpenseCommand(2, recurringExpensesList + RecurringExpenseCommand command = new RecurringExpenseCommand(2, recurringExpenseLists , "viewexpenses"); command.execute(); @@ -81,19 +81,19 @@ public void execute_viewExpensesWithOutOfBoundsIndex_printsErrorMessageNoExcepti @Test public void execute_viewExpensesWithValidIndex_printsOutputWithNoExceptionThrown() { - RecurringExpensesList recurringExpensesList = new RecurringExpensesList(); - recurringExpensesList.addNewRecurringList("list1"); + RecurringExpenseLists recurringExpenseLists = new RecurringExpenseLists(); + recurringExpenseLists.addNewRecurringList("list1"); - RecurringExpenseCommand command = new RecurringExpenseCommand(1, recurringExpensesList + RecurringExpenseCommand command = new RecurringExpenseCommand(1, recurringExpenseLists , "viewexpenses"); command.execute(); } @Test public void execute_viewEmptyListOfRecurringExpensesList_printsListWithoutExceptions() { - RecurringExpensesList recurringExpensesList = new RecurringExpensesList(); - RecurringExpenseCommand recurringExpenseCommand = new RecurringExpenseCommand(recurringExpensesList + RecurringExpenseLists recurringExpenseLists = new RecurringExpenseLists(); + RecurringExpenseCommand recurringExpenseCommand = new RecurringExpenseCommand(recurringExpenseLists , "viewlists"); recurringExpenseCommand.execute(); @@ -101,12 +101,12 @@ public void execute_viewEmptyListOfRecurringExpensesList_printsListWithoutExcept @Test public void execute_viewNonEmptyListOfRecurringExpensesList_printsListWithoutExceptions() { - RecurringExpensesList recurringExpensesList = new RecurringExpensesList(); - recurringExpensesList.addNewRecurringList("listOne"); - recurringExpensesList.addNewRecurringList("listTwo"); - recurringExpensesList.addNewRecurringList("listThree"); + RecurringExpenseLists recurringExpenseLists = new RecurringExpenseLists(); + recurringExpenseLists.addNewRecurringList("listOne"); + recurringExpenseLists.addNewRecurringList("listTwo"); + recurringExpenseLists.addNewRecurringList("listThree"); - RecurringExpenseCommand recurringExpenseCommand = new RecurringExpenseCommand(recurringExpensesList + RecurringExpenseCommand recurringExpenseCommand = new RecurringExpenseCommand(recurringExpenseLists , "viewlists"); recurringExpenseCommand.execute(); @@ -114,78 +114,78 @@ public void execute_viewNonEmptyListOfRecurringExpensesList_printsListWithoutExc @Test public void execute_addNewList_sizeOfOverallListIncreasedByOne() { - RecurringExpensesList recurringExpensesList = new RecurringExpensesList(); - recurringExpensesList.addNewRecurringList("listOne"); - recurringExpensesList.addNewRecurringList("listTwo"); - recurringExpensesList.addNewRecurringList("listThree"); + RecurringExpenseLists recurringExpenseLists = new RecurringExpenseLists(); + recurringExpenseLists.addNewRecurringList("listOne"); + recurringExpenseLists.addNewRecurringList("listTwo"); + recurringExpenseLists.addNewRecurringList("listThree"); RecurringExpenseCommand recurringExpenseCommand = new RecurringExpenseCommand("listFour" - , recurringExpensesList, "newlist"); + , recurringExpenseLists, "newlist"); recurringExpenseCommand.execute(); - assertEquals(4, recurringExpensesList.getSize()); + assertEquals(4, recurringExpenseLists.getSize()); } @Test public void execute_removeList_sizeOfOverallListReducedByOne(){ - RecurringExpensesList recurringExpensesList = new RecurringExpensesList(); - recurringExpensesList.addNewRecurringList("listOne"); - recurringExpensesList.addNewRecurringList("listTwo"); - recurringExpensesList.addNewRecurringList("listThree"); + RecurringExpenseLists recurringExpenseLists = new RecurringExpenseLists(); + recurringExpenseLists.addNewRecurringList("listOne"); + recurringExpenseLists.addNewRecurringList("listTwo"); + recurringExpenseLists.addNewRecurringList("listThree"); RecurringExpenseCommand recurringExpenseCommand = new RecurringExpenseCommand(2, - recurringExpensesList, "removelist" ); + recurringExpenseLists, "removelist" ); recurringExpenseCommand.execute(); - assertEquals(2, recurringExpensesList.getSize()); + assertEquals(2, recurringExpenseLists.getSize()); } @Test public void execute_removeListWithOutOfBoundsListNumber_sizeOfOverallListStaysSame(){ - RecurringExpensesList recurringExpensesList = new RecurringExpensesList(); - recurringExpensesList.addNewRecurringList("listOne"); - recurringExpensesList.addNewRecurringList("listTwo"); - recurringExpensesList.addNewRecurringList("listThree"); + RecurringExpenseLists recurringExpenseLists = new RecurringExpenseLists(); + recurringExpenseLists.addNewRecurringList("listOne"); + recurringExpenseLists.addNewRecurringList("listTwo"); + recurringExpenseLists.addNewRecurringList("listThree"); RecurringExpenseCommand recurringExpenseCommand = new RecurringExpenseCommand(4, - recurringExpensesList, "removelist" ); + recurringExpenseLists, "removelist" ); recurringExpenseCommand.execute(); - assertEquals(3, recurringExpensesList.getSize()); + assertEquals(3, recurringExpenseLists.getSize()); } @Test public void execute_newExpenseCommandWithInvalidCategory_sizeOfRecurringExpenseListUnchanged() { - RecurringExpensesList recurringExpensesList = new RecurringExpensesList(); - recurringExpensesList.addNewRecurringList("list1"); + RecurringExpenseLists recurringExpenseLists = new RecurringExpenseLists(); + recurringExpenseLists.addNewRecurringList("list1"); - RecurringExpenseCommand newExpenseCommand = new RecurringExpenseCommand(1,recurringExpensesList + RecurringExpenseCommand newExpenseCommand = new RecurringExpenseCommand(1, recurringExpenseLists ,"invalid", 500.00,"description", "newexpense" ); newExpenseCommand.execute(); - assertEquals(0, recurringExpensesList.getExpenseListAtListNumber(1).getExpenses().size()); + assertEquals(0, recurringExpenseLists.getExpenseListAtListNumber(1).getExpenses().size()); } @Test public void execute_newExpenseCommand_sizeOfRecurringExpenseListIncreaseByOne() { - RecurringExpensesList recurringExpensesList = new RecurringExpensesList(); - recurringExpensesList.addNewRecurringList("list1"); + RecurringExpenseLists recurringExpenseLists = new RecurringExpenseLists(); + recurringExpenseLists.addNewRecurringList("list1"); - RecurringExpenseCommand newExpenseCommand = new RecurringExpenseCommand(1,recurringExpensesList + RecurringExpenseCommand newExpenseCommand = new RecurringExpenseCommand(1, recurringExpenseLists ,"Entertainment", 500.00,"description", "newexpense" ); newExpenseCommand.execute(); - assertEquals(1, recurringExpensesList.getExpenseListAtListNumber(1).getExpenses().size()); + assertEquals(1, recurringExpenseLists.getExpenseListAtListNumber(1).getExpenses().size()); } } diff --git a/src/test/java/seedu/budgetbuddy/RecurringExpenseListsTest.java b/src/test/java/seedu/budgetbuddy/RecurringExpenseListsTest.java new file mode 100644 index 0000000000..97fca4aa8c --- /dev/null +++ b/src/test/java/seedu/budgetbuddy/RecurringExpenseListsTest.java @@ -0,0 +1,67 @@ +package seedu.budgetbuddy; + +import org.junit.jupiter.api.Test; +import seedu.budgetbuddy.commons.ExpenseList; +import seedu.budgetbuddy.commons.RecurringExpenseLists; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class RecurringExpenseListsTest { + + RecurringExpenseLists recurringExpenseLists = new RecurringExpenseLists(); + + @Test + void addNewRecurringList_addValidNewList_success() { + recurringExpenseLists.addNewRecurringList("Entertainment"); + assertEquals(1, recurringExpenseLists.getSize()); + } + + @Test + void removeList_removeValidListNumber_success() { + recurringExpenseLists.addNewRecurringList("Entertainment"); + recurringExpenseLists.addNewRecurringList("Housing"); + recurringExpenseLists.addNewRecurringList("Utilities"); + recurringExpenseLists.removeList(2); + + assertEquals(2, recurringExpenseLists.getSize()); + } + + @Test + void getSize_addThreeLists_sizeReturnedCorrect() { + recurringExpenseLists.addNewRecurringList("Entertainment"); + recurringExpenseLists.addNewRecurringList("Housing"); + recurringExpenseLists.addNewRecurringList("Utilities"); + + int expectedSize = 3; + + int obtainedSize = recurringExpenseLists.getSize(); + + assertEquals(expectedSize, obtainedSize); + } + + @Test + void getExpenseListAtListNumber_validListNumber_returnsCorrectList() { + recurringExpenseLists.addNewRecurringList("Entertainment"); + recurringExpenseLists.addNewRecurringList("Utilities"); + recurringExpenseLists.addNewRecurringList("Housing"); + ExpenseList obtainedList = recurringExpenseLists.getExpenseListAtListNumber(2); + + + assertNotNull(obtainedList); + assertEquals("Utilities", obtainedList.getName()); + } + + @Test + void printAllRecurringLists_nonEmptyList_noExceptionsThrown() { + recurringExpenseLists.addNewRecurringList("Entertainment"); + recurringExpenseLists.addNewRecurringList("Utilities"); + + recurringExpenseLists.printAllRecurringLists(); + } + + @Test + void printAllRecurringLists_emptyList_noExceptionsThrown() { + recurringExpenseLists.printAllRecurringLists(); + } +} diff --git a/src/test/java/seedu/budgetbuddy/RecurringExpensesListTest.java b/src/test/java/seedu/budgetbuddy/RecurringExpensesListTest.java deleted file mode 100644 index 38d85f6e0e..0000000000 --- a/src/test/java/seedu/budgetbuddy/RecurringExpensesListTest.java +++ /dev/null @@ -1,67 +0,0 @@ -package seedu.budgetbuddy; - -import org.junit.jupiter.api.Test; -import seedu.budgetbuddy.commons.ExpenseList; -import seedu.budgetbuddy.commons.RecurringExpensesList; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -public class RecurringExpensesListTest { - - RecurringExpensesList recurringExpensesList = new RecurringExpensesList(); - - @Test - void addNewRecurringList_addValidNewList_success() { - recurringExpensesList.addNewRecurringList("Entertainment"); - assertEquals(1, recurringExpensesList.getSize()); - } - - @Test - void removeList_removeValidListNumber_success() { - recurringExpensesList.addNewRecurringList("Entertainment"); - recurringExpensesList.addNewRecurringList("Housing"); - recurringExpensesList.addNewRecurringList("Utilities"); - recurringExpensesList.removeList(2); - - assertEquals(2, recurringExpensesList.getSize()); - } - - @Test - void getSize_addThreeLists_sizeReturnedCorrect() { - recurringExpensesList.addNewRecurringList("Entertainment"); - recurringExpensesList.addNewRecurringList("Housing"); - recurringExpensesList.addNewRecurringList("Utilities"); - - int expectedSize = 3; - - int obtainedSize = recurringExpensesList.getSize(); - - assertEquals(expectedSize, obtainedSize); - } - - @Test - void getExpenseListAtListNumber_validListNumber_returnsCorrectList() { - recurringExpensesList.addNewRecurringList("Entertainment"); - recurringExpensesList.addNewRecurringList("Utilities"); - recurringExpensesList.addNewRecurringList("Housing"); - ExpenseList obtainedList = recurringExpensesList.getExpenseListAtListNumber(2); - - - assertNotNull(obtainedList); - assertEquals("Utilities", obtainedList.getName()); - } - - @Test - void printAllRecurringLists_nonEmptyList_noExceptionsThrown() { - recurringExpensesList.addNewRecurringList("Entertainment"); - recurringExpensesList.addNewRecurringList("Utilities"); - - recurringExpensesList.printAllRecurringLists(); - } - - @Test - void printAllRecurringLists_emptyList_noExceptionsThrown() { - recurringExpensesList.printAllRecurringLists(); - } -}