I have a simple jUnit test for DateTimeFormatterBuilder
.
At runtime it works, when some String
comes on Spring-MVC hanlder (@RequestParam
)
At testtime it fails with the same String
value.
Tested value: 25-May-2018 11:10
Method to be tested:
public void getTimeDifference(@RequestParam String startDate, @RequestParam String endDate) {
DateTimeFormatter DATE_TIME_FORMAT = new DateTimeFormatterBuilder().parseCaseInsensitive().appendPattern("dd-MMM-yyyy HH:mm").toFormatter();
LocalDateTime.parse(startDate,DATE_TIME_FORMAT);
return messages;
}
Test-Method:
@Test
public void testFormat() throws Exception {
final String startDateFormatA = "25-May-2018 11:10";
final String endDateFormatA = "25-May-2018 11:10";
assertEquals("06:00", callDbController.getTimeDifference(startDateFormatA, endDateFormatA)[1]);
}
My Test: At runtime I set a break-point and test it on Display-View:
LocalDateTime.parse("25-May-2018 11:10",DATE_TIME_FORMAT)
At testtime with the same spring-aplication-context I do the same like on runtime and it fails.
Does anyboby have ideas?
Instant
? Do you really know what anInstant
is? Its the time in UTC.Instant result = formatter.parse(lo.time, Instant::from);
. – TreadwellUS
? If not, the expected month names may be localized and not match the english ones. – Treadwell