Skip to content

Commit

Permalink
Tests: Fix DateFormatter equals tests with locale (#34435)
Browse files Browse the repository at this point in the history
This commit removes randomization of locale for DateFormatter equals
tests, instead using explicit locales. The test framework already
randomizes locales, so the random choice of the second locale can
sometimes be equal to the already chosen locale. Randomization also does
not provide any extra protection, as the equality of DateFormatter does
not implement equality of the locales itself.

closes #34337
  • Loading branch information
rjernst authored and spinscale committed Nov 2, 2018
1 parent 0ae3187 commit 80c3daf
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,9 @@ public void testEqualsAndHashcode() {
assertThat(DateFormatters.forPattern("YYYY").withZone(ZoneId.of("CET")), not(equalTo(DateFormatters.forPattern("YYYY"))));

// different locale, thus not equals
assertThat(DateFormatters.forPattern("YYYY").withLocale(randomLocale(random())),
not(equalTo(DateFormatters.forPattern("YYYY"))));
DateFormatter f1 = DateFormatters.forPattern("YYYY").withLocale(Locale.CANADA);
DateFormatter f2 = f1.withLocale(Locale.FRENCH);
assertThat(f1, not(equalTo(f2)));

// different pattern, thus not equals
assertThat(DateFormatters.forPattern("YYYY"), not(equalTo(DateFormatters.forPattern("YY"))));
Expand Down

0 comments on commit 80c3daf

Please sign in to comment.