class Account { private int balance = 0; void deposit(int amount){ balance += amount; } void withdraw(int amount){ balance -= amount ; } String getStatement() { return "" + balance; //Integer.toString(balance); // } }
- class Account {
- private int balance = 0;
- void deposit(int amount){
- balance += amount;
- }
- void withdraw(int amount){
balance = 400;- balance -= amount ;
- }
- String getStatement() {
- return "" + balance; //Integer.toString(balance); //
- }
- }
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; // TODO: Replace examples and use TDD by writing your own tests class AccountTest { @Test void deposit_adds_money_to_initial_balance() { Account account = new Account(); account.deposit(100); String statement = account.getStatement(); assertTrue(statement.contains("100")); } @Test void deposit_adds_different_amount_of_money_to_initial_balance(){ Account account = new Account(); account.deposit(200); String statement = account.getStatement(); assertTrue(statement.contains("200")); } @Test void withdraw_of_zero_balance_remains_same(){ Account account = new Account(); account.withdraw(0); String statement = account.getStatement(); assertTrue(statement.contains("0")); } @Test void withdraw_reduces_balance_by_amount_withdrawn(){ Account account = new Account(); account.deposit(500); account.withdraw(100); String statement = account.getStatement(); assertTrue(statement.contains("400")); } }
- import org.junit.jupiter.api.Test;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- import static org.junit.jupiter.api.Assertions.assertTrue;
- // TODO: Replace examples and use TDD by writing your own tests
- class AccountTest {
- @Test
- void deposit_adds_money_to_initial_balance() {
- Account account = new Account();
- account.deposit(100);
- String statement = account.getStatement();
- assertTrue(statement.contains("100"));
- }
- @Test
- void deposit_adds_different_amount_of_money_to_initial_balance(){
- Account account = new Account();
- account.deposit(200);
- String statement = account.getStatement();
- assertTrue(statement.contains("200"));
- }
- @Test
- void withdraw_of_zero_balance_remains_same(){
- Account account = new Account();
- account.withdraw(0);
- String statement = account.getStatement();
- assertTrue(statement.contains("0"));
- }
- @Test
- void withdraw_reduces_balance_by_amount_withdrawn(){
- Account account = new Account();
- account.deposit(500);
- account.withdraw(100);
- String statement = account.getStatement();
- assertTrue(statement.contains("400"));
- }
- }