From: Gustavo Martin Morcuende Date: Sun, 4 Dec 2016 16:33:11 +0000 (+0100) Subject: AccountShould is failing for the right reasons. X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=2a6df957f06c0813b0b5d89a612deea5ae704ed5;p=JavaForFun AccountShould is failing for the right reasons. We can now implement the printStatement method. --- diff --git a/TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/AccountShould.java b/TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/AccountShould.java index e5d4139..f6a8cea 100644 --- a/TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/AccountShould.java +++ b/TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/AccountShould.java @@ -1,5 +1,7 @@ package org.craftedsw.feature; +import static java.util.Arrays.asList; +import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.verify; import java.util.List; @@ -14,8 +16,8 @@ import org.mockito.runners.MockitoJUnitRunner; public class AccountShould { @Mock private TransactionRepository transactionRepository; + @Mock private StatementPrinter statementPrinter; private Account account; - private StatementPrinter statementPrinter; @Before public void initialise() { @@ -38,7 +40,10 @@ public class AccountShould { @Test public void print_a_statement() { - List transactions = null; + List transactions = asList(new Transaction()); + given(transactionRepository.allTransactions()).willReturn(transactions); + + account.printStatement(); verify(statementPrinter).print(transactions); } diff --git a/TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/TransactionRepository.java b/TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/TransactionRepository.java index 08e3ef7..499e87e 100644 --- a/TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/TransactionRepository.java +++ b/TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/TransactionRepository.java @@ -1,5 +1,7 @@ package org.craftedsw.feature; +import java.util.List; + public class TransactionRepository { public void addDeposit(int amount) { @@ -10,4 +12,8 @@ public class TransactionRepository { throw new UnsupportedOperationException(); } + public List allTransactions() { + throw new UnsupportedOperationException(); + } + }