Now we have a test for addWithdrawal
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 4 Dec 2016 17:34:45 +0000 (18:34 +0100)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 4 Dec 2016 22:30:17 +0000 (23:30 +0100)
TDD/sandromancuso/bank/src/main/java/org/craftedsw/feature/TransactionRepository.java
TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/TransactionRepositoryShould.java

index d1d07bc..b778d4f 100644 (file)
@@ -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<Transaction> allTransactions() {
index 0c9bd9a..0b1e214 100644 (file)
@@ -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<Transaction> 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);