From: Gustavo Martin Morcuende Date: Sun, 4 Dec 2016 20:30:50 +0000 (+0100) Subject: PrintStatementeFeature requires the right values for clock. X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=2dacee792de7794614efc39271dbe9d4df41625d;p=JavaForFun PrintStatementeFeature requires the right values for clock. --- 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"); } }