From: Gustavo Martin Morcuende Date: Sun, 4 Dec 2016 20:11:59 +0000 (+0100) Subject: Making StatementPrinter and StatementPrinterShould look better X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=325e9cc0aee578283551d83b91980213b9b191ed;p=JavaForFun Making StatementPrinter and StatementPrinterShould look better --- diff --git a/TDD/sandromancuso/bank/src/main/java/org/craftedsw/feature/StatementPrinter.java b/TDD/sandromancuso/bank/src/main/java/org/craftedsw/feature/StatementPrinter.java index 7304ad9..513d630 100644 --- a/TDD/sandromancuso/bank/src/main/java/org/craftedsw/feature/StatementPrinter.java +++ b/TDD/sandromancuso/bank/src/main/java/org/craftedsw/feature/StatementPrinter.java @@ -18,6 +18,10 @@ public class StatementPrinter { public void print(List transactions) { console.printLine(STATEMENT_HEADER); + printStatementLines(transactions); + } + + private void printStatementLines(List transactions) { AtomicInteger runningBalance = new AtomicInteger(0); transactions.stream() .map(transaction -> statementLine(transaction, runningBalance)) diff --git a/TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/StatementPrinterShould.java b/TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/StatementPrinterShould.java index de914f6..bbace2c 100644 --- a/TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/StatementPrinterShould.java +++ b/TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/StatementPrinterShould.java @@ -7,6 +7,7 @@ import static org.mockito.Mockito.verify; import java.util.Collections; import java.util.List; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InOrder; @@ -17,21 +18,25 @@ import org.mockito.runners.MockitoJUnitRunner; public class StatementPrinterShould { private static final List NO_TRANSACTIONS = Collections.emptyList(); + + private StatementPrinter statementPrinter; + @Mock private Console console; + @Before + public void initialise() { + statementPrinter = new StatementPrinter(console); + } + @Test public void always_print_the_header() { - StatementPrinter statementPrinter = new StatementPrinter(console); - statementPrinter.print(NO_TRANSACTIONS); verify(console).printLine("DATE | AMOUNT | BALANCE"); } @Test public void - print_transactions_in_reverse_chronological_order() { - StatementPrinter statementPrinter = new StatementPrinter(console); - + print_transactions_in_reverse_chronological_order() { List transactions = transactionsContaining( deposit("01/04/2014", 1000), withdrawal("02/04/2014", 100),