@Nullable
    static NotificationTemplate lookupTemplateByLocale(Locale locale,
        Map<String, Optional<NotificationTemplate>> map) {
        return LanguageUtils.computeLangFromLocale(locale).stream()
            // reverse order to ensure that the variant is the first element and the default
            // is the last element
            .sorted(Collections.reverseOrder())
            .map(key -> map.getOrDefault(key, Optional.empty()))
            .filter(Optional::isPresent)
            .map(Optional::get)
            .findFirst()
            .orElse(null);
    }
@Test
    void lookupTemplateByLocaleTest() {
        Map<String, Optional<NotificationTemplate>> map = new HashMap<>();
        map.put("zh_CN", Optional.of(createNotificationTemplate("zh_CN-template")));
        map.put("zh", Optional.of(createNotificationTemplate("zh-template")));
        map.put("default", Optional.of(createNotificationTemplate("default-template")));

        var sc = ReasonNotificationTemplateSelectorImpl
            .lookupTemplateByLocale(Locale.SIMPLIFIED_CHINESE, map);
        assertThat(sc).isNotNull();
        assertThat(sc.getMetadata().getName()).isEqualTo("zh_CN-template");

        var c = ReasonNotificationTemplateSelectorImpl
            .lookupTemplateByLocale(Locale.CHINESE, map);
        assertThat(c).isNotNull();
        assertThat(c.getMetadata().getName()).isEqualTo("zh-template");

        var e = ReasonNotificationTemplateSelectorImpl
            .lookupTemplateByLocale(Locale.ENGLISH, map);
        assertThat(e).isNotNull();
        assertThat(e.getMetadata().getName()).isEqualTo("default-template");
    }