JAVA-32054 Upgrade spring-mvc-file to Spring Boot 3 (#16218)

This commit is contained in:
timis1 2024-03-30 20:51:01 +02:00 committed by GitHub
parent 6ff926e003
commit 39f3c493ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 27 deletions

View File

@ -10,9 +10,9 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId>
<artifactId>parent-boot-3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-boot-2</relativePath>
<relativePath>../../parent-boot-3</relativePath>
</parent>
<dependencies>
@ -25,26 +25,7 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
</dependencies>
<build>
<finalName>spring-mvc-file</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.baeldung.Application</mainClass>
<layout>JAR</layout>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -41,12 +41,12 @@ public class CustomMultipartFile implements MultipartFile {
}
@Override
public byte[] getBytes() throws IOException {
public byte[] getBytes() {
return input;
}
@Override
public InputStream getInputStream() throws IOException {
public InputStream getInputStream() {
return new ByteArrayInputStream(input);
}

View File

@ -9,7 +9,7 @@ import org.springframework.mock.web.MockMultipartFile;
class CustomMultipartFileUnitTest {
@Test
void whenProvidingByteArray_thenMultipartFileCreated() throws IOException {
void whenProvidingByteArray_thenMultipartFileCreated() {
byte[] inputArray = "Test String".getBytes();
CustomMultipartFile customMultipartFile = new CustomMultipartFile(inputArray);
Assertions.assertFalse(customMultipartFile.isEmpty());
@ -18,21 +18,21 @@ class CustomMultipartFileUnitTest {
}
@Test
void whenProvidingEmptyByteArray_thenMockMultipartFileIsEmpty() throws IOException {
void whenProvidingEmptyByteArray_thenMockMultipartFileIsEmpty() {
byte[] inputArray = "".getBytes();
MockMultipartFile mockMultipartFile = new MockMultipartFile("tempFileName", inputArray);
Assertions.assertTrue(mockMultipartFile.isEmpty());
}
@Test
void whenProvidingNullByteArray_thenMockMultipartFileIsEmpty() throws IOException {
void whenProvidingNullByteArray_thenMockMultipartFileIsEmpty() {
byte[] inputArray = null;
MockMultipartFile mockMultipartFile = new MockMultipartFile("tempFileName", inputArray);
Assertions.assertTrue(mockMultipartFile.isEmpty());
}
@Test
void whenProvidingByteArray_thenMultipartFileInputSizeMatches() throws IOException {
void whenProvidingByteArray_thenMultipartFileInputSizeMatches() {
byte[] inputArray = "Testing String".getBytes();
CustomMultipartFile customMultipartFile = new CustomMultipartFile(inputArray);
Assertions.assertEquals(inputArray.length, customMultipartFile.getSize());