Skip to content

Commit

Permalink
Add assertions to TransactionList
Browse files Browse the repository at this point in the history
  • Loading branch information
Vavinan committed Mar 20, 2024
1 parent fa37ab4 commit 7a2abcd
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/budgetbuddy/transaction/TransactionList.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class TransactionList {
public TransactionList() throws IOException {
// Initialise ArrayList in the constructor
this.transactions = dataStorage.readFileContents();
assert transactions != null : "Transaction list is null after reading from file";
this.parser = new Parser();
}

Expand All @@ -49,8 +50,10 @@ public void removeTransaction(String input, Account account) throws EmptyArgumen
int size = transactions.size();
if (id >= LOWER_BOUND && id < size) {
String itemRemoved = transactions.get(id).toString();
assert itemRemoved != null : "String representation of item to remove is null";
account.setBalance(account.getBalance() - transactions.get(id).getAmount() );
transactions.remove(id);
assert transactions.size() == size - 1 : "Transaction list size did not decrease after removal";
UserInterface.printDeleteMessage(itemRemoved, account.getBalance());
} else {
throw new IndexOutOfBoundsException(size);
Expand Down Expand Up @@ -82,7 +85,9 @@ public void processTransaction(String input, Account account)
}

Transaction t = parser.parseTransaction(input, account);
assert t != null : "Parsed transaction is null";
addTransaction(t);
assert transactions.get(transactions.size() - 1) != null : "Added transaction is null after adding to the list";
String fetchData = String.valueOf(transactions.get(transactions.size() - 1));
UserInterface.printAddMessage(fetchData, account.getBalance());
}
Expand Down

0 comments on commit 7a2abcd

Please sign in to comment.