From: Gustavo Martin Morcuende Date: Sun, 4 Dec 2016 17:47:15 +0000 (+0100) Subject: Clock test working but we need to control the random part. X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=db44fcfef3b4ad57eb0e75a22e41bd26e9af811a;p=JavaForFun 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. --- 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")); + } + +}