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=90c02f341df98291f78ce3d9d8fa58fb145d7ecf;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