Now we have test expecting some result, it is now failing for the right reasons.
authorGustavo Martin Morcuende <gustavo.martin@scmspain.com>
Sun, 4 Dec 2016 15:19:08 +0000 (16:19 +0100)
committerGustavo Martin Morcuende <gustavo.martin@scmspain.com>
Sun, 4 Dec 2016 15:24:34 +0000 (16:24 +0100)
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.

TDD/sandromancuso/bank/src/main/java/org/craftedsw/feature/Account.java
TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/PrintStatementFeature.java

index 348f65f..fb43a95 100644 (file)
@@ -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();
        }
 }
index d65b95a..c2c164a 100644 (file)
@@ -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");
        }
 
 }