Skip to content

Commit 72d818c

Browse files
authored
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 a6e8fb3 commit 72d818c

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
@@ -111,8 +111,9 @@ public void testEqualsAndHashcode() {
111111
assertThat(DateFormatters.forPattern("YYYY").withZone(ZoneId.of("CET")), not(equalTo(DateFormatters.forPattern("YYYY"))));
112112

113113
// different locale, thus not equals
114-
assertThat(DateFormatters.forPattern("YYYY").withLocale(randomLocale(random())),
115-
not(equalTo(DateFormatters.forPattern("YYYY"))));
114+
DateFormatter f1 = DateFormatters.forPattern("YYYY").withLocale(Locale.CANADA);
115+
DateFormatter f2 = f1.withLocale(Locale.FRENCH);
116+
assertThat(f1, not(equalTo(f2)));
116117

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

0 commit comments

Comments
 (0)