From 8f4a8e23dc398dbefe05c3166adaca0012b6815b Mon Sep 17 00:00:00 2001 From: u8avatar <90271762+u8avatar@users.noreply.github.com> Date: Wed, 15 Sep 2021 13:56:14 +0200 Subject: [PATCH 1/4] MY own test --- src/main/java/org/xpdojo/bank/Account.java | 6 +++++ .../java/org/xpdojo/bank/AccountTest.java | 25 +++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/xpdojo/bank/Account.java b/src/main/java/org/xpdojo/bank/Account.java index b03854bb..2d2a5c76 100644 --- a/src/main/java/org/xpdojo/bank/Account.java +++ b/src/main/java/org/xpdojo/bank/Account.java @@ -1,4 +1,10 @@ package org.xpdojo.bank; public class Account { + + public int balance; + + public void deposit(int i) { + balance += i; + } } diff --git a/src/test/java/org/xpdojo/bank/AccountTest.java b/src/test/java/org/xpdojo/bank/AccountTest.java index 7eb4079c..6119a97a 100644 --- a/src/test/java/org/xpdojo/bank/AccountTest.java +++ b/src/test/java/org/xpdojo/bank/AccountTest.java @@ -9,8 +9,29 @@ 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)); } } From 24e0f5eadc2f472a2e3843a626826120d669a133 Mon Sep 17 00:00:00 2001 From: u8avatar <90271762+u8avatar@users.noreply.github.com> Date: Wed, 15 Sep 2021 13:57:37 +0200 Subject: [PATCH 2/4] MY own test --- .idea/runConfigurations.xml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .idea/runConfigurations.xml 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 From 776d7984118199f54874d5947bde4c46b2be1a9a Mon Sep 17 00:00:00 2001 From: u8avatar <90271762+u8avatar@users.noreply.github.com> Date: Wed, 15 Sep 2021 14:06:38 +0200 Subject: [PATCH 3/4] now withdrawing as well --- src/main/java/org/xpdojo/bank/Account.java | 4 ++++ src/test/java/org/xpdojo/bank/AccountTest.java | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/src/main/java/org/xpdojo/bank/Account.java b/src/main/java/org/xpdojo/bank/Account.java index 2d2a5c76..4207d98b 100644 --- a/src/main/java/org/xpdojo/bank/Account.java +++ b/src/main/java/org/xpdojo/bank/Account.java @@ -7,4 +7,8 @@ public class Account { public void deposit(int i) { balance += i; } + + public void withdraw(int i) { + balance -= i; + } } diff --git a/src/test/java/org/xpdojo/bank/AccountTest.java b/src/test/java/org/xpdojo/bank/AccountTest.java index 6119a97a..50f48fea 100644 --- a/src/test/java/org/xpdojo/bank/AccountTest.java +++ b/src/test/java/org/xpdojo/bank/AccountTest.java @@ -34,4 +34,11 @@ public void depositingMultipleAmounts() { account.deposit(300); assertThat(account.balance, is(400)); } + + @Test + public void withdrawAnAmount() { + Account account = new Account(); + account.withdraw(100); + assertThat(account.balance, is(-100)); + } } From 5830dff11df4c26a0c590ed9274c1759d04fc030 Mon Sep 17 00:00:00 2001 From: u8avatar <90271762+u8avatar@users.noreply.github.com> Date: Wed, 15 Sep 2021 14:18:44 +0200 Subject: [PATCH 4/4] doing a simple transfer from one account to the next --- src/main/java/org/xpdojo/bank/Account.java | 7 +++++++ src/test/java/org/xpdojo/bank/AccountTest.java | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/main/java/org/xpdojo/bank/Account.java b/src/main/java/org/xpdojo/bank/Account.java index 4207d98b..a84613e9 100644 --- a/src/main/java/org/xpdojo/bank/Account.java +++ b/src/main/java/org/xpdojo/bank/Account.java @@ -11,4 +11,11 @@ public void deposit(int 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 50f48fea..4b69a6f3 100644 --- a/src/test/java/org/xpdojo/bank/AccountTest.java +++ b/src/test/java/org/xpdojo/bank/AccountTest.java @@ -41,4 +41,22 @@ public void withdrawAnAmount() { 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)); + + } }