Skip to content

Commit 45ec13b

Browse files
author
Nakul Sabharwal
committed
Renamed unit test function to testMultipartPostWithHeadersMap, restructered code of createPartHeader function.
1 parent 579995a commit 45ec13b

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

src/main/java/com/microsoft/graph/models/extensions/Multipart.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,22 @@ private void writePartData(String partContent, byte[] byteArray) throws IOExcept
8181

8282
private String createPartHeader(String name, String contentType, String filename) {
8383
String partContent = addBoundary();
84-
String partContentWithNameAndFilename = "Content-Disposition: form-data; name=\"%s\"; filename=\"%s\"" + RETURN + "Content-Type:%s" + RETURN + RETURN;
85-
String partContentWithFilename = "Content-Disposition: form-data; filename=\"%s\"" + RETURN + "Content-Type:%s" + RETURN + RETURN;
86-
String partContentWithNameAndContentType = "Content-Disposition: form-data; name=\"%s\"" + RETURN + "Content-Type:%s" + RETURN + RETURN;
87-
String partContentWithContentType = "Content-Disposition: form-data" + RETURN + "Content-Type:%s" + RETURN + RETURN;
88-
89-
if(filename != null && name != null)
90-
partContent += String.format(partContentWithNameAndFilename, name, filename, contentType);
91-
else if(filename != null)
92-
partContent += String.format(partContentWithFilename, filename, contentType);
93-
else if(name != null)
94-
partContent += String.format(partContentWithNameAndContentType, name, contentType);
95-
else
96-
partContent += String.format(partContentWithContentType, contentType);
84+
if(filename != null && name != null) {
85+
String partContentWithNameAndFilename = "Content-Disposition: form-data; name=\"%s\"; filename=\"%s\"" + RETURN + "Content-Type:%s" + RETURN + RETURN;
86+
partContent += String.format(partContentWithNameAndFilename, name, filename, contentType);
87+
}
88+
else if(filename != null) {
89+
String partContentWithFilename = "Content-Disposition: form-data; filename=\"%s\"" + RETURN + "Content-Type:%s" + RETURN + RETURN;
90+
partContent += String.format(partContentWithFilename, filename, contentType);
91+
}
92+
else if(name != null) {
93+
String partContentWithNameAndContentType = "Content-Disposition: form-data; name=\"%s\"" + RETURN + "Content-Type:%s" + RETURN + RETURN;
94+
partContent += String.format(partContentWithNameAndContentType, name, contentType);
95+
}
96+
else {
97+
String partContentWithContentType = "Content-Disposition: form-data" + RETURN + "Content-Type:%s" + RETURN + RETURN;
98+
partContent += String.format(partContentWithContentType, contentType);
99+
}
97100

98101
return partContent;
99102
}
@@ -145,7 +148,6 @@ private void addData(String name, String contentType, String filename, byte[] by
145148
writePartData(partContent, byteArray);
146149
}
147150

148-
149151
/**
150152
* Add a part to the multipart body
151153
* @param name The name of the part

src/test/java/com/microsoft/graph/functional/OneNoteTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ public void testMultipartPost(){
439439
* Test posting multipart content to a page
440440
*/
441441
@Test
442-
public void testMultipartHeadersMapPost(){
442+
public void testMultipartPostWithHeadersMap(){
443443
try {
444444
Multipart multipart = new Multipart();
445445

0 commit comments

Comments
 (0)