Clock test working but we need to control the random part.
authorGustavo Martin Morcuende <gustavo.martin@scmspain.com>
Sun, 4 Dec 2016 17:47:15 +0000 (18:47 +0100)
committerGustavo Martin Morcuende <gustavo.martin@scmspain.com>
Sun, 4 Dec 2016 17:47:15 +0000 (18:47 +0100)
We need it in order to write tests that will work in any day.

TDD/sandromancuso/bank/src/main/java/org/craftedsw/feature/Clock.java
TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/ClockShould.java [new file with mode: 0644]

index 41d35bf..9b964b3 100644 (file)
@@ -1,9 +1,14 @@
 package org.craftedsw.feature;
 
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+
 public class Clock {
 
        public String todayAsString() {
-               throw new UnsupportedOperationException();
+               // We need to control this random stuff for our tests. :(
+               LocalDate today = LocalDate.now();
+               return today.format(DateTimeFormatter.ofPattern("dd/MM/yyyy"));
        }
 
 }
diff --git a/TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/ClockShould.java b/TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/ClockShould.java
new file mode 100644 (file)
index 0000000..24f33d5
--- /dev/null
@@ -0,0 +1,19 @@
+package org.craftedsw.feature;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+public class ClockShould {
+
+       @Test public void
+       return_todays_date_in_dd_MM_yyyy_format() {
+               Clock clock = new Clock();
+               
+               String date = clock.todayAsString();
+               
+               assertThat(date, is("04/12/2016"));
+       }
+
+}