Skip to content

Commit 7211db9

Browse files
committed
Polishing
1 parent 3b87c87 commit 7211db9

File tree

8 files changed

+173
-178
lines changed

8 files changed

+173
-178
lines changed

spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/SplittingStompEncoder.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
import org.springframework.util.Assert;
2525

2626
/**
27-
* Uses {@link org.springframework.messaging.simp.stomp.StompEncoder} to encode
28-
* a message and splits it into parts no larger than the configured
29-
* {@link SplittingStompEncoder#bufferSizeLimit}.
27+
* Uses a {@link StompEncoder} to encode a message and splits it into parts no
28+
* larger than the configured
29+
* {@linkplain #SplittingStompEncoder(StompEncoder, int) buffer size limit}.
3030
*
3131
* @author Injae Kim
3232
* @author Rossen Stoyanchev
@@ -40,6 +40,11 @@ public class SplittingStompEncoder {
4040
private final int bufferSizeLimit;
4141

4242

43+
/**
44+
* Create a new {@code SplittingStompEncoder}.
45+
* @param encoder the {@link StompEncoder} to use
46+
* @param bufferSizeLimit the buffer size limit
47+
*/
4348
public SplittingStompEncoder(StompEncoder encoder, int bufferSizeLimit) {
4449
Assert.notNull(encoder, "StompEncoder is required");
4550
Assert.isTrue(bufferSizeLimit > 0, "Buffer size limit must be greater than 0");
@@ -49,7 +54,7 @@ public SplittingStompEncoder(StompEncoder encoder, int bufferSizeLimit) {
4954

5055

5156
/**
52-
* Encode the given payload and headers to a STOMP frame, and split into a
57+
* Encode the given payload and headers to a STOMP frame, and split it into a
5358
* list of parts based on the configured buffer size limit.
5459
* @param headers the STOMP message headers
5560
* @param payload the STOMP message payload

spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 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.
@@ -78,10 +78,10 @@ public MessageHeaderInitializer getHeaderInitializer() {
7878
* Decodes one or more STOMP frames from the given {@code ByteBuffer} into a
7979
* list of {@link Message Messages}. If the input buffer contains partial STOMP frame
8080
* content, or additional content with a partial STOMP frame, the buffer is
81-
* reset and an empty list is returned.
81+
* reset, and an empty list is returned.
8282
* @param byteBuffer the buffer to decode the STOMP frame from
8383
* @return the decoded messages, or an empty list if none
84-
* @throws StompConversionException raised in case of decoding issues
84+
* @throws StompConversionException in case of decoding issues
8585
*/
8686
public List<Message<byte[]>> decode(ByteBuffer byteBuffer) {
8787
return decode(byteBuffer, null);
@@ -93,18 +93,18 @@ public List<Message<byte[]>> decode(ByteBuffer byteBuffer) {
9393
* <p>If the given ByteBuffer contains only partial STOMP frame content and no
9494
* complete STOMP frames, an empty list is returned, and the buffer is reset
9595
* to where it was.
96-
* <p>If the buffer contains one or more STOMP frames, those are returned and
97-
* the buffer reset to point to the beginning of the unused partial content.
98-
* <p>The output partialMessageHeaders map is used to store successfully parsed
96+
* <p>If the buffer contains one or more STOMP frames, those are returned, and
97+
* the buffer is reset to point to the beginning of the unused partial content.
98+
* <p>The {@code partialMessageHeaders} map is used to store successfully parsed
9999
* headers in case of partial content. The caller can then check if a
100100
* "content-length" header was read, which helps to determine how much more
101101
* content is needed before the next attempt to decode.
102102
* @param byteBuffer the buffer to decode the STOMP frame from
103103
* @param partialMessageHeaders an empty output map that will store the last
104-
* successfully parsed partialMessageHeaders in case of partial message content
104+
* successfully parsed partial message headers in case of partial message content
105105
* in cases where the partial buffer ended with a partial STOMP frame
106106
* @return the decoded messages, or an empty list if none
107-
* @throws StompConversionException raised in case of decoding issues
107+
* @throws StompConversionException in case of decoding issues
108108
*/
109109
public List<Message<byte[]>> decode(ByteBuffer byteBuffer,
110110
@Nullable MultiValueMap<String, String> partialMessageHeaders) {
@@ -127,7 +127,7 @@ public List<Message<byte[]>> decode(ByteBuffer byteBuffer,
127127
}
128128

129129
/**
130-
* Decode a single STOMP frame from the given {@code buffer} into a {@link Message}.
130+
* Decode a single STOMP frame from the given {@code byteBuffer} into a {@link Message}.
131131
*/
132132
@Nullable
133133
private Message<byte[]> decodeMessage(ByteBuffer byteBuffer, @Nullable MultiValueMap<String, String> headers) {

spring-test/src/main/java/org/springframework/test/context/bean/override/convention/TestBeanOverrideProcessor.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ public static Method ensureMethod(Class<?> enclosingClass, Class<?> expectedMeth
5656

5757
Assert.isTrue(expectedMethodNames.length > 0, "At least one expectedMethodName is required");
5858
Set<String> expectedNames = new LinkedHashSet<>(Arrays.asList(expectedMethodNames));
59-
final List<Method> found = Arrays.stream(enclosingClass.getDeclaredMethods())
60-
.filter(method -> Modifier.isStatic(method.getModifiers()))
61-
.filter(method -> expectedNames.contains(method.getName())
62-
&& expectedMethodReturnType.isAssignableFrom(method.getReturnType()))
59+
List<Method> found = Arrays.stream(enclosingClass.getDeclaredMethods())
60+
.filter(method -> Modifier.isStatic(method.getModifiers()) &&
61+
expectedNames.contains(method.getName()) &&
62+
expectedMethodReturnType.isAssignableFrom(method.getReturnType()))
6363
.toList();
6464

6565
Assert.state(found.size() == 1, () -> "Found " + found.size() + " static methods " +
@@ -71,23 +71,22 @@ public static Method ensureMethod(Class<?> enclosingClass, Class<?> expectedMeth
7171

7272
@Override
7373
public OverrideMetadata createMetadata(Field field, Annotation overrideAnnotation, ResolvableType typeToOverride) {
74-
final Class<?> enclosingClass = field.getDeclaringClass();
75-
// if we can get an explicit method name right away, fail fast if it doesn't match
74+
Class<?> declaringClass = field.getDeclaringClass();
75+
// If we can, get an explicit method name right away; fail fast if it doesn't match.
7676
if (overrideAnnotation instanceof TestBean testBeanAnnotation) {
7777
Method overrideMethod = null;
7878
String beanName = null;
7979
if (!testBeanAnnotation.methodName().isBlank()) {
80-
overrideMethod = ensureMethod(enclosingClass, field.getType(), testBeanAnnotation.methodName());
80+
overrideMethod = ensureMethod(declaringClass, field.getType(), testBeanAnnotation.methodName());
8181
}
8282
if (!testBeanAnnotation.name().isBlank()) {
8383
beanName = testBeanAnnotation.name();
8484
}
8585
return new MethodConventionOverrideMetadata(field, overrideMethod, beanName,
8686
overrideAnnotation, typeToOverride);
8787
}
88-
// otherwise defer the resolution of the static method until OverrideMetadata#createOverride
89-
return new MethodConventionOverrideMetadata(field, null, null, overrideAnnotation,
90-
typeToOverride);
88+
// Otherwise defer the resolution of the static method until OverrideMetadata#createOverride.
89+
return new MethodConventionOverrideMetadata(field, null, null, overrideAnnotation, typeToOverride);
9190
}
9291

9392
static final class MethodConventionOverrideMetadata extends OverrideMetadata {
@@ -100,6 +99,7 @@ static final class MethodConventionOverrideMetadata extends OverrideMetadata {
10099

101100
public MethodConventionOverrideMetadata(Field field, @Nullable Method overrideMethod, @Nullable String beanName,
102101
Annotation overrideAnnotation, ResolvableType typeToOverride) {
102+
103103
super(field, overrideAnnotation, typeToOverride, BeanOverrideStrategy.REPLACE_DEFINITION);
104104
this.overrideMethod = overrideMethod;
105105
this.beanName = beanName;
@@ -121,6 +121,7 @@ public String getBeanOverrideDescription() {
121121
@Override
122122
protected Object createOverride(String beanName, @Nullable BeanDefinition existingBeanDefinition,
123123
@Nullable Object existingBeanInstance) {
124+
124125
Method methodToInvoke = this.overrideMethod;
125126
if (methodToInvoke == null) {
126127
methodToInvoke = ensureMethod(field().getDeclaringClass(), field().getType(),
@@ -135,7 +136,7 @@ protected Object createOverride(String beanName, @Nullable BeanDefinition existi
135136
}
136137
catch (IllegalAccessException | InvocationTargetException ex) {
137138
throw new IllegalArgumentException("Could not invoke bean overriding method " + methodToInvoke.getName() +
138-
", a static method with no input parameters is expected", ex);
139+
"; a static method with no formal parameters is expected", ex);
139140
}
140141

141142
return override;

spring-test/src/main/java/org/springframework/test/web/reactive/server/CookieAssertions.java

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2024 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.
@@ -24,9 +24,10 @@
2424
import org.hamcrest.MatcherAssert;
2525

2626
import org.springframework.http.ResponseCookie;
27-
import org.springframework.test.util.AssertionErrors;
2827

2928
import static org.hamcrest.MatcherAssert.assertThat;
29+
import static org.springframework.test.util.AssertionErrors.assertEquals;
30+
import static org.springframework.test.util.AssertionErrors.fail;
3031

3132
/**
3233
* Assertions on cookies of the response.
@@ -48,18 +49,20 @@ public CookieAssertions(ExchangeResult exchangeResult, WebTestClient.ResponseSpe
4849

4950

5051
/**
51-
* Expect a header with the given name to match the specified values.
52+
* Expect a response cookie with the given name to match the specified value.
5253
*/
5354
public WebTestClient.ResponseSpec valueEquals(String name, String value) {
55+
String cookieValue = getCookie(name).getValue();
5456
this.exchangeResult.assertWithDiagnostics(() -> {
5557
String message = getMessage(name);
56-
AssertionErrors.assertEquals(message, value, getCookie(name).getValue());
58+
assertEquals(message, value, cookieValue);
5759
});
5860
return this.responseSpec;
5961
}
6062

6163
/**
62-
* Assert the first value of the response cookie with a Hamcrest {@link Matcher}.
64+
* Assert the value of the response cookie with the given name with a Hamcrest
65+
* {@link Matcher}.
6366
*/
6467
public WebTestClient.ResponseSpec value(String name, Matcher<? super String> matcher) {
6568
String value = getCookie(name).getValue();
@@ -71,7 +74,7 @@ public WebTestClient.ResponseSpec value(String name, Matcher<? super String> mat
7174
}
7275

7376
/**
74-
* Consume the value of the response cookie.
77+
* Consume the value of the response cookie with the given name.
7578
*/
7679
public WebTestClient.ResponseSpec value(String name, Consumer<String> consumer) {
7780
String value = getCookie(name).getValue();
@@ -94,25 +97,25 @@ public WebTestClient.ResponseSpec doesNotExist(String name) {
9497
ResponseCookie cookie = this.exchangeResult.getResponseCookies().getFirst(name);
9598
if (cookie != null) {
9699
String message = getMessage(name) + " exists with value=[" + cookie.getValue() + "]";
97-
this.exchangeResult.assertWithDiagnostics(() -> AssertionErrors.fail(message));
100+
this.exchangeResult.assertWithDiagnostics(() -> fail(message));
98101
}
99102
return this.responseSpec;
100103
}
101104

102105
/**
103-
* Assert a cookie's maxAge attribute.
106+
* Assert a cookie's "Max-Age" attribute.
104107
*/
105108
public WebTestClient.ResponseSpec maxAge(String name, Duration expected) {
106109
Duration maxAge = getCookie(name).getMaxAge();
107110
this.exchangeResult.assertWithDiagnostics(() -> {
108111
String message = getMessage(name) + " maxAge";
109-
AssertionErrors.assertEquals(message, expected, maxAge);
112+
assertEquals(message, expected, maxAge);
110113
});
111114
return this.responseSpec;
112115
}
113116

114117
/**
115-
* Assert a cookie's maxAge attribute with a Hamcrest {@link Matcher}.
118+
* Assert a cookie's "Max-Age" attribute with a Hamcrest {@link Matcher}.
116119
*/
117120
public WebTestClient.ResponseSpec maxAge(String name, Matcher<? super Long> matcher) {
118121
long maxAge = getCookie(name).getMaxAge().getSeconds();
@@ -124,19 +127,19 @@ public WebTestClient.ResponseSpec maxAge(String name, Matcher<? super Long> matc
124127
}
125128

126129
/**
127-
* Assert a cookie's path attribute.
130+
* Assert a cookie's "Path" attribute.
128131
*/
129132
public WebTestClient.ResponseSpec path(String name, String expected) {
130133
String path = getCookie(name).getPath();
131134
this.exchangeResult.assertWithDiagnostics(() -> {
132135
String message = getMessage(name) + " path";
133-
AssertionErrors.assertEquals(message, expected, path);
136+
assertEquals(message, expected, path);
134137
});
135138
return this.responseSpec;
136139
}
137140

138141
/**
139-
* Assert a cookie's path attribute with a Hamcrest {@link Matcher}.
142+
* Assert a cookie's "Path" attribute with a Hamcrest {@link Matcher}.
140143
*/
141144
public WebTestClient.ResponseSpec path(String name, Matcher<? super String> matcher) {
142145
String path = getCookie(name).getPath();
@@ -148,19 +151,19 @@ public WebTestClient.ResponseSpec path(String name, Matcher<? super String> matc
148151
}
149152

150153
/**
151-
* Assert a cookie's domain attribute.
154+
* Assert a cookie's "Domain" attribute.
152155
*/
153156
public WebTestClient.ResponseSpec domain(String name, String expected) {
154157
String path = getCookie(name).getDomain();
155158
this.exchangeResult.assertWithDiagnostics(() -> {
156159
String message = getMessage(name) + " domain";
157-
AssertionErrors.assertEquals(message, expected, path);
160+
assertEquals(message, expected, path);
158161
});
159162
return this.responseSpec;
160163
}
161164

162165
/**
163-
* Assert a cookie's domain attribute with a Hamcrest {@link Matcher}.
166+
* Assert a cookie's "Domain" attribute with a Hamcrest {@link Matcher}.
164167
*/
165168
public WebTestClient.ResponseSpec domain(String name, Matcher<? super String> matcher) {
166169
String domain = getCookie(name).getDomain();
@@ -172,37 +175,37 @@ public WebTestClient.ResponseSpec domain(String name, Matcher<? super String> ma
172175
}
173176

174177
/**
175-
* Assert a cookie's secure attribute.
178+
* Assert a cookie's "Secure" attribute.
176179
*/
177180
public WebTestClient.ResponseSpec secure(String name, boolean expected) {
178181
boolean isSecure = getCookie(name).isSecure();
179182
this.exchangeResult.assertWithDiagnostics(() -> {
180183
String message = getMessage(name) + " secure";
181-
AssertionErrors.assertEquals(message, expected, isSecure);
184+
assertEquals(message, expected, isSecure);
182185
});
183186
return this.responseSpec;
184187
}
185188

186189
/**
187-
* Assert a cookie's httpOnly attribute.
190+
* Assert a cookie's "HttpOnly" attribute.
188191
*/
189192
public WebTestClient.ResponseSpec httpOnly(String name, boolean expected) {
190193
boolean isHttpOnly = getCookie(name).isHttpOnly();
191194
this.exchangeResult.assertWithDiagnostics(() -> {
192195
String message = getMessage(name) + " httpOnly";
193-
AssertionErrors.assertEquals(message, expected, isHttpOnly);
196+
assertEquals(message, expected, isHttpOnly);
194197
});
195198
return this.responseSpec;
196199
}
197200

198201
/**
199-
* Assert a cookie's sameSite attribute.
202+
* Assert a cookie's "SameSite" attribute.
200203
*/
201204
public WebTestClient.ResponseSpec sameSite(String name, String expected) {
202205
String sameSite = getCookie(name).getSameSite();
203206
this.exchangeResult.assertWithDiagnostics(() -> {
204207
String message = getMessage(name) + " sameSite";
205-
AssertionErrors.assertEquals(message, expected, sameSite);
208+
assertEquals(message, expected, sameSite);
206209
});
207210
return this.responseSpec;
208211
}
@@ -211,13 +214,12 @@ public WebTestClient.ResponseSpec sameSite(String name, String expected) {
211214
private ResponseCookie getCookie(String name) {
212215
ResponseCookie cookie = this.exchangeResult.getResponseCookies().getFirst(name);
213216
if (cookie == null) {
214-
this.exchangeResult.assertWithDiagnostics(() ->
215-
AssertionErrors.fail("No cookie with name '" + name + "'"));
217+
this.exchangeResult.assertWithDiagnostics(() -> fail("No cookie with name '" + name + "'"));
216218
}
217219
return Objects.requireNonNull(cookie);
218220
}
219221

220-
private String getMessage(String cookie) {
222+
private static String getMessage(String cookie) {
221223
return "Response cookie '" + cookie + "'";
222224
}
223225

0 commit comments

Comments
 (0)