From 74a33930224d18d6cc78a59137ceef42bcc80102 Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Sun, 4 Dec 2016 20:02:02 +0100 Subject: [PATCH] StatementPrinterShould is failing for the right reasons. --- .../org/craftedsw/feature/StatementPrinter.java | 4 ++- .../craftedsw/feature/StatementPrinterShould.java | 32 ++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) 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 717ec3c..e55d7a7 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 @@ -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 transactions) { - console.printLine("DATE | AMOUNT | BALANCE"); + console.printLine(STATEMENT_HEADER); } } 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 01bc876..84eea6a 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 @@ -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 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 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); + } } -- 2.1.4