From 83cbb3bb00084beec6151e6a4780905dc7ec1a7f Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Sun, 4 Dec 2016 19:49:14 +0100 Subject: [PATCH] The acceptance test is failing because we need to implement the print method in StatementPrinter. We always write first a test and then the implementation. In this case we have to create the test called StatementPrinterShould and from there we can create the implementation for the print method. --- .../org/craftedsw/feature/StatementPrinter.java | 8 ++++++- .../craftedsw/feature/StatementPrinterShould.java | 28 ++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/StatementPrinterShould.java 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 d09be2f..717ec3c 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,8 +4,14 @@ import java.util.List; public class StatementPrinter { + private final Console console; + + public StatementPrinter(Console console) { + this.console = console; + } + public void print(List transactions) { - throw new UnsupportedOperationException(); + console.printLine("DATE | AMOUNT | BALANCE"); } } 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 new file mode 100644 index 0000000..01bc876 --- /dev/null +++ b/TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/StatementPrinterShould.java @@ -0,0 +1,28 @@ +package org.craftedsw.feature; + +import static org.mockito.Mockito.verify; + +import java.util.Collections; +import java.util.List; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.class) +public class StatementPrinterShould { + + private static final List NO_TRANSACTIONS = Collections.emptyList(); + @Mock private Console console; + + @Test public void + always_print_the_header() { + StatementPrinter statementPrinter = new StatementPrinter(console); + + statementPrinter.print(NO_TRANSACTIONS); + + verify(console).printLine("DATE | AMOUNT | BALANCE"); + } + +} -- 2.1.4