StatementPrinterShould is failing for the right reasons.
authorGustavo Martin Morcuende <gustavo.martin@scmspain.com>
Sun, 4 Dec 2016 19:02:02 +0000 (20:02 +0100)
committerGustavo Martin Morcuende <gustavo.martin@scmspain.com>
Sun, 4 Dec 2016 19:02:02 +0000 (20:02 +0100)
TDD/sandromancuso/bank/src/main/java/org/craftedsw/feature/StatementPrinter.java
TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/StatementPrinterShould.java

index 717ec3c..e55d7a7 100644 (file)
@@ -4,6 +4,8 @@ import java.util.List;
 
 public class StatementPrinter {
 
+       private static final String STATEMENT_HEADER = "DATE | AMOUNT | BALANCE";
+       
        private final Console console;
 
        public StatementPrinter(Console console) {
@@ -11,7 +13,7 @@ public class StatementPrinter {
        }
 
        public void print(List<Transaction> transactions) {
-               console.printLine("DATE | AMOUNT | BALANCE");
+               console.printLine(STATEMENT_HEADER);
        }
 
 }
index 01bc876..84eea6a 100644 (file)
@@ -1,5 +1,7 @@
 package org.craftedsw.feature;
 
+import static java.util.Arrays.asList;
+import static org.mockito.Mockito.inOrder;
 import static org.mockito.Mockito.verify;
 
 import java.util.Collections;
@@ -7,6 +9,7 @@ import java.util.List;
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.mockito.InOrder;
 import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
 
@@ -25,4 +28,33 @@ public class StatementPrinterShould {
                verify(console).printLine("DATE | AMOUNT | BALANCE");
        }
 
+       @Test public void
+       print_transactions_in_reverse_chronological_order() {
+               StatementPrinter statementPrinter = new StatementPrinter(console);
+               
+               List<Transaction> transactions = transactionsContaining(
+                               deposit("01/04/2014", 1000),
+                               withdrawal("02/04/2014", 100),
+                               deposit("10/04/2014", 500)
+                               );
+               statementPrinter.print(transactions);
+               
+               InOrder inOrder = inOrder(console);
+               inOrder.verify(console).printLine("DATE | AMOUNT | BALANCE");
+               inOrder.verify(console).printLine("10/04/2014 | 500.00 | 1400.00");
+               inOrder.verify(console).printLine("02/04/2014 | -100.00 | 900.00");
+               inOrder.verify(console).printLine("01/04/2014 | 1000.00 | 1000.00");
+       }
+
+       private List<Transaction> transactionsContaining(Transaction...transactions) {
+               return asList(transactions);
+       }
+
+       private Transaction withdrawal(String date, int amount) {
+               return new Transaction(date, -amount);
+       }
+
+       private Transaction deposit(String date, int amount) {
+               return new Transaction(date, amount);
+       }
 }