From b854f6370d7a5288766e189214f66a922c0e98d6 Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Sun, 4 Dec 2016 21:11:59 +0100 Subject: [PATCH] Making StatementPrinter and StatementPrinterShould look better --- .../main/java/org/craftedsw/feature/StatementPrinter.java | 4 ++++ .../org/craftedsw/feature/StatementPrinterShould.java | 15 ++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) 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), -- 2.1.4