From: Gustavo Martin Morcuende Date: Sun, 4 Dec 2016 17:34:45 +0000 (+0100) Subject: Now we have a test for addWithdrawal X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=91af093d77bb55bf36ee2b8edc19d88747ab5b36;p=JavaForFun Now we have a test for addWithdrawal --- diff --git a/TDD/sandromancuso/bank/src/main/java/org/craftedsw/feature/TransactionRepository.java b/TDD/sandromancuso/bank/src/main/java/org/craftedsw/feature/TransactionRepository.java index d1d07bc..b778d4f 100644 --- a/TDD/sandromancuso/bank/src/main/java/org/craftedsw/feature/TransactionRepository.java +++ b/TDD/sandromancuso/bank/src/main/java/org/craftedsw/feature/TransactionRepository.java @@ -19,7 +19,8 @@ public class TransactionRepository { } public void addWithdrawal(int amount) { - throw new UnsupportedOperationException(); + Transaction withdrawalTransaction = new Transaction(clock.todayAsString(), -amount); + transactions.add(withdrawalTransaction); } public List allTransactions() { diff --git a/TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/TransactionRepositoryShould.java b/TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/TransactionRepositoryShould.java index 0c9bd9a..0b1e214 100644 --- a/TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/TransactionRepositoryShould.java +++ b/TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/TransactionRepositoryShould.java @@ -39,6 +39,17 @@ public class TransactionRepositoryShould { assertThat(transactions.size(), is(1)); assertThat(transactions.get(0), is(transaction(TODAY, 100))); } + + @Test public void + create_and_store_a_withdrawal_transaction() { + given(clock.todayAsString()).willReturn(TODAY); + transactionRepository.addWithdrawal(100); + + List transactions = transactionRepository.allTransactions(); + + assertThat(transactions.size(), is(1)); + assertThat(transactions.get(0), is(transaction(TODAY, -100))); + } private Transaction transaction(String date, int amount) { return new Transaction(date, amount);