Skip to content

Commit 95a8646

Browse files
committed
Polishing
1 parent 5434edd commit 95a8646

File tree

4 files changed

+35
-34
lines changed

4 files changed

+35
-34
lines changed

spring-web/src/main/java/org/springframework/web/method/annotation/ModelFactory.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 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.
@@ -234,11 +234,9 @@ private boolean isBindingCandidate(String attributeName, Object value) {
234234
if (attributeName.startsWith(BindingResult.MODEL_KEY_PREFIX)) {
235235
return false;
236236
}
237-
238237
if (this.sessionAttributesHandler.isHandlerSessionAttribute(attributeName, value.getClass())) {
239238
return true;
240239
}
241-
242240
return (!value.getClass().isArray() && !(value instanceof Collection) &&
243241
!(value instanceof Map) && !BeanUtils.isSimpleValueType(value.getClass()));
244242
}

spring-web/src/test/java/org/springframework/web/method/annotation/ModelFactoryTests.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 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.
@@ -51,7 +51,7 @@
5151
*
5252
* @author Rossen Stoyanchev
5353
*/
54-
public class ModelFactoryTests {
54+
class ModelFactoryTests {
5555

5656
private NativeWebRequest webRequest;
5757

@@ -65,7 +65,7 @@ public class ModelFactoryTests {
6565

6666

6767
@BeforeEach
68-
public void setUp() throws Exception {
68+
void setup() {
6969
this.webRequest = new ServletWebRequest(new MockHttpServletRequest());
7070
this.attributeStore = new DefaultSessionAttributeStore();
7171
this.attributeHandler = new SessionAttributesHandler(TestController.class, this.attributeStore);
@@ -75,7 +75,7 @@ public void setUp() throws Exception {
7575

7676

7777
@Test
78-
public void modelAttributeMethod() throws Exception {
78+
void modelAttributeMethod() throws Exception {
7979
ModelFactory modelFactory = createModelFactory("modelAttr", Model.class);
8080
HandlerMethod handlerMethod = createHandlerMethod("handle");
8181
modelFactory.initModel(this.webRequest, this.mavContainer, handlerMethod);
@@ -84,7 +84,7 @@ public void modelAttributeMethod() throws Exception {
8484
}
8585

8686
@Test
87-
public void modelAttributeMethodWithExplicitName() throws Exception {
87+
void modelAttributeMethodWithExplicitName() throws Exception {
8888
ModelFactory modelFactory = createModelFactory("modelAttrWithName");
8989
HandlerMethod handlerMethod = createHandlerMethod("handle");
9090
modelFactory.initModel(this.webRequest, this.mavContainer, handlerMethod);
@@ -93,7 +93,7 @@ public void modelAttributeMethodWithExplicitName() throws Exception {
9393
}
9494

9595
@Test
96-
public void modelAttributeMethodWithNameByConvention() throws Exception {
96+
void modelAttributeMethodWithNameByConvention() throws Exception {
9797
ModelFactory modelFactory = createModelFactory("modelAttrConvention");
9898
HandlerMethod handlerMethod = createHandlerMethod("handle");
9999
modelFactory.initModel(this.webRequest, this.mavContainer, handlerMethod);
@@ -102,7 +102,7 @@ public void modelAttributeMethodWithNameByConvention() throws Exception {
102102
}
103103

104104
@Test
105-
public void modelAttributeMethodWithNullReturnValue() throws Exception {
105+
void modelAttributeMethodWithNullReturnValue() throws Exception {
106106
ModelFactory modelFactory = createModelFactory("nullModelAttr");
107107
HandlerMethod handlerMethod = createHandlerMethod("handle");
108108
modelFactory.initModel(this.webRequest, this.mavContainer, handlerMethod);
@@ -112,7 +112,7 @@ public void modelAttributeMethodWithNullReturnValue() throws Exception {
112112
}
113113

114114
@Test
115-
public void modelAttributeWithBindingDisabled() throws Exception {
115+
void modelAttributeWithBindingDisabled() throws Exception {
116116
ModelFactory modelFactory = createModelFactory("modelAttrWithBindingDisabled");
117117
HandlerMethod handlerMethod = createHandlerMethod("handle");
118118
modelFactory.initModel(this.webRequest, this.mavContainer, handlerMethod);
@@ -122,7 +122,7 @@ public void modelAttributeWithBindingDisabled() throws Exception {
122122
}
123123

124124
@Test
125-
public void modelAttributeFromSessionWithBindingDisabled() throws Exception {
125+
void modelAttributeFromSessionWithBindingDisabled() throws Exception {
126126
Foo foo = new Foo();
127127
this.attributeStore.storeAttribute(this.webRequest, "foo", foo);
128128

@@ -136,7 +136,7 @@ public void modelAttributeFromSessionWithBindingDisabled() throws Exception {
136136
}
137137

138138
@Test
139-
public void sessionAttribute() throws Exception {
139+
void sessionAttribute() throws Exception {
140140
this.attributeStore.storeAttribute(this.webRequest, "sessionAttr", "sessionAttrValue");
141141

142142
ModelFactory modelFactory = createModelFactory("modelAttr", Model.class);
@@ -147,21 +147,20 @@ public void sessionAttribute() throws Exception {
147147
}
148148

149149
@Test
150-
public void sessionAttributeNotPresent() throws Exception {
150+
void sessionAttributeNotPresent() throws Exception {
151151
ModelFactory modelFactory = new ModelFactory(null, null, this.attributeHandler);
152152
HandlerMethod handlerMethod = createHandlerMethod("handleSessionAttr", String.class);
153153
assertThatExceptionOfType(HttpSessionRequiredException.class).isThrownBy(() ->
154154
modelFactory.initModel(this.webRequest, this.mavContainer, handlerMethod));
155155

156156
// Now add attribute and try again
157157
this.attributeStore.storeAttribute(this.webRequest, "sessionAttr", "sessionAttrValue");
158-
159158
modelFactory.initModel(this.webRequest, this.mavContainer, handlerMethod);
160159
assertThat(this.mavContainer.getModel().get("sessionAttr")).isEqualTo("sessionAttrValue");
161160
}
162161

163162
@Test
164-
public void updateModelBindingResult() throws Exception {
163+
void updateModelBindingResult() throws Exception {
165164
String commandName = "attr1";
166165
Object command = new Object();
167166
ModelAndViewContainer container = new ModelAndViewContainer();
@@ -181,7 +180,7 @@ public void updateModelBindingResult() throws Exception {
181180
}
182181

183182
@Test
184-
public void updateModelSessionAttributesSaved() throws Exception {
183+
void updateModelSessionAttributesSaved() throws Exception {
185184
String attributeName = "sessionAttr";
186185
String attribute = "value";
187186
ModelAndViewContainer container = new ModelAndViewContainer();
@@ -199,7 +198,7 @@ public void updateModelSessionAttributesSaved() throws Exception {
199198
}
200199

201200
@Test
202-
public void updateModelSessionAttributesRemoved() throws Exception {
201+
void updateModelSessionAttributesRemoved() throws Exception {
203202
String attributeName = "sessionAttr";
204203
String attribute = "value";
205204
ModelAndViewContainer container = new ModelAndViewContainer();
@@ -221,7 +220,7 @@ public void updateModelSessionAttributesRemoved() throws Exception {
221220
}
222221

223222
@Test // SPR-12542
224-
public void updateModelWhenRedirecting() throws Exception {
223+
void updateModelWhenRedirecting() throws Exception {
225224
String attributeName = "sessionAttr";
226225
String attribute = "value";
227226
ModelAndViewContainer container = new ModelAndViewContainer();
@@ -286,7 +285,7 @@ public Boolean nullModelAttr() {
286285
return null;
287286
}
288287

289-
@ModelAttribute(name="foo", binding=false)
288+
@ModelAttribute(name = "foo", binding = false)
290289
public Foo modelAttrWithBindingDisabled() {
291290
return new Foo();
292291
}

spring-web/src/test/java/org/springframework/web/method/annotation/SessionAttributesHandlerTests.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 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.
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.web.method.annotation;
1818

19-
2019
import java.util.HashSet;
2120

2221
import org.junit.jupiter.api.Test;
@@ -35,43 +34,48 @@
3534

3635
/**
3736
* Test fixture with {@link SessionAttributesHandler}.
37+
*
3838
* @author Rossen Stoyanchev
3939
*/
40-
public class SessionAttributesHandlerTests {
40+
class SessionAttributesHandlerTests {
4141

4242
private final SessionAttributeStore sessionAttributeStore = new DefaultSessionAttributeStore();
4343

44-
private final SessionAttributesHandler sessionAttributesHandler = new SessionAttributesHandler(
45-
SessionAttributeHandler.class, sessionAttributeStore);
44+
private final SessionAttributesHandler sessionAttributesHandler =
45+
new SessionAttributesHandler(TestSessionAttributesHolder.class, sessionAttributeStore);
4646

4747
private final NativeWebRequest request = new ServletWebRequest(new MockHttpServletRequest());
4848

4949

5050
@Test
51-
public void isSessionAttribute() throws Exception {
51+
void isSessionAttribute() {
5252
assertThat(sessionAttributesHandler.isHandlerSessionAttribute("attr1", String.class)).isTrue();
5353
assertThat(sessionAttributesHandler.isHandlerSessionAttribute("attr2", String.class)).isTrue();
5454
assertThat(sessionAttributesHandler.isHandlerSessionAttribute("simple", TestBean.class)).isTrue();
5555
assertThat(sessionAttributesHandler.isHandlerSessionAttribute("simple", String.class)).isFalse();
5656
}
5757

5858
@Test
59-
public void retrieveAttributes() throws Exception {
59+
void retrieveAttributes() {
6060
sessionAttributeStore.storeAttribute(request, "attr1", "value1");
6161
sessionAttributeStore.storeAttribute(request, "attr2", "value2");
6262
sessionAttributeStore.storeAttribute(request, "attr3", new TestBean());
6363
sessionAttributeStore.storeAttribute(request, "attr4", new TestBean());
6464

65-
assertThat(sessionAttributesHandler.retrieveAttributes(request).keySet()).as("Named attributes (attr1, attr2) should be 'known' right away").isEqualTo(new HashSet<>(asList("attr1", "attr2")));
65+
assertThat(sessionAttributesHandler.retrieveAttributes(request).keySet())
66+
.as("Named attributes (attr1, attr2) should be 'known' right away")
67+
.isEqualTo(new HashSet<>(asList("attr1", "attr2")));
6668

6769
// Resolve 'attr3' by type
6870
sessionAttributesHandler.isHandlerSessionAttribute("attr3", TestBean.class);
6971

70-
assertThat(sessionAttributesHandler.retrieveAttributes(request).keySet()).as("Named attributes (attr1, attr2) and resolved attribute (att3) should be 'known'").isEqualTo(new HashSet<>(asList("attr1", "attr2", "attr3")));
72+
assertThat(sessionAttributesHandler.retrieveAttributes(request).keySet())
73+
.as("Named attributes (attr1, attr2) and resolved attribute (attr3) should be 'known'")
74+
.isEqualTo(new HashSet<>(asList("attr1", "attr2", "attr3")));
7175
}
7276

7377
@Test
74-
public void cleanupAttributes() throws Exception {
78+
void cleanupAttributes() {
7579
sessionAttributeStore.storeAttribute(request, "attr1", "value1");
7680
sessionAttributeStore.storeAttribute(request, "attr2", "value2");
7781
sessionAttributeStore.storeAttribute(request, "attr3", new TestBean());
@@ -90,7 +94,7 @@ public void cleanupAttributes() throws Exception {
9094
}
9195

9296
@Test
93-
public void storeAttributes() throws Exception {
97+
void storeAttributes() {
9498
ModelMap model = new ModelMap();
9599
model.put("attr1", "value1");
96100
model.put("attr2", "value2");
@@ -105,8 +109,8 @@ public void storeAttributes() throws Exception {
105109
}
106110

107111

108-
@SessionAttributes(names = { "attr1", "attr2" }, types = { TestBean.class })
109-
private static class SessionAttributeHandler {
112+
@SessionAttributes(names = {"attr1", "attr2"}, types = TestBean.class)
113+
private static class TestSessionAttributesHolder {
110114
}
111115

112116
}

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ protected ModelAndView handleAsyncRequestTimeoutException(AsyncRequestTimeoutExc
438438
* Handle an {@link ErrorResponse} exception.
439439
* <p>The default implementation sets status and the headers of the response
440440
* to those obtained from the {@code ErrorResponse}. If available, the
441-
* {@link ProblemDetail#getDetail()} is used as the message for
441+
* {@link ProblemDetail#getDetail()} is used as the message for
442442
* {@link HttpServletResponse#sendError(int, String)}.
443443
* @param errorResponse the exception to be handled
444444
* @param request current HTTP request

0 commit comments

Comments
 (0)