@Test
public void testClosestLocale() {

  Set<Locale> list = new LinkedHashSet<Locale>(Arrays.asList(
          new Locale("es"),
          new Locale("en", "GB"),
          new Locale("en", "US"),
          new Locale("ko")));
  assertEquals("es", LocaleUtil.findClosestLocale(list, new Locale("es")).getLanguage());
  assertEquals("en_GB", LocaleUtil.findClosestLocale(list, new Locale("en", "GB")).toString());
  assertEquals("en_GB", LocaleUtil.findClosestLocale(list, new Locale("en")).toString()); // first English in list
  assertEquals("ko", LocaleUtil.findClosestLocale(list, Locale.KOREAN).getLanguage()); //ko
  assertEquals("ko", LocaleUtil.findClosestLocale(list, Locale.KOREA).toString()); //ko-KR
  // Test a case where there is no good match to the preferred language, but there is to the default language.
  assertEquals("en_GB", LocaleUtil.findClosestLocale(list, Locale.JAPANESE, Locale.CANADA).toString());
  assertEquals("en_US", LocaleUtil.findClosestLocale(list, Locale.JAPANESE, Locale.US).toString());
}