Skip to content

Commit 8ee09e5

Browse files
Tussle0410bclozel
authored andcommitted
Separate commonly used DepositionTypeCheck into methods
Closes gh-34573 Signed-off-by: ChanHyeongLee <[email protected]> [[email protected]: apply code conventions] Signed-off-by: Brian Clozel <[email protected]>
1 parent de75b6e commit 8ee09e5

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

spring-web/src/main/java/org/springframework/http/ContentDisposition.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -99,23 +99,27 @@ private ContentDisposition(@Nullable String type, @Nullable String name, @Nullab
9999
* @since 5.3
100100
*/
101101
public boolean isAttachment() {
102-
return (this.type != null && this.type.equalsIgnoreCase("attachment"));
102+
return isDispositionType("attachment");
103103
}
104104

105105
/**
106106
* Return whether the {@link #getType() type} is {@literal "form-data"}.
107107
* @since 5.3
108108
*/
109109
public boolean isFormData() {
110-
return (this.type != null && this.type.equalsIgnoreCase("form-data"));
110+
return isDispositionType("form-data");
111111
}
112112

113113
/**
114114
* Return whether the {@link #getType() type} is {@literal "inline"}.
115115
* @since 5.3
116116
*/
117117
public boolean isInline() {
118-
return (this.type != null && this.type.equalsIgnoreCase("inline"));
118+
return isDispositionType("inline");
119+
}
120+
121+
private boolean isDispositionType(String type) {
122+
return this.type != null && this.type.equalsIgnoreCase(type);
119123
}
120124

121125
/**
@@ -556,6 +560,7 @@ private static char hexDigit(int b) {
556560
}
557561

558562

563+
559564
/**
560565
* A mutable builder for {@code ContentDisposition}.
561566
*/

spring-web/src/test/java/org/springframework/http/ContentDispositionTests.java

+24
Original file line numberDiff line numberDiff line change
@@ -310,4 +310,28 @@ void parseFormattedWithQuestionMark() {
310310
.isEqualTo(filename);
311311
}
312312

313+
@Test
314+
void attachmentType(){
315+
ContentDisposition attachment = ContentDisposition.attachment().build();
316+
assertThat(attachment.isAttachment()).isTrue();
317+
assertThat(attachment.isFormData()).isFalse();
318+
assertThat(attachment.isInline()).isFalse();
319+
}
320+
321+
@Test
322+
void formDataType(){
323+
ContentDisposition formData = ContentDisposition.formData().build();
324+
assertThat(formData.isAttachment()).isFalse();
325+
assertThat(formData.isFormData()).isTrue();
326+
assertThat(formData.isInline()).isFalse();
327+
}
328+
329+
@Test
330+
void inlineType(){
331+
ContentDisposition inline = ContentDisposition.inline().build();
332+
assertThat(inline.isAttachment()).isFalse();
333+
assertThat(inline.isFormData()).isFalse();
334+
assertThat(inline.isInline()).isTrue();
335+
}
336+
313337
}

0 commit comments

Comments
 (0)