Skip to content

Commit

Permalink
Polish contribution
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Dec 5, 2023
1 parent a596c0e commit db48813
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2023 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.
Expand Down Expand Up @@ -63,24 +63,21 @@ public MockPart(String name, @Nullable byte[] content) {
* @see #getHeaders()
*/
public MockPart(String name, @Nullable String filename, @Nullable byte[] content) {
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(name, filename, content, null);
}

/**
* Constructor for a part with a filename, byte[] content and MediaType mediaType.
* Constructor for a part with a filename, byte[] content, and content type.
* @since 6.1.2
* @see #getHeaders()
*/
public MockPart(String name, @Nullable String filename, @Nullable byte[] content, @Nullable MediaType mediaType) {
public MockPart(String name, @Nullable String filename, @Nullable byte[] content, @Nullable MediaType contentType) {
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);
this.headers.setContentType(contentType);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ void mockMultiPartHttpServletRequestWithMixedData() {
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
request.addFile(new MockMultipartFile("file", "myOrigFilename", MediaType.TEXT_PLAIN_VALUE, "myContent2".getBytes()));

MockPart metadataPart = new MockPart("metadata", "{\"foo\": \"bar\"}".getBytes());
metadataPart.getHeaders().setContentType(MediaType.APPLICATION_JSON);
MockPart metadataPart = new MockPart("metadata", null, "{\"foo\": \"bar\"}".getBytes(), MediaType.APPLICATION_JSON);
request.addPart(metadataPart);

HttpHeaders fileHttpHeaders = request.getMultipartHeaders("file");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2023 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.
Expand Down Expand Up @@ -34,7 +34,7 @@
*
* @author Rossen Stoyanchev
* @author Juergen Hoeller
* @since 3.1
* @since 4.3.12
* @see MockHttpServletRequest#addPart
* @see MockMultipartFile
*/
Expand Down Expand Up @@ -63,11 +63,21 @@ public MockPart(String name, @Nullable byte[] content) {
* @see #getHeaders()
*/
public MockPart(String name, @Nullable String filename, @Nullable byte[] content) {
this(name, filename, content, null);
}

/**
* Constructor for a part with a filename, byte[] content, and content type.
* @since 6.1.2
* @see #getHeaders()
*/
public MockPart(String name, @Nullable String filename, @Nullable byte[] content, @Nullable MediaType contentType) {
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(contentType);
}


Expand Down

0 comments on commit db48813

Please sign in to comment.