We need it in order to write tests that will work in any day.
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"));
}
}
--- /dev/null
+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"));
+ }
+
+}