From: Gustavo Martin Morcuende Date: Sun, 4 Dec 2016 18:49:14 +0000 (+0100) Subject: The acceptance test is failing because we need to implement the print method in State... X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=112ce5a0b0f8e1d0877c059fd4e2b87c614f6c38;p=JavaForFun 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. --- 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"); + } + +}