Skip to content

Commit f60bb59

Browse files
committed
Better unit test failure messages
1 parent d2f8cac commit f60bb59

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

src/test/java/org/apache/commons/lang3/time/FastDateParser_TimeZoneStrategyTest.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,18 @@ public void testTimeZoneStrategy_TimeZone(final Locale locale) {
9393

9494
private void testTimeZoneStrategyPattern(final String languageTag, final String source) throws ParseException {
9595
final Locale locale = Locale.forLanguageTag(languageTag);
96-
assumeFalse(LocaleUtils.isLanguageUndetermined(locale), () -> toFailureMessage(locale, languageTag));
97-
assumeTrue(LocaleUtils.isAvailableLocale(locale), () -> toFailureMessage(locale, languageTag));
98-
final TimeZone tzDefault = TimeZone.getTimeZone("Etc/UTC");
99-
final FastDateParser parser = new FastDateParser("z", tzDefault, locale);
96+
final TimeZone timeZone = TimeZone.getTimeZone("Etc/UTC");
97+
assumeFalse(LocaleUtils.isLanguageUndetermined(locale), () -> toFailureMessage(locale, languageTag, timeZone));
98+
assumeTrue(LocaleUtils.isAvailableLocale(locale), () -> toFailureMessage(locale, languageTag, timeZone));
99+
final FastDateParser parser = new FastDateParser("z", timeZone, locale);
100100
parser.parse(source);
101101
testTimeZoneStrategyPattern_TimeZone_getAvailableIDs(locale);
102102
}
103103

104104
private void testTimeZoneStrategyPattern_DateFormatSymbols_getZoneStrings(final Locale locale) {
105105
Objects.requireNonNull(locale, "locale");
106-
assumeFalse(LocaleUtils.isLanguageUndetermined(locale), () -> toFailureMessage(locale, null));
107-
assumeTrue(LocaleUtils.isAvailableLocale(locale), () -> toFailureMessage(locale, null));
106+
assumeFalse(LocaleUtils.isLanguageUndetermined(locale), () -> toFailureMessage(locale, null, null));
107+
assumeTrue(LocaleUtils.isAvailableLocale(locale), () -> toFailureMessage(locale, null, null));
108108

109109
final String[][] zones = ArraySorter.sort(DateFormatSymbols.getInstance(locale).getZoneStrings(),
110110
Comparator.comparing(array -> array[0]));
@@ -163,19 +163,19 @@ private void testTimeZoneStrategyPattern_DateFormatSymbols_getZoneStrings(final
163163
*/
164164
private void testTimeZoneStrategyPattern_TimeZone_getAvailableIDs(final Locale locale) {
165165
Objects.requireNonNull(locale, "locale");
166-
assumeFalse(LocaleUtils.isLanguageUndetermined(locale), () -> toFailureMessage(locale, null));
167-
assumeTrue(LocaleUtils.isAvailableLocale(locale), () -> toFailureMessage(locale, null));
168-
166+
assumeFalse(LocaleUtils.isLanguageUndetermined(locale), () -> toFailureMessage(locale, null, null));
167+
assumeTrue(LocaleUtils.isAvailableLocale(locale), () -> toFailureMessage(locale, null, null));
169168
for (final String id : ArraySorter.sort(TimeZone.getAvailableIDs())) {
170169
final TimeZone timeZone = TimeZone.getTimeZone(id);
171-
final FastDateParser parser = new FastDateParser("z", timeZone, locale);
172170
final String displayName = timeZone.getDisplayName(locale);
171+
final FastDateParser parser = new FastDateParser("z", timeZone, locale);
173172
try {
174173
parser.parse(displayName);
175174
} catch (final ParseException e) {
176175
// Missing "Zulu" or something else in broken JDK's GH builds?
177-
fail(String.format("%s: with locale = %s, id = '%s', timeZone = %s, displayName = '%s', parser = '%s'", e, locale, id, timeZone, displayName,
178-
parser.toStringAll()), e);
176+
// Call LocaleUtils again
177+
fail(String.format("%s: with id = '%s', displayName = '%s', %s, parser = '%s'", e, id, displayName,
178+
toFailureMessage(locale, null, timeZone), parser.toStringAll()), e);
179179
}
180180
}
181181
}
@@ -196,6 +196,11 @@ public void testTimeZoneStrategyPatternPortugal() throws ParseException {
196196
testTimeZoneStrategyPattern("pt_PT", "Horário do Meridiano de Greenwich");
197197
}
198198

199+
@Test
200+
public void testTimeZoneStrategyPattern_zh_HK_Hans() throws ParseException {
201+
testTimeZoneStrategyPattern("zh_HK_#Hans", "?????????");
202+
}
203+
199204
/**
200205
* Breaks randomly on GitHub for Locale "sr_ME_#Cyrl", TimeZone "Etc/UTC" if we do not check if the Locale's language is "undetermined".
201206
*
@@ -212,8 +217,8 @@ public void testTimeZoneStrategyPatternSuriname() throws ParseException {
212217
testTimeZoneStrategyPattern("sr_ME_#Cyrl", "Srednje vreme po Griniču");
213218
}
214219

215-
private String toFailureMessage(final Locale locale, final String languageTag) {
216-
return String.format("locale = %s, languageTag = '%s', isAvailableLocale = %s, isLanguageUndetermined = %s", languageTag, locale,
217-
LocaleUtils.isAvailableLocale(locale), LocaleUtils.isLanguageUndetermined(locale));
220+
private String toFailureMessage(final Locale locale, final String languageTag, final TimeZone timeZone) {
221+
return String.format("locale = %s, languageTag = '%s', isAvailableLocale = %s, isLanguageUndetermined = %s, timeZone = %s", languageTag, locale,
222+
LocaleUtils.isAvailableLocale(locale), LocaleUtils.isLanguageUndetermined(locale), TimeZones.toTimeZone(timeZone));
218223
}
219224
}

0 commit comments

Comments
 (0)