From: Gustavo Martin Morcuende Date: Sun, 4 Dec 2016 17:25:48 +0000 (+0100) Subject: Tests failing for the right reason X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=13500dbf248636b2375fb264d358e39652b210a0;p=JavaForFun Tests failing for the right reason We need to keep implementing methods. --- 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 499e87e..4c5d20a 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 @@ -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 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) { diff --git a/TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/PrintStatementFeature.java b/TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/PrintStatementFeature.java index 48b180d..c11e331 100644 --- a/TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/PrintStatementFeature.java +++ b/TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/PrintStatementFeature.java @@ -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); } 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 c661acd..0c9bd9a 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 @@ -26,7 +26,7 @@ public class TransactionRepositoryShould { @Before public void initialise() { - transactionRepository = new TransactionRepository(); + transactionRepository = new TransactionRepository(clock); } @Test public void