From db44fcfef3b4ad57eb0e75a22e41bd26e9af811a Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Sun, 4 Dec 2016 18:47:15 +0100 Subject: [PATCH] Clock test working but we need to control the random part. We need it in order to write tests that will work in any day. --- .../src/main/java/org/craftedsw/feature/Clock.java | 7 ++++++- .../test/java/org/craftedsw/feature/ClockShould.java | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/ClockShould.java diff --git a/TDD/sandromancuso/bank/src/main/java/org/craftedsw/feature/Clock.java b/TDD/sandromancuso/bank/src/main/java/org/craftedsw/feature/Clock.java index 41d35bf..9b964b3 100644 --- a/TDD/sandromancuso/bank/src/main/java/org/craftedsw/feature/Clock.java +++ b/TDD/sandromancuso/bank/src/main/java/org/craftedsw/feature/Clock.java @@ -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 index 0000000..24f33d5 --- /dev/null +++ b/TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/ClockShould.java @@ -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")); + } + +} -- 2.1.4