Skip to content

Commit

Permalink
Use InvalidMimeTypeException in MimeTypeUtils#sortBySpecificity
Browse files Browse the repository at this point in the history
Closes gh-31254
  • Loading branch information
rstoyanchev committed Nov 15, 2023
1 parent 19e8ed1 commit 05c3ffb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,9 @@ public static String toString(Collection<? extends MimeType> mimeTypes) {
*/
public static <T extends MimeType> void sortBySpecificity(List<T> mimeTypes) {
Assert.notNull(mimeTypes, "'mimeTypes' must not be null");
Assert.isTrue(mimeTypes.size() <= 50, "Too many elements");
if (mimeTypes.size() >= 50) {
throw new InvalidMimeTypeException(mimeTypes.toString(), "Too many elements");
}

bubbleSort(mimeTypes, MimeType::isLessSpecific);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,9 @@ void sortBySpecificity() {
MimeType audioWave = new MimeType("audio", "wave");
MimeType audioBasicLevel = new MimeType("audio", "basic", singletonMap("level", "1"));

List<MimeType> mimeTypes = new ArrayList<>(List.of(MimeTypeUtils.ALL, audio, audioWave, audioBasic,
audioBasicLevel));
List<MimeType> mimeTypes = new ArrayList<>(
List.of(MimeTypeUtils.ALL, audio, audioWave, audioBasic, audioBasicLevel));

MimeTypeUtils.sortBySpecificity(mimeTypes);

assertThat(mimeTypes).containsExactly(audioWave, audioBasicLevel, audioBasic, audio, MimeTypeUtils.ALL);
Expand Down

0 comments on commit 05c3ffb

Please sign in to comment.