Skip to content

Commit 2fd0887

Browse files
rjernstspinscale
authored andcommitted
Tests: Fix DateFormatter equals tests with locale (#34435)
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
1 parent 7591555 commit 2fd0887

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

server/src/test/java/org/elasticsearch/common/time/DateFormattersTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,9 @@ public void testEqualsAndHashcode() {
175175
assertThat(DateFormatters.forPattern("YYYY").withZone(ZoneId.of("CET")), not(equalTo(DateFormatters.forPattern("YYYY"))));
176176

177177
// different locale, thus not equals
178-
assertThat(DateFormatters.forPattern("YYYY").withLocale(randomLocale(random())),
179-
not(equalTo(DateFormatters.forPattern("YYYY"))));
178+
DateFormatter f1 = DateFormatters.forPattern("YYYY").withLocale(Locale.CANADA);
179+
DateFormatter f2 = f1.withLocale(Locale.FRENCH);
180+
assertThat(f1, not(equalTo(f2)));
180181

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

0 commit comments

Comments
 (0)