From 91af093d77bb55bf36ee2b8edc19d88747ab5b36 Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Sun, 4 Dec 2016 18:34:45 +0100 Subject: [PATCH] Now we have a test for addWithdrawal --- .../java/org/craftedsw/feature/TransactionRepository.java | 3 ++- .../org/craftedsw/feature/TransactionRepositoryShould.java | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) 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); -- 2.1.4