LocaleUtil { public static Optional<Locale> getExactLocaleMatch(VaadinRequest request, List<Locale> providedLocales) { Locale foundLocale = null; Enumeration<Locale> locales = request.getLocales(); while (locales.hasMoreElements()) { Locale locale = locales.nextElement(); if (providedLocales.contains(locale)) { foundLocale = locale; break; } } return Optional.ofNullable(foundLocale); } private  LocaleUtil(); static Optional<Locale> getExactLocaleMatch(VaadinRequest request,
            List<Locale> providedLocales); static Optional<Locale> getLocaleMatchByLanguage(VaadinRequest request,
            List<Locale> providedLocales);  }
@Test public void exact_match_provided_matches() { Optional<Locale> exactLocaleMatch = LocaleUtil.getExactLocaleMatch(request, Arrays.asList(Locale.ENGLISH, LOCALE_EN)); Assert.assertEquals( "Found wrong locale event though an exact match should have been available.", LOCALE_EN, exactLocaleMatch.get()); }
@Test public void no_exact_match_returns_null() { Optional<Locale> exactLocaleMatch = LocaleUtil.getExactLocaleMatch(request, Arrays.asList(Locale.ENGLISH)); Assert.assertFalse( "Found locale event though none should have been available.", exactLocaleMatch.isPresent()); }