Tests failing for the right reason
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 4 Dec 2016 17:25:48 +0000 (18:25 +0100)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 4 Dec 2016 22:30:10 +0000 (23:30 +0100)
We need to keep implementing methods.

TDD/sandromancuso/bank/src/main/java/org/craftedsw/feature/TransactionRepository.java
TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/PrintStatementFeature.java
TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/TransactionRepositoryShould.java

index 499e87e..4c5d20a 100644 (file)
@@ -1,11 +1,20 @@
 package org.craftedsw.feature;
 
+import java.util.ArrayList;
 import java.util.List;
 
 public class TransactionRepository {
 
+       private final Clock clock;
+       private List<Transaction> transactions = new ArrayList<>();
+
+       public TransactionRepository(Clock clock) {
+               this.clock = clock;
+       }
+
        public void addDeposit(int amount) {
-               throw new UnsupportedOperationException();
+               Transaction depositTransaction = new Transaction(clock.todayAsString(), amount);
+               transactions.add(depositTransaction);
        }
 
        public void addWithdrawal(int amount) {
index 48b180d..c11e331 100644 (file)
@@ -13,13 +13,17 @@ import org.mockito.runners.MockitoJUnitRunner;
 public class PrintStatementFeature {
 
        @Mock private Console console;
+       // We treat Clock as an external thing. We need to control it,
+       // that is why we mock it.
+       @Mock private Clock clock;
+       
        private Account account;
        
        @Before
        public void initialise() {
                // Acceptance test is using the real repository because the acceptance test
                // is testing the system as a whole. We are just mocking the external world (the Console)
-               TransactionRepository transactionRepository = new TransactionRepository(); 
+               TransactionRepository transactionRepository = new TransactionRepository(clock); 
                StatementPrinter statementPrinter = new StatementPrinter();
                account = new Account(transactionRepository, statementPrinter);
        }
index c661acd..0c9bd9a 100644 (file)
@@ -26,7 +26,7 @@ public class TransactionRepositoryShould {
        
        @Before
        public void initialise() {
-               transactionRepository = new TransactionRepository();
+               transactionRepository = new TransactionRepository(clock);
        }
 
        @Test public void