From 0b4be58024084830744858bf324de98886855698 Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Sun, 4 Dec 2016 16:19:08 +0100 Subject: [PATCH] Now we have test expecting some result, it is now failing for the right reasons. We are using the double loop of unit testing: * First, start with an acceptance test. * Second, once the acceptance test is failing for the right reason then you go to the inner loop of TDD (the unit test) we can start unit testing our code. Once we have all the classes under unit tests our accpetance test should go green. --- .../bank/src/main/java/org/craftedsw/feature/Account.java | 7 ------- .../java/org/craftedsw/feature/PrintStatementFeature.java | 14 +++++++------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/TDD/sandromancuso/bank/src/main/java/org/craftedsw/feature/Account.java b/TDD/sandromancuso/bank/src/main/java/org/craftedsw/feature/Account.java index 348f65f..fb43a95 100644 --- a/TDD/sandromancuso/bank/src/main/java/org/craftedsw/feature/Account.java +++ b/TDD/sandromancuso/bank/src/main/java/org/craftedsw/feature/Account.java @@ -3,18 +3,11 @@ package org.craftedsw.feature; public class Account { public void deposit(int amount) { - // IDE configuration for always throwing this exception - // when automatically creating methods. - // In this way, when running our unit tests we are - // able to find out what is not yet implemented. - throw new UnsupportedOperationException(); } public void withdraw(int amount) { - throw new UnsupportedOperationException(); } public void printStatement() { - throw new UnsupportedOperationException(); } } 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 d65b95a..c2c164a 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,10 +1,11 @@ package org.craftedsw.feature; -import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.inOrder; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; @@ -29,12 +30,11 @@ public class PrintStatementFeature { account.printStatement(); - // console will be some kind of interface that will represent my class console - // (always using interfaces for external stuff, like databases, etc, etc) - verify(console).printLine("DATE | AMOUNT | BALANCE"); - verify(console).printLine("10 / 04 / 2014 | 500.00 | 1400.00"); - verify(console).printLine("02 / 04 / 2014 | -100.00 | 900.00"); - verify(console).printLine("01 / 04 / 2014 | 1000.00 | 1000.00"); + 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"); } } -- 2.1.4