|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2013 the original author or authors. |
| 2 | + * Copyright 2002-2015 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
27 | 27 | import org.springframework.core.convert.ConversionService;
|
28 | 28 | import org.springframework.core.convert.support.DefaultConversionService;
|
29 | 29 |
|
| 30 | +import static java.util.Collections.singletonMap; |
30 | 31 | import static org.junit.Assert.*;
|
31 | 32 |
|
32 | 33 | /**
|
| 34 | + * Unit tests for {@link MimeType}. |
| 35 | + * |
33 | 36 | * @author Arjen Poutsma
|
34 | 37 | * @author Juergen Hoeller
|
| 38 | + * @author Sam Brannen |
35 | 39 | */
|
36 | 40 | public class MimeTypeTests {
|
37 | 41 |
|
38 |
| - |
39 | 42 | @Test(expected = IllegalArgumentException.class)
|
40 | 43 | public void slashInSubtype() {
|
41 | 44 | new MimeType("text", "/");
|
@@ -85,7 +88,7 @@ public void parseQuotedCharset() {
|
85 | 88 | }
|
86 | 89 |
|
87 | 90 | @Test
|
88 |
| - public void testWithConversionService() { |
| 91 | + public void withConversionService() { |
89 | 92 | ConversionService conversionService = new DefaultConversionService();
|
90 | 93 | assertTrue(conversionService.canConvert(String.class, MimeType.class));
|
91 | 94 | MimeType mimeType = MimeType.valueOf("application/xml");
|
@@ -211,16 +214,18 @@ public void parseMimeTypeIllegalCharset() {
|
211 | 214 | MimeTypeUtils.parseMimeType("text/html; charset=foo-bar");
|
212 | 215 | }
|
213 | 216 |
|
214 |
| - // SPR-8917 |
215 |
| - |
| 217 | + /** |
| 218 | + * SPR-8917 |
| 219 | + */ |
216 | 220 | @Test
|
217 | 221 | public void parseMimeTypeQuotedParameterValue() {
|
218 | 222 | MimeType mimeType = MimeTypeUtils.parseMimeType("audio/*;attr=\"v>alue\"");
|
219 | 223 | assertEquals("\"v>alue\"", mimeType.getParameter("attr"));
|
220 | 224 | }
|
221 | 225 |
|
222 |
| - // SPR-8917 |
223 |
| - |
| 226 | + /** |
| 227 | + * SPR-8917 |
| 228 | + */ |
224 | 229 | @Test
|
225 | 230 | public void parseMimeTypeSingleQuotedParameterValue() {
|
226 | 231 | MimeType mimeType = MimeTypeUtils.parseMimeType("audio/*;attr='v>alue'");
|
@@ -249,7 +254,7 @@ public void compareTo() {
|
249 | 254 | MimeType audioBasic = new MimeType("audio", "basic");
|
250 | 255 | MimeType audio = new MimeType("audio");
|
251 | 256 | MimeType audioWave = new MimeType("audio", "wave");
|
252 |
| - MimeType audioBasicLevel = new MimeType("audio", "basic", Collections.singletonMap("level", "1")); |
| 257 | + MimeType audioBasicLevel = new MimeType("audio", "basic", singletonMap("level", "1")); |
253 | 258 |
|
254 | 259 | // equal
|
255 | 260 | assertEquals("Invalid comparison result", 0, audioBasic.compareTo(audioBasic));
|
@@ -284,16 +289,27 @@ public void compareToCaseSensitivity() {
|
284 | 289 | assertEquals("Invalid comparison result", 0, m1.compareTo(m2));
|
285 | 290 | assertEquals("Invalid comparison result", 0, m2.compareTo(m1));
|
286 | 291 |
|
287 |
| - m1 = new MimeType("audio", "basic", Collections.singletonMap("foo", "bar")); |
288 |
| - m2 = new MimeType("audio", "basic", Collections.singletonMap("Foo", "bar")); |
| 292 | + m1 = new MimeType("audio", "basic", singletonMap("foo", "bar")); |
| 293 | + m2 = new MimeType("audio", "basic", singletonMap("Foo", "bar")); |
289 | 294 | assertEquals("Invalid comparison result", 0, m1.compareTo(m2));
|
290 | 295 | assertEquals("Invalid comparison result", 0, m2.compareTo(m1));
|
291 | 296 |
|
292 |
| - m1 = new MimeType("audio", "basic", Collections.singletonMap("foo", "bar")); |
293 |
| - m2 = new MimeType("audio", "basic", Collections.singletonMap("foo", "Bar")); |
| 297 | + m1 = new MimeType("audio", "basic", singletonMap("foo", "bar")); |
| 298 | + m2 = new MimeType("audio", "basic", singletonMap("foo", "Bar")); |
294 | 299 | assertTrue("Invalid comparison result", m1.compareTo(m2) != 0);
|
295 | 300 | assertTrue("Invalid comparison result", m2.compareTo(m1) != 0);
|
296 | 301 | }
|
297 | 302 |
|
| 303 | + /** |
| 304 | + * SPR-13157 |
| 305 | + * @since 4.2 |
| 306 | + */ |
| 307 | + @Test |
| 308 | + public void equalsIsCaseInsensitiveForCharsets() { |
| 309 | + MimeType m1 = new MimeType("text", "plain", singletonMap("charset", "UTF-8")); |
| 310 | + MimeType m2 = new MimeType("text", "plain", singletonMap("charset", "utf-8")); |
| 311 | + assertEquals(m1, m2); |
| 312 | + assertEquals(m2, m1); |
| 313 | + } |
298 | 314 |
|
299 | 315 | }
|
0 commit comments