Permalink
Browse files

JBEHAVE-812: Use locale-independent date format in unit tests.

  • Loading branch information...
1 parent 2008982 commit a764a1b25eb4d4357abbf45aa5ec8507e39c702c @maurotalevi maurotalevi committed Aug 13, 2012
@@ -15,6 +15,7 @@
import org.apache.commons.io.IOUtils;
import org.custommonkey.xmlunit.XMLUnit;
+import org.hamcrest.core.IsEqual;
import org.jbehave.core.failures.RestartingScenarioFailure;
import org.jbehave.core.failures.UUIDExceptionWrapper;
import org.jbehave.core.i18n.LocalizedKeywords;
@@ -96,11 +97,11 @@ public static void narrateAnInterestingStory(StoryReporter reporter, boolean wit
reporter.pending("Then I should have a balance of $30");
}
reporter.notPerformed("Then I should have $20");
- OutcomesTable outcomesTable = new OutcomesTable();
+ OutcomesTable outcomesTable = new OutcomesTable(new LocalizedKeywords(), "dd/MM/yyyy");
outcomesTable.addOutcome("I don't return all", 100.0, equalTo(50.));
Date actualDate = dateFor("01/01/2011");
Date expectedDate = dateFor("02/01/2011");
- outcomesTable.addOutcome("A wrong date", actualDate, equalTo(expectedDate));
+ outcomesTable.addOutcome("A wrong date", actualDate, new IsDateEqual(expectedDate, outcomesTable.getDateFormat()));
try {
outcomesTable.verify();
} catch (UUIDExceptionWrapper e) {
@@ -138,6 +139,23 @@ public static void narrateAnInterestingStory(StoryReporter reporter, boolean wit
reporter.afterStory(givenStory);
}
+ public static class IsDateEqual extends IsEqual<Date> {
+
+ private Date date;
+ private String dateFormat;
+
+ public IsDateEqual(Date equalArg, String dateFormat) {
+ super(equalArg);
+ this.date = equalArg;
+ this.dateFormat = dateFormat;
+ }
+
+ @Override
+ public void describeTo(org.hamcrest.Description description) {
+ description.appendValue(new SimpleDateFormat(dateFormat).format(date));
+ }
+
+ }
private static Date dateFor(String date) {
try {
return new SimpleDateFormat("dd/MM/yyyy").parse(date);
@@ -40,17 +40,17 @@
<div class="step failed">Then I should have a balance of $30 <span class="keyword failed">(FAILED)</span></div>
<pre class="failure">java.lang.Exception: Expected &lt;30&gt; got &lt;25&gt;
- at org.jbehave.core.reporters.TemplateableOutputBehaviour.narrateAnInterestingStory(TemplateableOutputBehaviour.java:94)
- at org.jbehave.core.reporters.TemplateableOutputBehaviour.shouldReportEventsToHtmlOutput(TemplateableOutputBehaviour.java:43)
+ at org.jbehave.core.reporters.TemplateableOutputBehaviour.narrateAnInterestingStory(TemplateableOutputBehaviour.java:95)
+ at org.jbehave.core.reporters.TemplateableOutputBehaviour.shouldReportEventsToHtmlOutput(TemplateableOutputBehaviour.java:44)
(reflection-invoke)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)</pre>
<div class="step notPerformed">Then I should have $20 <span class="keyword notPerformed">(NOT PERFORMED)</span></div>
<div class="step failed">Then I don't return loan <span class="keyword failed">(FAILED)</span></div>
<pre class="failure">org.jbehave.core.model.OutcomesTable$OutcomesFailed
at org.jbehave.core.model.OutcomesTable.verify(OutcomesTable.java:55)
- at org.jbehave.core.reporters.TemplateableOutputBehaviour.narrateAnInterestingStory(TemplateableOutputBehaviour.java:105)
- at org.jbehave.core.reporters.TemplateableOutputBehaviour.shouldReportEventsToHtmlOutput(TemplateableOutputBehaviour.java:43)
+ at org.jbehave.core.reporters.TemplateableOutputBehaviour.narrateAnInterestingStory(TemplateableOutputBehaviour.java:106)
+ at org.jbehave.core.reporters.TemplateableOutputBehaviour.shouldReportEventsToHtmlOutput(TemplateableOutputBehaviour.java:44)
(reflection-invoke)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)</pre>
<div class="outcomes"><table>
@@ -67,15 +67,15 @@
</tr>
<tr class="notVerified">
-<td>A wrong date</td><td>Sat Jan 01 12:00:00 CET 2011</td><td>&lt;Sun Jan 02 00:00:00 CET 2011&gt;</td><td>No</td>
+<td>A wrong date</td><td>01/01/2011</td><td>&quot;02/01/2011&quot;</td><td>No</td>
</tr>
</tbody>
</table>
<pre class="failure">org.jbehave.core.model.OutcomesTable$OutcomesFailed
at org.jbehave.core.model.OutcomesTable.verify(OutcomesTable.java:55)
- at org.jbehave.core.reporters.TemplateableOutputBehaviour.narrateAnInterestingStory(TemplateableOutputBehaviour.java:105)
- at org.jbehave.core.reporters.TemplateableOutputBehaviour.shouldReportEventsToHtmlOutput(TemplateableOutputBehaviour.java:43)
+ at org.jbehave.core.reporters.TemplateableOutputBehaviour.narrateAnInterestingStory(TemplateableOutputBehaviour.java:106)
+ at org.jbehave.core.reporters.TemplateableOutputBehaviour.shouldReportEventsToHtmlOutput(TemplateableOutputBehaviour.java:44)
(reflection-invoke)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)</pre>
</div>
@@ -113,8 +113,8 @@ <h3 class="example">Example: {money=$50, to=Paul}</h3>
<div class="step failed">Then I should have a balance of $30 <span class="keyword failed">(FAILED)</span></div>
<pre class="failure">java.lang.Exception: Expected &lt;30&gt; got &lt;25&gt;
- at org.jbehave.core.reporters.TemplateableOutputBehaviour.narrateAnInterestingStory(TemplateableOutputBehaviour.java:120)
- at org.jbehave.core.reporters.TemplateableOutputBehaviour.shouldReportEventsToHtmlOutput(TemplateableOutputBehaviour.java:43)
+ at org.jbehave.core.reporters.TemplateableOutputBehaviour.narrateAnInterestingStory(TemplateableOutputBehaviour.java:121)
+ at org.jbehave.core.reporters.TemplateableOutputBehaviour.shouldReportEventsToHtmlOutput(TemplateableOutputBehaviour.java:44)
(reflection-invoke)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)</pre>
</div> <!-- end scenario -->
@@ -44,8 +44,8 @@ Then I should... - try again
<step outcome="failed">
Then I should have a balance of $30
<failure>java.lang.Exception: Expected &lt;30&gt; got &lt;25&gt;
- at org.jbehave.core.reporters.TemplateableOutputBehaviour.narrateAnInterestingStory(TemplateableOutputBehaviour.java:94)
- at org.jbehave.core.reporters.TemplateableOutputBehaviour.shouldReportEventsToXmlOutput(TemplateableOutputBehaviour.java:58)
+ at org.jbehave.core.reporters.TemplateableOutputBehaviour.narrateAnInterestingStory(TemplateableOutputBehaviour.java:95)
+ at org.jbehave.core.reporters.TemplateableOutputBehaviour.shouldReportEventsToXmlOutput(TemplateableOutputBehaviour.java:59)
(reflection-invoke)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)</failure></step>
<step outcome="notPerformed">
@@ -55,8 +55,8 @@ Then I should have $20
Then I don&apos;t return loan
<failure>org.jbehave.core.model.OutcomesTable$OutcomesFailed
at org.jbehave.core.model.OutcomesTable.verify(OutcomesTable.java:55)
- at org.jbehave.core.reporters.TemplateableOutputBehaviour.narrateAnInterestingStory(TemplateableOutputBehaviour.java:105)
- at org.jbehave.core.reporters.TemplateableOutputBehaviour.shouldReportEventsToXmlOutput(TemplateableOutputBehaviour.java:58)
+ at org.jbehave.core.reporters.TemplateableOutputBehaviour.narrateAnInterestingStory(TemplateableOutputBehaviour.java:106)
+ at org.jbehave.core.reporters.TemplateableOutputBehaviour.shouldReportEventsToXmlOutput(TemplateableOutputBehaviour.java:59)
(reflection-invoke)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)</failure><outcomes>
<fields>
@@ -71,7 +71,7 @@ Then I don&apos;t return loan
</outcome>
<outcome>
-<value>A wrong date</value><value>Sat Jan 01 12:00:00 CET 2011</value><value>&lt;Sun Jan 02 00:00:00 CET 2011&gt;</value><value>No</value>
+<value>A wrong date</value><value>01/01/2011</value><value>&quot;02/01/2011&quot;</value><value>No</value>
</outcome>
</outcomes>
</step>
@@ -112,8 +112,8 @@ Then I give it to Paul
<step outcome="failed">
Then I should have a balance of $30
<failure>java.lang.Exception: Expected &lt;30&gt; got &lt;25&gt;
- at org.jbehave.core.reporters.TemplateableOutputBehaviour.narrateAnInterestingStory(TemplateableOutputBehaviour.java:120)
- at org.jbehave.core.reporters.TemplateableOutputBehaviour.shouldReportEventsToXmlOutput(TemplateableOutputBehaviour.java:58)
+ at org.jbehave.core.reporters.TemplateableOutputBehaviour.narrateAnInterestingStory(TemplateableOutputBehaviour.java:121)
+ at org.jbehave.core.reporters.TemplateableOutputBehaviour.shouldReportEventsToXmlOutput(TemplateableOutputBehaviour.java:59)
(reflection-invoke)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)</failure></step>
</scenario>

0 comments on commit a764a1b

Please sign in to comment.