### Question:
LocaleFilter { public static <T> Entry<Locale, T> findClosest(Locale filter, Map<Locale, T> values) { return findClosest(filter, values, null); }  static Optional<Entry<Locale, T>> findClosestOptional(Locale filter, Map<Locale, T> values); static Entry<Locale, T> findClosest(Locale filter, Map<Locale, T> values); static Optional<Entry<Locale, T>> findClosestOptional(Locale filter, Map<Locale, T> values, Locale fallback); static Entry<Locale, T> findClosest(Locale filter, Map<Locale, T> values, Locale fallback);  }### Answer:
@Test public void findClosestExact() { Map<Locale, String> valueMap = new HashMap<>(); valueMap.put(Locale.GERMANY, "Moin moin"); valueMap.put(Locale.GERMAN, "Hallo"); valueMap.put(Locale.FRANCE, "Salute"); Map.Entry<Locale, String> result = LocaleFilter.findClosest(Locale.GERMANY, valueMap); assertThat(result, notNullValue()); assertThat(result.getValue(), equalTo("Moin moin")); }
@Test public void findClosestViaLanguage() { Map<Locale, String> valueMap = new HashMap<>(); valueMap.put(Locale.GERMANY, "Moin moin"); valueMap.put(Locale.FRANCE, "Salute"); Map.Entry<Locale, String> result = LocaleFilter.findClosest(Locale.GERMAN, valueMap); assertThat(result, notNullValue()); assertThat(result.getValue(), equalTo("Moin moin")); }
@Test public void findClosestViaFallbackExact() { Map<Locale, String> valueMap = new HashMap<>(); valueMap.put(Locale.GERMANY, "Moin moin"); valueMap.put(Locale.GERMAN, "Hallo"); valueMap.put(Locale.FRANCE, "Salute"); Map.Entry<Locale, String> result = LocaleFilter.findClosest(Locale.CHINESE, valueMap, Locale.GERMANY); assertThat(result, notNullValue()); assertThat(result.getValue(), equalTo("Moin moin")); }
@Test public void findClosestViaFallbackLanguage() { Map<Locale, String> valueMap = new HashMap<>(); valueMap.put(Locale.GERMANY, "Moin moin"); valueMap.put(Locale.FRANCE, "Salute"); Map.Entry<Locale, String> result = LocaleFilter.findClosest(Locale.CHINESE, valueMap, Locale.GERMAN); assertThat(result, notNullValue()); assertThat(result.getValue(), equalTo("Moin moin")); }
@Test public void findClosestViaFallbackRootLanguage() { Map<Locale, String> valueMap = new HashMap<>(); valueMap.put(Locale.GERMANY, "Moin moin"); valueMap.put(Locale.ROOT, "Hello"); Map.Entry<Locale, String> result = LocaleFilter.findClosest(Locale.CHINESE, valueMap, Locale.FRENCH); assertThat(result, notNullValue()); assertThat(result.getValue(), equalTo("Hello")); }