Introduce overloaded MockPart constructor that accepts the Content-Type

Closes gh-31757
This commit is contained in:
HyeongMokJeong 2023-12-05 20:23:34 +09:00 committed by Sam Brannen
parent 462ef95904
commit a596c0e226
1 changed files with 13 additions and 0 deletions

View File

@ -70,6 +70,19 @@ public class MockPart implements Part {
this.headers.setContentDispositionFormData(name, filename);
}
/**
* Constructor for a part with a filename, byte[] content and MediaType mediaType.
* @see #getHeaders()
*/
public MockPart(String name, @Nullable String filename, @Nullable byte[] content, @Nullable MediaType mediaType) {
Assert.hasLength(name, "'name' must not be empty");
this.name = name;
this.filename = filename;
this.content = (content != null ? content : new byte[0]);
this.headers.setContentDispositionFormData(name, filename);
this.headers.setContentType(mediaType);
}
@Override
public String getName() {