Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions src/main/java/org/xpdojo/bank/Account.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
50 changes: 48 additions & 2 deletions src/test/java/org/xpdojo/bank/AccountTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));

}
}