This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git


The following commit(s) were added to refs/heads/master by this push:
     new f60bb59f1 Better unit test failure messages
f60bb59f1 is described below

commit f60bb59f1fa7f07861a81aeb8bc778addbba6fe4
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Thu Dec 5 15:45:56 2024 -0500

    Better unit test failure messages
---
 .../time/FastDateParser_TimeZoneStrategyTest.java  | 35 ++++++++++++----------
 1 file changed, 20 insertions(+), 15 deletions(-)

diff --git 
a/src/test/java/org/apache/commons/lang3/time/FastDateParser_TimeZoneStrategyTest.java
 
b/src/test/java/org/apache/commons/lang3/time/FastDateParser_TimeZoneStrategyTest.java
index 0093060b9..1f1f7aa7a 100644
--- 
a/src/test/java/org/apache/commons/lang3/time/FastDateParser_TimeZoneStrategyTest.java
+++ 
b/src/test/java/org/apache/commons/lang3/time/FastDateParser_TimeZoneStrategyTest.java
@@ -93,18 +93,18 @@ public class FastDateParser_TimeZoneStrategyTest extends 
AbstractLangTest {
 
     private void testTimeZoneStrategyPattern(final String languageTag, final 
String source) throws ParseException {
         final Locale locale = Locale.forLanguageTag(languageTag);
-        assumeFalse(LocaleUtils.isLanguageUndetermined(locale), () -> 
toFailureMessage(locale, languageTag));
-        assumeTrue(LocaleUtils.isAvailableLocale(locale), () -> 
toFailureMessage(locale, languageTag));
-        final TimeZone tzDefault = TimeZone.getTimeZone("Etc/UTC");
-        final FastDateParser parser = new FastDateParser("z", tzDefault, 
locale);
+        final TimeZone timeZone = TimeZone.getTimeZone("Etc/UTC");
+        assumeFalse(LocaleUtils.isLanguageUndetermined(locale), () -> 
toFailureMessage(locale, languageTag, timeZone));
+        assumeTrue(LocaleUtils.isAvailableLocale(locale), () -> 
toFailureMessage(locale, languageTag, timeZone));
+        final FastDateParser parser = new FastDateParser("z", timeZone, 
locale);
         parser.parse(source);
         testTimeZoneStrategyPattern_TimeZone_getAvailableIDs(locale);
     }
 
     private void 
testTimeZoneStrategyPattern_DateFormatSymbols_getZoneStrings(final Locale 
locale) {
         Objects.requireNonNull(locale, "locale");
-        assumeFalse(LocaleUtils.isLanguageUndetermined(locale), () -> 
toFailureMessage(locale, null));
-        assumeTrue(LocaleUtils.isAvailableLocale(locale), () -> 
toFailureMessage(locale, null));
+        assumeFalse(LocaleUtils.isLanguageUndetermined(locale), () -> 
toFailureMessage(locale, null, null));
+        assumeTrue(LocaleUtils.isAvailableLocale(locale), () -> 
toFailureMessage(locale, null, null));
 
         final String[][] zones = 
ArraySorter.sort(DateFormatSymbols.getInstance(locale).getZoneStrings(),
                 Comparator.comparing(array -> array[0]));
@@ -163,19 +163,19 @@ public class FastDateParser_TimeZoneStrategyTest extends 
AbstractLangTest {
      */
     private void testTimeZoneStrategyPattern_TimeZone_getAvailableIDs(final 
Locale locale) {
         Objects.requireNonNull(locale, "locale");
-        assumeFalse(LocaleUtils.isLanguageUndetermined(locale), () -> 
toFailureMessage(locale, null));
-        assumeTrue(LocaleUtils.isAvailableLocale(locale), () -> 
toFailureMessage(locale, null));
-
+        assumeFalse(LocaleUtils.isLanguageUndetermined(locale), () -> 
toFailureMessage(locale, null, null));
+        assumeTrue(LocaleUtils.isAvailableLocale(locale), () -> 
toFailureMessage(locale, null, null));
         for (final String id : ArraySorter.sort(TimeZone.getAvailableIDs())) {
             final TimeZone timeZone = TimeZone.getTimeZone(id);
-            final FastDateParser parser = new FastDateParser("z", timeZone, 
locale);
             final String displayName = timeZone.getDisplayName(locale);
+            final FastDateParser parser = new FastDateParser("z", timeZone, 
locale);
             try {
                 parser.parse(displayName);
             } catch (final ParseException e) {
                 // Missing "Zulu" or something else in broken JDK's GH builds?
-                fail(String.format("%s: with locale = %s, id = '%s', timeZone 
= %s, displayName = '%s', parser = '%s'", e, locale, id, timeZone, displayName,
-                        parser.toStringAll()), e);
+                // Call LocaleUtils again
+                fail(String.format("%s: with id = '%s', displayName = '%s', 
%s, parser = '%s'", e, id, displayName,
+                        toFailureMessage(locale, null, timeZone), 
parser.toStringAll()), e);
             }
         }
     }
@@ -196,6 +196,11 @@ public class FastDateParser_TimeZoneStrategyTest extends 
AbstractLangTest {
         testTimeZoneStrategyPattern("pt_PT", "Horário do Meridiano de 
Greenwich");
     }
 
+    @Test
+    public void testTimeZoneStrategyPattern_zh_HK_Hans() throws ParseException 
{
+        testTimeZoneStrategyPattern("zh_HK_#Hans", "?????????");
+    }
+
     /**
      * Breaks randomly on GitHub for Locale "sr_ME_#Cyrl", TimeZone "Etc/UTC" 
if we do not check if the Locale's language is "undetermined".
      *
@@ -212,8 +217,8 @@ public class FastDateParser_TimeZoneStrategyTest extends 
AbstractLangTest {
         testTimeZoneStrategyPattern("sr_ME_#Cyrl", "Srednje vreme po Griniču");
     }
 
-    private String toFailureMessage(final Locale locale, final String 
languageTag) {
-        return String.format("locale = %s, languageTag = '%s', 
isAvailableLocale = %s, isLanguageUndetermined = %s", languageTag, locale,
-                LocaleUtils.isAvailableLocale(locale), 
LocaleUtils.isLanguageUndetermined(locale));
+    private String toFailureMessage(final Locale locale, final String 
languageTag, final TimeZone timeZone) {
+        return String.format("locale = %s, languageTag = '%s', 
isAvailableLocale = %s, isLanguageUndetermined = %s, timeZone = %s", 
languageTag, locale,
+                LocaleUtils.isAvailableLocale(locale), 
LocaleUtils.isLanguageUndetermined(locale), TimeZones.toTimeZone(timeZone));
     }
 }

Reply via email to