MimeType.compareTo uses case-insensitive Charset (analogous to equals)

Issue: SPR-16458

(cherry picked from commit cfe7ff1)
This commit is contained in:
Juergen Hoeller
2018-02-02 13:44:07 +01:00
parent 8fda96cadb
commit 5fd761ee39
2 changed files with 55 additions and 43 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,7 +27,7 @@ import org.junit.Test;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.support.DefaultConversionService;
import static java.util.Collections.singletonMap;
import static java.util.Collections.*;
import static org.junit.Assert.*;
/**
@@ -70,7 +70,7 @@ public class MimeTypeTests {
}
@Test
public void parseCharset() throws Exception {
public void parseCharset() {
String s = "text/html; charset=iso-8859-1";
MimeType mimeType = MimeType.valueOf(s);
assertEquals("Invalid type", "text", mimeType.getType());
@@ -106,7 +106,7 @@ public class MimeTypeTests {
}
@Test
public void includes() throws Exception {
public void includes() {
MimeType textPlain = MimeTypeUtils.TEXT_PLAIN;
assertTrue("Equal types is not inclusive", textPlain.includes(textPlain));
MimeType allText = new MimeType("text");
@@ -133,7 +133,7 @@ public class MimeTypeTests {
}
@Test
public void isCompatible() throws Exception {
public void isCompatible() {
MimeType textPlain = MimeTypeUtils.TEXT_PLAIN;
assertTrue("Equal types is not compatible", textPlain.isCompatibleWith(textPlain));
MimeType allText = new MimeType("text");
@@ -160,14 +160,14 @@ public class MimeTypeTests {
}
@Test
public void testToString() throws Exception {
public void testToString() {
MimeType mimeType = new MimeType("text", "plain");
String result = mimeType.toString();
assertEquals("Invalid toString() returned", "text/plain", result);
}
@Test
public void parseMimeType() throws Exception {
public void parseMimeType() {
String s = "audio/*";
MimeType mimeType = MimeTypeUtils.parseMimeType(s);
assertEquals("Invalid type", "audio", mimeType.getType());
@@ -200,7 +200,7 @@ public class MimeTypeTests {
}
@Test(expected = InvalidMimeTypeException.class)
public void parseMimeTypeMissingTypeAndSubtype() throws Exception {
public void parseMimeTypeMissingTypeAndSubtype() {
MimeTypeUtils.parseMimeType(" ;a=b");
}
@@ -229,19 +229,13 @@ public class MimeTypeTests {
MimeTypeUtils.parseMimeType("text/html; charset=foo-bar");
}
/**
* SPR-8917
*/
@Test
@Test // SPR-8917
public void parseMimeTypeQuotedParameterValue() {
MimeType mimeType = MimeTypeUtils.parseMimeType("audio/*;attr=\"v>alue\"");
assertEquals("\"v>alue\"", mimeType.getParameter("attr"));
}
/**
* SPR-8917
*/
@Test
@Test // SPR-8917
public void parseMimeTypeSingleQuotedParameterValue() {
MimeType mimeType = MimeTypeUtils.parseMimeType("audio/*;attr='v>alue'");
assertEquals("'v>alue'", mimeType.getParameter("attr"));
@@ -253,7 +247,7 @@ public class MimeTypeTests {
}
@Test
public void parseMimeTypes() throws Exception {
public void parseMimeTypes() {
String s = "text/plain, text/html, text/x-dvi, text/x-c";
List<MimeType> mimeTypes = MimeTypeUtils.parseMimeTypes(s);
assertNotNull("No mime types returned", mimeTypes);
@@ -325,6 +319,8 @@ public class MimeTypeTests {
MimeType m2 = new MimeType("text", "plain", singletonMap("charset", "utf-8"));
assertEquals(m1, m2);
assertEquals(m2, m1);
assertEquals(0, m1.compareTo(m2));
assertEquals(0, m2.compareTo(m1));
}
}