From 0f0e0f8cc753d79e2b19f26ab03a7f6639024390 Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Sun, 4 Dec 2016 21:30:50 +0100 Subject: [PATCH] PrintStatementeFeature requires the right values for clock. --- .../bank/src/main/java/org/craftedsw/feature/Console.java | 2 +- .../java/org/craftedsw/feature/PrintStatementFeature.java | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/TDD/sandromancuso/bank/src/main/java/org/craftedsw/feature/Console.java b/TDD/sandromancuso/bank/src/main/java/org/craftedsw/feature/Console.java index 64785e5..dc0c0e3 100644 --- a/TDD/sandromancuso/bank/src/main/java/org/craftedsw/feature/Console.java +++ b/TDD/sandromancuso/bank/src/main/java/org/craftedsw/feature/Console.java @@ -3,7 +3,7 @@ package org.craftedsw.feature; public class Console { public void printLine(String text) { - throw new UnsupportedOperationException(); + System.out.println(text); } } diff --git a/TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/PrintStatementFeature.java b/TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/PrintStatementFeature.java index c11e331..f8f70ec 100644 --- a/TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/PrintStatementFeature.java +++ b/TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/PrintStatementFeature.java @@ -1,5 +1,6 @@ package org.craftedsw.feature; +import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.inOrder; import org.junit.Before; @@ -24,12 +25,14 @@ public class PrintStatementFeature { // Acceptance test is using the real repository because the acceptance test // is testing the system as a whole. We are just mocking the external world (the Console) TransactionRepository transactionRepository = new TransactionRepository(clock); - StatementPrinter statementPrinter = new StatementPrinter(); + StatementPrinter statementPrinter = new StatementPrinter(console); account = new Account(transactionRepository, statementPrinter); } @Test public void print_statement_containing_all_transactions() { + given(clock.todayAsString()).willReturn("01/04/2014", "02/04/2014", "10/04/2014"); + account.deposit(1000); // No negative value, instead we use the verb withdraw. // Semantics are very important in the code!!! @@ -40,9 +43,9 @@ public class PrintStatementFeature { 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"); + 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"); } } -- 2.1.4