HawkbitCommonUtil { public static Locale getLocaleToBeUsed(final UiProperties.Localization localizationProperties, final Locale desiredLocale) { final List<Locale> availableLocals = localizationProperties.getAvailableLocals(); if (availableLocals.contains(desiredLocale)) { return desiredLocale; } return localizationProperties.getDefaultLocal(); } private  HawkbitCommonUtil(); static String concatStrings(final String delimiter, final String... texts); static String getFormattedNameVersion(final String name, final String version); static Locale getCurrentLocale(); static Locale getLocaleToBeUsed(final UiProperties.Localization localizationProperties,
            final Locale desiredLocale); static void initLocalization(final UI ui, final Localization localizationProperties,
            final VaadinMessageSource i18n); static List<T> getEntitiesByPageableProvider(final Function<Pageable, Slice<T>> provider); static boolean atLeastOnePresent(final Long count); static Long getSumOf(final Collection<Long> countList); static String sanitizeHtml(final String html); static final String SP_STRING_PIPE; }
@Test @Description("If a default locale is set in the environment, then it should take perceedence over requested browser locale") public void getLocaleToBeUsedShouldReturnDefaultLocalIfSet() { final UiProperties.Localization localizationProperties = Mockito.mock(UiProperties.Localization.class); doReturn(Locale.GERMAN).when(localizationProperties).getDefaultLocal(); final Locale localeToBeUsed = HawkbitCommonUtil.getLocaleToBeUsed(localizationProperties, Locale.CHINESE); assertEquals(Locale.GERMAN, localeToBeUsed); }
@Test @Description("If no default locale is set in the environment, then the requested browser locale may be used if supported") public void getLocaleToBeUsedShouldReturnRequestedLocalIfSupportedAndNoDefaultIsSet() { final UiProperties.Localization localizationProperties = Mockito.mock(UiProperties.Localization.class); doReturn(null).when(localizationProperties).getDefaultLocal(); doReturn(Arrays.asList(Locale.ENGLISH, Locale.GERMAN)).when(localizationProperties).getAvailableLocals(); final Locale localeToBeUsed = HawkbitCommonUtil.getLocaleToBeUsed(localizationProperties, Locale.GERMAN); assertEquals(Locale.GERMAN, localeToBeUsed); }