Weaken random date formatter test assertion

`ESTestCase#testRandomDateFormatterPattern` previously asserted that
round tripping `millis -> text -> millis` wouldn't lose any precision.
But some date formats don't include the time of day so, of course, this
could lose precision. This replaces that with an assertion that
`text -> millis -> text` doesn't lose precision. Which should be true
for any sane date format. Really, we're just trying to make sure that
the random date formats that we return are *fairly* sane.
This commit is contained in:
Nik Everett 2020-08-18 16:43:22 -04:00
parent e2e3fb12bc
commit 5e723c5cc2
1 changed files with 12 additions and 1 deletions

View File

@ -204,6 +204,17 @@ public class ESTestCaseTests extends ESTestCase {
public void testRandomDateFormatterPattern() { public void testRandomDateFormatterPattern() {
DateFormatter formatter = DateFormatter.forPattern(randomDateFormatterPattern()); DateFormatter formatter = DateFormatter.forPattern(randomDateFormatterPattern());
assertThat(formatter.parseMillis(formatter.formatMillis(0)), equalTo(0L)); /*
* Make sure it doesn't crash trying to format some dates and
* that round tripping through millis doesn't lose any information.
* Interestingly, round tripping through a string *can* lose
* information because not all date formats spit out milliseconds.
* Hell, not all of them spit out the time of day at all!
* But going from text back to millis back to text should
* be fine!
*/
String formatted = formatter.formatMillis(randomLongBetween(0, 2_000_000_000_000L));
String formattedAgain = formatter.formatMillis(formatter.parseMillis(formatted));
assertThat(formattedAgain, equalTo(formatted));
} }
} }