Skip to content

Commit 29b7659

Browse files
committed
Polish
1 parent 27b5d2b commit 29b7659

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestPartMethodArgumentResolver.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -96,15 +96,12 @@ public Mono<Object> resolveArgument(
9696

9797
ReactiveAdapter adapter = getAdapterRegistry().getAdapter(parameter.getParameterType());
9898
if (adapter != null) {
99-
// Mono<Part> or Flux<Part>
10099
MethodParameter elementType = parameter.nested();
101-
if (Part.class.isAssignableFrom(elementType.getNestedParameterType())) {
102-
return Mono.just(adapter.fromPublisher(parts));
103-
}
104-
return Mono.just(adapter.fromPublisher(decodePartValues(parts, elementType, bindingContext, exchange, isRequired)));
100+
return Mono.just(adapter.fromPublisher(
101+
Part.class.isAssignableFrom(elementType.getNestedParameterType()) ?
102+
parts : decodePartValues(parts, elementType, bindingContext, exchange, isRequired)));
105103
}
106104

107-
// <T> or Mono<T>
108105
return decodePartValues(parts, parameter, bindingContext, exchange, isRequired)
109106
.next().cast(Object.class);
110107
}

spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestPartMethodArgumentResolverTests.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -53,9 +53,13 @@
5353
import org.springframework.web.server.ServerWebExchange;
5454
import org.springframework.web.server.ServerWebInputException;
5555

56-
import static org.junit.Assert.*;
57-
import static org.springframework.core.ResolvableType.*;
58-
import static org.springframework.web.method.MvcAnnotationPredicates.*;
56+
import static org.junit.Assert.assertEquals;
57+
import static org.junit.Assert.assertFalse;
58+
import static org.junit.Assert.assertNotNull;
59+
import static org.junit.Assert.assertNull;
60+
import static org.junit.Assert.assertTrue;
61+
import static org.springframework.core.ResolvableType.forClass;
62+
import static org.springframework.web.method.MvcAnnotationPredicates.requestPart;
5963

6064
/**
6165
* Unit tests for {@link RequestPartMethodArgumentResolver}.
@@ -132,13 +136,13 @@ public void listPerson() {
132136
assertEquals("James", actual.get(1).getName());
133137
}
134138

135-
@Test
139+
@Test // gh-23060
136140
public void listPersonNotRequired() {
137141
MethodParameter param = this.testMethod.annot(requestPart().notRequired()).arg(List.class, Person.class);
138142
MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder();
139143
List<Person> actual = resolveArgument(param, bodyBuilder);
140144

141-
assertThat(actual).isEmpty();
145+
assertEquals(Collections.emptyList(), actual);
142146
}
143147

144148
@Test
@@ -151,13 +155,13 @@ public void monoPerson() {
151155
assertEquals("Jones", actual.block().getName());
152156
}
153157

154-
@Test
158+
@Test // gh-23060
155159
public void monoPersonNotRequired() {
156160
MethodParameter param = this.testMethod.annot(requestPart().notRequired()).arg(Mono.class, Person.class);
157161
MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder();
158162
Mono<Person> actual = resolveArgument(param, bodyBuilder);
159163

160-
assertThat(actual.block()).isNull();
164+
assertNull(actual.block());
161165
}
162166

163167
@Test
@@ -173,13 +177,13 @@ public void fluxPerson() {
173177
assertEquals("James", persons.get(1).getName());
174178
}
175179

176-
@Test
180+
@Test // gh-23060
177181
public void fluxPersonNotRequired() {
178182
MethodParameter param = this.testMethod.annot(requestPart().notRequired()).arg(Flux.class, Person.class);
179183
MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder();
180184
Flux<Person> actual = resolveArgument(param, bodyBuilder);
181185

182-
assertThat(actual.collectList().block()).isEmpty();
186+
assertEquals(Collections.emptyList(), actual.collectList().block());
183187
}
184188

185189
@Test
@@ -205,13 +209,13 @@ public void listPart() {
205209
assertEquals("{\"name\":\"James\"}", partToUtf8String(actual.get(1)));
206210
}
207211

208-
@Test
212+
@Test // gh-23060
209213
public void listPartNotRequired() {
210214
MethodParameter param = this.testMethod.annot(requestPart().notRequired()).arg(List.class, Part.class);
211215
MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder();
212216
List<Part> actual = resolveArgument(param, bodyBuilder);
213217

214-
assertThat(actual).isEmpty();
218+
assertEquals(Collections.emptyList(), actual);
215219
}
216220

217221
@Test
@@ -225,13 +229,13 @@ public void monoPart() {
225229
assertEquals("{\"name\":\"Jones\"}", partToUtf8String(part));
226230
}
227231

228-
@Test
232+
@Test // gh-23060
229233
public void monoPartNotRequired() {
230234
MethodParameter param = this.testMethod.annot(requestPart().notRequired()).arg(Mono.class, Part.class);
231235
MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder();
232236
Mono<Part> actual = resolveArgument(param, bodyBuilder);
233237

234-
assertThat(actual.block()).isNull();
238+
assertNull(actual.block());
235239
}
236240

237241
@Test
@@ -247,13 +251,13 @@ public void fluxPart() {
247251
assertEquals("{\"name\":\"James\"}", partToUtf8String(parts.get(1)));
248252
}
249253

250-
@Test
254+
@Test // gh-23060
251255
public void fluxPartNotRequired() {
252256
MethodParameter param = this.testMethod.annot(requestPart().notRequired()).arg(Flux.class, Part.class);
253257
MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder();
254258
Flux<Part> actual = resolveArgument(param, bodyBuilder);
255259

256-
assertThat(actual.collectList().block()).isEmpty();
260+
assertEquals(Collections.emptyList(), actual.collectList().block());
257261
}
258262

259263
@Test

0 commit comments

Comments
 (0)