diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 00000000..797acea5 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/src/main/java/org/xpdojo/bank/Account.java b/src/main/java/org/xpdojo/bank/Account.java index b03854bb..a84613e9 100644 --- a/src/main/java/org/xpdojo/bank/Account.java +++ b/src/main/java/org/xpdojo/bank/Account.java @@ -1,4 +1,21 @@ package org.xpdojo.bank; public class Account { + + public int balance; + + public void deposit(int i) { + balance += i; + } + + public void withdraw(int i) { + balance -= i; + } + + public void transfer(int transferAmount, Account receivingAccount) { + if (transferAmount <= balance) { + this.withdraw(transferAmount); + receivingAccount.deposit(transferAmount); + } + } } diff --git a/src/test/java/org/xpdojo/bank/AccountTest.java b/src/test/java/org/xpdojo/bank/AccountTest.java index 7eb4079c..4b69a6f3 100644 --- a/src/test/java/org/xpdojo/bank/AccountTest.java +++ b/src/test/java/org/xpdojo/bank/AccountTest.java @@ -9,8 +9,54 @@ public class AccountTest { @Test - @Ignore + //@Ignore public void depositAnAmountToIncreaseTheBalance() { - assertThat("your first test isn't implemented", true, is(false)); + //assertThat("your first test isn't implemented", true, is(false)); + //arrange + Account account = new Account(); + + //act (add some money) + account.deposit(100); + //assert + assertThat(account.balance, is(100)); + } + + @Test + public void startingBalanceIsZero() { + Account account = new Account(); + assertThat(account.balance, is(0)); + } + + @Test + public void depositingMultipleAmounts() { + Account account = new Account(); + account.deposit(100); + account.deposit(300); + assertThat(account.balance, is(400)); + } + + @Test + public void withdrawAnAmount() { + Account account = new Account(); + account.withdraw(100); + assertThat(account.balance, is(-100)); + } + + @Test + public void depositAndWithdrawAnAmount() { + Account account = new Account(); + account.deposit(400); + account.withdraw(100); + assertThat(account.balance, is(300)); + } + + @Test + public void transferAnAmountFromOneAccountToAnother() { + Account account1 = new Account(), account2 = new Account(); + account1.deposit(100); + account1.transfer(100, account2); + assertThat(account1.balance, is(0)); + assertThat(account2.balance, is(100)); + } }