Skip to content

Commit 7325a86

Browse files
committed
Consistent declarations and assertions in MockMultipartFile
See gh-26261 (cherry picked from commit fbd2ffd)
1 parent fe26b7d commit 7325a86

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

spring-test/src/main/java/org/springframework/mock/web/MockMultipartFile.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
2121
import java.io.IOException;
2222
import java.io.InputStream;
2323

24+
import org.springframework.lang.NonNull;
2425
import org.springframework.lang.Nullable;
2526
import org.springframework.util.Assert;
2627
import org.springframework.util.FileCopyUtils;
@@ -42,10 +43,10 @@ public class MockMultipartFile implements MultipartFile {
4243

4344
private final String name;
4445

45-
private String originalFilename;
46+
private final String originalFilename;
4647

4748
@Nullable
48-
private String contentType;
49+
private final String contentType;
4950

5051
private final byte[] content;
5152

@@ -79,7 +80,7 @@ public MockMultipartFile(String name, InputStream contentStream) throws IOExcept
7980
public MockMultipartFile(
8081
String name, @Nullable String originalFilename, @Nullable String contentType, @Nullable byte[] content) {
8182

82-
Assert.hasLength(name, "Name must not be null");
83+
Assert.hasLength(name, "Name must not be empty");
8384
this.name = name;
8485
this.originalFilename = (originalFilename != null ? originalFilename : "");
8586
this.contentType = contentType;
@@ -108,6 +109,7 @@ public String getName() {
108109
}
109110

110111
@Override
112+
@NonNull
111113
public String getOriginalFilename() {
112114
return this.originalFilename;
113115
}

spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockMultipartFile.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
2121
import java.io.IOException;
2222
import java.io.InputStream;
2323

24+
import org.springframework.lang.NonNull;
2425
import org.springframework.lang.Nullable;
2526
import org.springframework.util.Assert;
2627
import org.springframework.util.FileCopyUtils;
@@ -42,10 +43,10 @@ public class MockMultipartFile implements MultipartFile {
4243

4344
private final String name;
4445

45-
private String originalFilename;
46+
private final String originalFilename;
4647

4748
@Nullable
48-
private String contentType;
49+
private final String contentType;
4950

5051
private final byte[] content;
5152

@@ -79,7 +80,7 @@ public MockMultipartFile(String name, InputStream contentStream) throws IOExcept
7980
public MockMultipartFile(
8081
String name, @Nullable String originalFilename, @Nullable String contentType, @Nullable byte[] content) {
8182

82-
Assert.hasLength(name, "Name must not be null");
83+
Assert.hasLength(name, "Name must not be empty");
8384
this.name = name;
8485
this.originalFilename = (originalFilename != null ? originalFilename : "");
8586
this.contentType = contentType;
@@ -108,6 +109,7 @@ public String getName() {
108109
}
109110

110111
@Override
112+
@NonNull
111113
public String getOriginalFilename() {
112114
return this.originalFilename;
113115
}

0 commit comments

Comments
 (0)