Revisit MockPart constructors
Issue: SPR-15854
This commit is contained in:
@@ -27,13 +27,15 @@ import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
/**
|
||||
* Mock implementation of {@code javax.servlet.http.Part}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 5.0
|
||||
* @author Juergen Hoeller
|
||||
* @since 4.3.12
|
||||
* @see MockHttpServletRequest#addPart
|
||||
* @see MockMultipartFile
|
||||
*/
|
||||
public class MockPart implements Part {
|
||||
|
||||
@@ -55,19 +57,11 @@ public class MockPart implements Part {
|
||||
this(name, null, content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for a part with a filename and streamed content.
|
||||
* @see #getHeaders()
|
||||
*/
|
||||
public MockPart(String name, @Nullable String filename, InputStream content) throws IOException {
|
||||
this(name, filename, FileCopyUtils.copyToByteArray(content));
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for a part with a filename and byte[] content.
|
||||
* @see #getHeaders()
|
||||
*/
|
||||
private MockPart(String name, @Nullable String filename, @Nullable byte[] content) {
|
||||
public MockPart(String name, @Nullable String filename, @Nullable byte[] content) {
|
||||
Assert.hasLength(name, "Name must not be null");
|
||||
this.name = name;
|
||||
this.filename = filename;
|
||||
@@ -104,6 +98,16 @@ public class MockPart implements Part {
|
||||
return new ByteArrayInputStream(this.content);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(String fileName) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete() throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getHeader(String name) {
|
||||
@@ -122,20 +126,11 @@ public class MockPart implements Part {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@link HttpHeaders} backing header related accessor methods.
|
||||
* Return the {@link HttpHeaders} backing header related accessor methods,
|
||||
* allowing for populating selected header entries.
|
||||
*/
|
||||
public HttpHeaders getHeaders() {
|
||||
public final HttpHeaders getHeaders() {
|
||||
return this.headers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(String fileName) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete() throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user