diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockMultipartFile.java b/spring-test/src/main/java/org/springframework/mock/web/MockMultipartFile.java index 359d945a1d3e..781ab7a6e48f 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockMultipartFile.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockMultipartFile.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -21,6 +21,7 @@ import java.io.IOException; import java.io.InputStream; +import org.springframework.lang.NonNull; import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.FileCopyUtils; @@ -42,10 +43,10 @@ public class MockMultipartFile implements MultipartFile { private final String name; - private String originalFilename; + private final String originalFilename; @Nullable - private String contentType; + private final String contentType; private final byte[] content; @@ -79,7 +80,7 @@ public MockMultipartFile(String name, InputStream contentStream) throws IOExcept public MockMultipartFile( String name, @Nullable String originalFilename, @Nullable String contentType, @Nullable byte[] content) { - Assert.hasLength(name, "Name must not be null"); + Assert.hasLength(name, "Name must not be empty"); this.name = name; this.originalFilename = (originalFilename != null ? originalFilename : ""); this.contentType = contentType; @@ -108,6 +109,7 @@ public String getName() { } @Override + @NonNull public String getOriginalFilename() { return this.originalFilename; } diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockMultipartFile.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockMultipartFile.java index 9250fb076c11..849731ac5a68 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockMultipartFile.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockMultipartFile.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -21,6 +21,7 @@ import java.io.IOException; import java.io.InputStream; +import org.springframework.lang.NonNull; import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.FileCopyUtils; @@ -42,10 +43,10 @@ public class MockMultipartFile implements MultipartFile { private final String name; - private String originalFilename; + private final String originalFilename; @Nullable - private String contentType; + private final String contentType; private final byte[] content; @@ -79,7 +80,7 @@ public MockMultipartFile(String name, InputStream contentStream) throws IOExcept public MockMultipartFile( String name, @Nullable String originalFilename, @Nullable String contentType, @Nullable byte[] content) { - Assert.hasLength(name, "Name must not be null"); + Assert.hasLength(name, "Name must not be empty"); this.name = name; this.originalFilename = (originalFilename != null ? originalFilename : ""); this.contentType = contentType; @@ -108,6 +109,7 @@ public String getName() { } @Override + @NonNull public String getOriginalFilename() { return this.originalFilename; }