diff --git a/src/main/java/dev/banking/model/BankAccount.java b/src/main/java/dev/banking/model/BankAccount.java index 74b0ae0..265ec49 100644 --- a/src/main/java/dev/banking/model/BankAccount.java +++ b/src/main/java/dev/banking/model/BankAccount.java @@ -35,6 +35,7 @@ public class BankAccount { public void deposit(long amount) { lock.writeLock().lock(); try { + if (amount < 0) throw new IllegalArgumentException("Amount cannot be negative"); balance += amount; } finally { @@ -45,6 +46,8 @@ public class BankAccount { public void withdraw(long amount) { lock.writeLock().lock(); try { + if (amount < 0) throw new IllegalArgumentException("Amount cannot be negative"); + if (balance < amount) throw new IllegalArgumentException("insufficient balance"); balance -= amount; } finally { @@ -61,6 +64,8 @@ public class BankAccount { try { second.lock.writeLock().lock(); try { + if (amount < 0) throw new IllegalArgumentException("Amount cannot be negative"); + if (amount > balance) throw new IllegalArgumentException("insufficient balance"); this.balance -= amount; target.balance += amount; } finally {