Skip to content

Commit

Permalink
Add HeaderUtil.getAcceptableLanguages test and use '*' as wildcard lo…
Browse files Browse the repository at this point in the history
…cale
  • Loading branch information
koplas committed Nov 6, 2024
1 parent 5ad6ccb commit c55d0be
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public class HeaderUtil {
private static final List<Locale> LANGUAGE_WILDCARD = List.of(Locale.ROOT);
private static final List<Locale> LANGUAGE_WILDCARD = List.of(new Locale("*"));

private static final ClassValue<RuntimeDelegate.HeaderDelegate<?>> HEADER_DELEGATE_CACHE = new ClassValue<>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.jboss.resteasy.reactive.common.headers;

import static org.junit.jupiter.api.Assertions.*;

import java.util.Locale;

import org.jboss.resteasy.reactive.common.util.MultivaluedTreeMap;
import org.junit.jupiter.api.Test;

class HeaderUtilTest {

@Test
void getAcceptableLanguages() {
MultivaluedTreeMap<String, String> emptyHeaders = new MultivaluedTreeMap<>();
Locale[] wildcardLocale = new Locale[] { new Locale("*") };
assertArrayEquals(wildcardLocale, HeaderUtil.getAcceptableLanguages(emptyHeaders).toArray());

MultivaluedTreeMap<String, String> singleLanguage = new MultivaluedTreeMap<>();
singleLanguage.add("Accept-Language", "de");
Locale[] singleLocale = new Locale[] { Locale.GERMAN };
assertArrayEquals(singleLocale, HeaderUtil.getAcceptableLanguages(singleLanguage).toArray());

MultivaluedTreeMap<String, String> multipleWeightedLanguages = new MultivaluedTreeMap<>();
multipleWeightedLanguages.add("Accept-Language", "da, en-gb;q=0.8, en;q=0.7");
Locale[] multipleWeightedLocales = new Locale[] { new Locale("da"), Locale.UK, Locale.ENGLISH };
assertArrayEquals(multipleWeightedLocales, HeaderUtil.getAcceptableLanguages(multipleWeightedLanguages).toArray());
}
}

0 comments on commit c55d0be

Please sign in to comment.