|
22 | 22 | import java.nio.file.Path; |
23 | 23 | import java.util.stream.Stream; |
24 | 24 |
|
| 25 | +import org.junit.jupiter.api.Test; |
25 | 26 | import org.junit.jupiter.params.ParameterizedTest; |
26 | 27 | import org.junit.jupiter.params.provider.Arguments; |
27 | 28 | import org.junit.jupiter.params.provider.MethodSource; |
28 | 29 |
|
29 | 30 | import org.springframework.core.io.PathResource; |
30 | 31 | import org.springframework.util.MimeType; |
| 32 | +import org.springframework.util.MimeTypeUtils; |
31 | 33 |
|
32 | 34 | import static org.assertj.core.api.Assertions.assertThat; |
| 35 | +import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; |
33 | 36 |
|
34 | 37 | /** |
35 | 38 | * @author YunKui Lu |
@@ -90,4 +93,27 @@ void getMimeTypeByString(String extension, MimeType expectedMimeType) { |
90 | 93 | assertThat(mimeType).isEqualTo(expectedMimeType); |
91 | 94 | } |
92 | 95 |
|
| 96 | + @Test |
| 97 | + void getMimeTypeWithEmptyString() { |
| 98 | + assertThatThrownBy(() -> MimeTypeDetector.getMimeType("")).isInstanceOf(IllegalArgumentException.class) |
| 99 | + .hasMessageContaining("Unable to detect the MIME type"); |
| 100 | + } |
| 101 | + |
| 102 | + @Test |
| 103 | + void getMimeTypeWithMultipleDots() { |
| 104 | + // Should use the last extension |
| 105 | + MimeType expectedPng = MimeTypeUtils.IMAGE_PNG; |
| 106 | + assertThat(MimeTypeDetector.getMimeType("test.backup.png")).isEqualTo(expectedPng); |
| 107 | + assertThat(MimeTypeDetector.getMimeType(new File("archive.tar.gz.png"))).isEqualTo(expectedPng); |
| 108 | + } |
| 109 | + |
| 110 | + @Test |
| 111 | + void getMimeTypeWithQueryParameters() throws MalformedURLException { |
| 112 | + MimeType expectedJpg = MimeTypeUtils.IMAGE_JPEG; |
| 113 | + URI uri = URI.create("https://example.com/image.jpg?version=1.2&cache=false"); |
| 114 | + |
| 115 | + assertThat(MimeTypeDetector.getMimeType(uri)).isEqualTo(expectedJpg); |
| 116 | + assertThat(MimeTypeDetector.getMimeType(uri.toURL())).isEqualTo(expectedJpg); |
| 117 | + } |
| 118 | + |
93 | 119 | } |
0 commit comments