Skip to content

Commit 652266b

Browse files
committed
Polishing
1 parent 75117f4 commit 652266b

File tree

5 files changed

+40
-49
lines changed

5 files changed

+40
-49
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@ else if (Map.class == type) {
12081208
}
12091209

12101210
private boolean isRequired(DependencyDescriptor descriptor) {
1211-
return this.autowireCandidateResolver.isRequired(descriptor);
1211+
return getAutowireCandidateResolver().isRequired(descriptor);
12121212
}
12131213

12141214
private boolean indicatesMultipleBeans(Class<?> type) {

spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,8 +1283,8 @@ else if (aliasPresent) {
12831283
* single-element Annotation, given an annotation instance.
12841284
* @param annotation the annotation instance from which to retrieve the value
12851285
* @return the attribute value, or {@code null} if not found unless the attribute
1286-
* value cannot be retrieved due to an {@link AnnotationConfigurationException}, in
1287-
* which case such an exception will be rethrown
1286+
* value cannot be retrieved due to an {@link AnnotationConfigurationException},
1287+
* in which case such an exception will be rethrown
12881288
* @see #getValue(Annotation, String)
12891289
*/
12901290
public static Object getValue(Annotation annotation) {
@@ -1296,8 +1296,8 @@ public static Object getValue(Annotation annotation) {
12961296
* @param annotation the annotation instance from which to retrieve the value
12971297
* @param attributeName the name of the attribute value to retrieve
12981298
* @return the attribute value, or {@code null} if not found unless the attribute
1299-
* value cannot be retrieved due to an {@link AnnotationConfigurationException}, in
1300-
* which case such an exception will be rethrown
1299+
* value cannot be retrieved due to an {@link AnnotationConfigurationException},
1300+
* in which case such an exception will be rethrown
13011301
* @see #getValue(Annotation)
13021302
* @see #rethrowAnnotationConfigurationException(Throwable)
13031303
*/

spring-test/src/main/java/org/springframework/test/web/servlet/result/CookieResultMatchers.java

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import org.hamcrest.Matcher;
2222

23+
import org.springframework.test.web.servlet.MvcResult;
2324
import org.springframework.test.web.servlet.ResultMatcher;
2425

2526
import static org.hamcrest.MatcherAssert.*;
@@ -50,8 +51,7 @@ protected CookieResultMatchers() {
5051
*/
5152
public ResultMatcher value(final String name, final Matcher<? super String> matcher) {
5253
return result -> {
53-
Cookie cookie = result.getResponse().getCookie(name);
54-
assertTrue("Response cookie '" + name + "' not found", cookie != null);
54+
Cookie cookie = getCookie(result, name);
5555
assertThat("Response cookie '" + name + "'", cookie.getValue(), matcher);
5656
};
5757
}
@@ -61,8 +61,7 @@ public ResultMatcher value(final String name, final Matcher<? super String> matc
6161
*/
6262
public ResultMatcher value(final String name, final String expectedValue) {
6363
return result -> {
64-
Cookie cookie = result.getResponse().getCookie(name);
65-
assertTrue("Response cookie '" + name + "' not found", cookie != null);
64+
Cookie cookie = getCookie(result, name);
6665
assertEquals("Response cookie", expectedValue, cookie.getValue());
6766
};
6867
}
@@ -72,10 +71,7 @@ public ResultMatcher value(final String name, final String expectedValue) {
7271
* max age is 0 (i.e. expired).
7372
*/
7473
public ResultMatcher exists(final String name) {
75-
return result -> {
76-
Cookie cookie = result.getResponse().getCookie(name);
77-
assertTrue("No cookie with name '" + name + "'", cookie != null);
78-
};
74+
return result -> getCookie(result, name);
7975
}
8076

8177
/**
@@ -94,8 +90,7 @@ public ResultMatcher doesNotExist(final String name) {
9490
*/
9591
public ResultMatcher maxAge(final String name, final Matcher<? super Integer> matcher) {
9692
return result -> {
97-
Cookie cookie = result.getResponse().getCookie(name);
98-
assertTrue("No cookie with name '" + name + "'", cookie != null);
93+
Cookie cookie = getCookie(result, name);
9994
assertThat("Response cookie '" + name + "' maxAge", cookie.getMaxAge(), matcher);
10095
};
10196
}
@@ -105,8 +100,7 @@ public ResultMatcher maxAge(final String name, final Matcher<? super Integer> ma
105100
*/
106101
public ResultMatcher maxAge(final String name, final int maxAge) {
107102
return result -> {
108-
Cookie cookie = result.getResponse().getCookie(name);
109-
assertTrue("No cookie with name: " + name, cookie != null);
103+
Cookie cookie = getCookie(result, name);
110104
assertEquals("Response cookie '" + name + "' maxAge", maxAge, cookie.getMaxAge());
111105
};
112106
}
@@ -116,14 +110,14 @@ public ResultMatcher maxAge(final String name, final int maxAge) {
116110
*/
117111
public ResultMatcher path(final String name, final Matcher<? super String> matcher) {
118112
return result -> {
119-
Cookie cookie = result.getResponse().getCookie(name);
113+
Cookie cookie = getCookie(result, name);
120114
assertThat("Response cookie '" + name + "' path", cookie.getPath(), matcher);
121115
};
122116
}
123117

124118
public ResultMatcher path(final String name, final String path) {
125119
return result -> {
126-
Cookie cookie = result.getResponse().getCookie(name);
120+
Cookie cookie = getCookie(result, name);
127121
assertEquals("Response cookie '" + name + "' path", path, cookie.getPath());
128122
};
129123
}
@@ -133,7 +127,7 @@ public ResultMatcher path(final String name, final String path) {
133127
*/
134128
public ResultMatcher domain(final String name, final Matcher<? super String> matcher) {
135129
return result -> {
136-
Cookie cookie = result.getResponse().getCookie(name);
130+
Cookie cookie = getCookie(result, name);
137131
assertThat("Response cookie '" + name + "' domain", cookie.getDomain(), matcher);
138132
};
139133
}
@@ -143,7 +137,7 @@ public ResultMatcher domain(final String name, final Matcher<? super String> mat
143137
*/
144138
public ResultMatcher domain(final String name, final String domain) {
145139
return result -> {
146-
Cookie cookie = result.getResponse().getCookie(name);
140+
Cookie cookie = getCookie(result, name);
147141
assertEquals("Response cookie '" + name + "' domain", domain, cookie.getDomain());
148142
};
149143
}
@@ -153,7 +147,7 @@ public ResultMatcher domain(final String name, final String domain) {
153147
*/
154148
public ResultMatcher comment(final String name, final Matcher<? super String> matcher) {
155149
return result -> {
156-
Cookie cookie = result.getResponse().getCookie(name);
150+
Cookie cookie = getCookie(result, name);
157151
assertThat("Response cookie '" + name + "' comment", cookie.getComment(), matcher);
158152
};
159153
}
@@ -163,7 +157,7 @@ public ResultMatcher comment(final String name, final Matcher<? super String> ma
163157
*/
164158
public ResultMatcher comment(final String name, final String comment) {
165159
return result -> {
166-
Cookie cookie = result.getResponse().getCookie(name);
160+
Cookie cookie = getCookie(result, name);
167161
assertEquals("Response cookie '" + name + "' comment", comment, cookie.getComment());
168162
};
169163
}
@@ -173,7 +167,7 @@ public ResultMatcher comment(final String name, final String comment) {
173167
*/
174168
public ResultMatcher version(final String name, final Matcher<? super Integer> matcher) {
175169
return result -> {
176-
Cookie cookie = result.getResponse().getCookie(name);
170+
Cookie cookie = getCookie(result, name);
177171
assertThat("Response cookie '" + name + "' version", cookie.getVersion(), matcher);
178172
};
179173
}
@@ -183,7 +177,7 @@ public ResultMatcher version(final String name, final Matcher<? super Integer> m
183177
*/
184178
public ResultMatcher version(final String name, final int version) {
185179
return result -> {
186-
Cookie cookie = result.getResponse().getCookie(name);
180+
Cookie cookie = getCookie(result, name);
187181
assertEquals("Response cookie '" + name + "' version", version, cookie.getVersion());
188182
};
189183
}
@@ -193,7 +187,7 @@ public ResultMatcher version(final String name, final int version) {
193187
*/
194188
public ResultMatcher secure(final String name, final boolean secure) {
195189
return result -> {
196-
Cookie cookie = result.getResponse().getCookie(name);
190+
Cookie cookie = getCookie(result, name);
197191
assertEquals("Response cookie '" + name + "' secure", secure, cookie.getSecure());
198192
};
199193
}
@@ -204,9 +198,16 @@ public ResultMatcher secure(final String name, final boolean secure) {
204198
*/
205199
public ResultMatcher httpOnly(final String name, final boolean httpOnly) {
206200
return result -> {
207-
Cookie cookie = result.getResponse().getCookie(name);
201+
Cookie cookie = getCookie(result, name);
208202
assertEquals("Response cookie '" + name + "' httpOnly", httpOnly, cookie.isHttpOnly());
209203
};
210204
}
211205

206+
207+
private static Cookie getCookie(MvcResult result, String name) {
208+
Cookie cookie = result.getResponse().getCookie(name);
209+
assertTrue("No cookie with name '" + name + "'", cookie != null);
210+
return cookie;
211+
}
212+
212213
}

spring-test/src/main/java/org/springframework/test/web/servlet/result/HandlerResultMatchers.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ public ResultMatcher handlerType(final Class<?> type) {
9393
* mockMvc.perform(get("/"))
9494
* .andExpect(handler().methodCall(on(SimpleController.class).handle()));
9595
* </pre>
96-
*
9796
* @param obj either the value returned from a "mock" controller invocation
9897
* or the "mock" controller itself after an invocation
9998
*/

spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartHttpMessageWriter.java

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ public class MultipartHttpMessageWriter implements HttpMessageWriter<MultiValueM
6666
public static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
6767

6868

69+
private final DataBufferFactory bufferFactory = new DefaultDataBufferFactory();
70+
6971
private final List<HttpMessageWriter<?>> partWriters;
7072

7173
private Charset charset = DEFAULT_CHARSET;
7274

73-
private final DataBufferFactory bufferFactory = new DefaultDataBufferFactory();
74-
7575

7676
public MultipartHttpMessageWriter() {
7777
this.partWriters = Arrays.asList(
@@ -84,13 +84,14 @@ public MultipartHttpMessageWriter(List<HttpMessageWriter<?>> partWriters) {
8484
this.partWriters = partWriters;
8585
}
8686

87+
8788
/**
8889
* Set the character set to use for part headers such as
8990
* "Content-Disposition" (and its filename parameter).
9091
* <p>By default this is set to "UTF-8".
9192
*/
9293
public void setCharset(Charset charset) {
93-
Assert.notNull(charset, "'charset' must not be null");
94+
Assert.notNull(charset, "Charset must not be null");
9495
this.charset = charset;
9596
}
9697

@@ -126,11 +127,9 @@ public Mono<Void> write(Publisher<? extends MultiValueMap<String, ?>> inputStrea
126127
outputMessage.getHeaders().setContentType(new MediaType(MediaType.MULTIPART_FORM_DATA, params));
127128

128129
return Mono.from(inputStream).flatMap(map -> {
129-
130130
Flux<DataBuffer> body = Flux.fromIterable(map.entrySet())
131131
.concatMap(entry -> encodePartValues(boundary, entry.getKey(), entry.getValue()))
132132
.concatWith(Mono.just(generateLastLine(boundary)));
133-
134133
return outputMessage.writeWith(body);
135134
});
136135
}
@@ -150,9 +149,7 @@ private Flux<DataBuffer> encodePartValues(byte[] boundary, String name, List<?>
150149

151150
@SuppressWarnings("unchecked")
152151
private <T> Flux<DataBuffer> encodePart(byte[] boundary, String name, T value) {
153-
154-
MultipartHttpOutputMessage outputMessage =
155-
new MultipartHttpOutputMessage(this.bufferFactory, getCharset());
152+
MultipartHttpOutputMessage outputMessage = new MultipartHttpOutputMessage(this.bufferFactory, getCharset());
156153

157154
T body;
158155
if (value instanceof HttpEntity) {
@@ -173,7 +170,7 @@ private <T> Flux<DataBuffer> encodePart(byte[] boundary, String name, T value) {
173170
.filter(partWriter -> partWriter.canWrite(bodyType, contentType))
174171
.findFirst();
175172

176-
if(!writer.isPresent()) {
173+
if (!writer.isPresent()) {
177174
return Flux.error(new CodecException("No suitable writer found for part: " + name));
178175
}
179176

@@ -182,17 +179,14 @@ private <T> Flux<DataBuffer> encodePart(byte[] boundary, String name, T value) {
182179

183180
// partWritten.subscribe() is required in order to make sure MultipartHttpOutputMessage#getBody()
184181
// returns a non-null value (occurs with ResourceHttpMessageWriter that invokes
185-
// ReactiveHttpOutputMessage.writeWith() only when at least one element has been
186-
// requested).
182+
// ReactiveHttpOutputMessage.writeWith() only when at least one element has been requested).
187183
partWritten.subscribe();
188184

189185
return Flux.concat(
190-
Mono.just(generateBoundaryLine(boundary)),
191-
outputMessage.getBody(),
192-
Mono.just(generateNewLine())
193-
);
186+
Mono.just(generateBoundaryLine(boundary)), outputMessage.getBody(), Mono.just(generateNewLine()));
194187
}
195188

189+
196190
private DataBuffer generateBoundaryLine(byte[] boundary) {
197191
DataBuffer buffer = this.bufferFactory.allocateBuffer(boundary.length + 4);
198192
buffer.write((byte)'-');
@@ -231,17 +225,15 @@ private static class MultipartHttpOutputMessage implements ReactiveHttpOutputMes
231225

232226
private final HttpHeaders headers = new HttpHeaders();
233227

234-
private final AtomicBoolean commited = new AtomicBoolean();
228+
private final AtomicBoolean committed = new AtomicBoolean();
235229

236230
private Flux<DataBuffer> body;
237231

238-
239232
public MultipartHttpOutputMessage(DataBufferFactory bufferFactory, Charset charset) {
240233
this.bufferFactory = bufferFactory;
241234
this.charset = charset;
242235
}
243236

244-
245237
@Override
246238
public HttpHeaders getHeaders() {
247239
return (this.body != null ? HttpHeaders.readOnlyHttpHeaders(this.headers) : this.headers);
@@ -254,12 +246,12 @@ public DataBufferFactory bufferFactory() {
254246

255247
@Override
256248
public void beforeCommit(Supplier<? extends Mono<Void>> action) {
257-
this.commited.set(true);
249+
this.committed.set(true);
258250
}
259251

260252
@Override
261253
public boolean isCommitted() {
262-
return this.commited.get();
254+
return this.committed.get();
263255
}
264256

265257
@Override
@@ -305,7 +297,6 @@ public Mono<Void> setComplete() {
305297
return (this.body != null ? this.body.then() :
306298
Mono.error(new IllegalStateException("Body has not been written yet")));
307299
}
308-
309300
}
310301

311302
}

0 commit comments

Comments
 (0)