-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44259 from koplas/header-language-fix
Fix HttpHeaders.getAcceptableLanguages() on empty headers
- Loading branch information
Showing
2 changed files
with
30 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...mmon/runtime/src/test/java/org/jboss/resteasy/reactive/common/headers/HeaderUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |