Making StatementPrinter and StatementPrinterShould look better
authorGustavo Martin Morcuende <gustavo.martin@scmspain.com>
Sun, 4 Dec 2016 20:11:59 +0000 (21:11 +0100)
committerGustavo Martin Morcuende <gustavo.martin@scmspain.com>
Sun, 4 Dec 2016 20:11:59 +0000 (21:11 +0100)
TDD/sandromancuso/bank/src/main/java/org/craftedsw/feature/StatementPrinter.java
TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/StatementPrinterShould.java

index 7304ad9..513d630 100644 (file)
@@ -18,6 +18,10 @@ public class StatementPrinter {
 
        public void print(List<Transaction> transactions) {
                console.printLine(STATEMENT_HEADER);
+               printStatementLines(transactions);      
+       }
+
+       private void printStatementLines(List<Transaction> transactions) {
                AtomicInteger runningBalance = new AtomicInteger(0);
                transactions.stream()
                                        .map(transaction -> statementLine(transaction, runningBalance))
index de914f6..bbace2c 100644 (file)
@@ -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<Transaction> 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<Transaction> transactions = transactionsContaining(
                                deposit("01/04/2014", 1000),
                                withdrawal("02/04/2014", 100),