1
1
/*
2
- * Copyright 2002-2023 the original author or authors.
2
+ * Copyright 2002-2024 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
51
51
*
52
52
* @author Rossen Stoyanchev
53
53
*/
54
- public class ModelFactoryTests {
54
+ class ModelFactoryTests {
55
55
56
56
private NativeWebRequest webRequest ;
57
57
@@ -65,7 +65,7 @@ public class ModelFactoryTests {
65
65
66
66
67
67
@ BeforeEach
68
- public void setUp () throws Exception {
68
+ void setup () {
69
69
this .webRequest = new ServletWebRequest (new MockHttpServletRequest ());
70
70
this .attributeStore = new DefaultSessionAttributeStore ();
71
71
this .attributeHandler = new SessionAttributesHandler (TestController .class , this .attributeStore );
@@ -75,7 +75,7 @@ public void setUp() throws Exception {
75
75
76
76
77
77
@ Test
78
- public void modelAttributeMethod () throws Exception {
78
+ void modelAttributeMethod () throws Exception {
79
79
ModelFactory modelFactory = createModelFactory ("modelAttr" , Model .class );
80
80
HandlerMethod handlerMethod = createHandlerMethod ("handle" );
81
81
modelFactory .initModel (this .webRequest , this .mavContainer , handlerMethod );
@@ -84,7 +84,7 @@ public void modelAttributeMethod() throws Exception {
84
84
}
85
85
86
86
@ Test
87
- public void modelAttributeMethodWithExplicitName () throws Exception {
87
+ void modelAttributeMethodWithExplicitName () throws Exception {
88
88
ModelFactory modelFactory = createModelFactory ("modelAttrWithName" );
89
89
HandlerMethod handlerMethod = createHandlerMethod ("handle" );
90
90
modelFactory .initModel (this .webRequest , this .mavContainer , handlerMethod );
@@ -93,7 +93,7 @@ public void modelAttributeMethodWithExplicitName() throws Exception {
93
93
}
94
94
95
95
@ Test
96
- public void modelAttributeMethodWithNameByConvention () throws Exception {
96
+ void modelAttributeMethodWithNameByConvention () throws Exception {
97
97
ModelFactory modelFactory = createModelFactory ("modelAttrConvention" );
98
98
HandlerMethod handlerMethod = createHandlerMethod ("handle" );
99
99
modelFactory .initModel (this .webRequest , this .mavContainer , handlerMethod );
@@ -102,7 +102,7 @@ public void modelAttributeMethodWithNameByConvention() throws Exception {
102
102
}
103
103
104
104
@ Test
105
- public void modelAttributeMethodWithNullReturnValue () throws Exception {
105
+ void modelAttributeMethodWithNullReturnValue () throws Exception {
106
106
ModelFactory modelFactory = createModelFactory ("nullModelAttr" );
107
107
HandlerMethod handlerMethod = createHandlerMethod ("handle" );
108
108
modelFactory .initModel (this .webRequest , this .mavContainer , handlerMethod );
@@ -112,7 +112,7 @@ public void modelAttributeMethodWithNullReturnValue() throws Exception {
112
112
}
113
113
114
114
@ Test
115
- public void modelAttributeWithBindingDisabled () throws Exception {
115
+ void modelAttributeWithBindingDisabled () throws Exception {
116
116
ModelFactory modelFactory = createModelFactory ("modelAttrWithBindingDisabled" );
117
117
HandlerMethod handlerMethod = createHandlerMethod ("handle" );
118
118
modelFactory .initModel (this .webRequest , this .mavContainer , handlerMethod );
@@ -122,7 +122,7 @@ public void modelAttributeWithBindingDisabled() throws Exception {
122
122
}
123
123
124
124
@ Test
125
- public void modelAttributeFromSessionWithBindingDisabled () throws Exception {
125
+ void modelAttributeFromSessionWithBindingDisabled () throws Exception {
126
126
Foo foo = new Foo ();
127
127
this .attributeStore .storeAttribute (this .webRequest , "foo" , foo );
128
128
@@ -136,7 +136,7 @@ public void modelAttributeFromSessionWithBindingDisabled() throws Exception {
136
136
}
137
137
138
138
@ Test
139
- public void sessionAttribute () throws Exception {
139
+ void sessionAttribute () throws Exception {
140
140
this .attributeStore .storeAttribute (this .webRequest , "sessionAttr" , "sessionAttrValue" );
141
141
142
142
ModelFactory modelFactory = createModelFactory ("modelAttr" , Model .class );
@@ -147,21 +147,20 @@ public void sessionAttribute() throws Exception {
147
147
}
148
148
149
149
@ Test
150
- public void sessionAttributeNotPresent () throws Exception {
150
+ void sessionAttributeNotPresent () throws Exception {
151
151
ModelFactory modelFactory = new ModelFactory (null , null , this .attributeHandler );
152
152
HandlerMethod handlerMethod = createHandlerMethod ("handleSessionAttr" , String .class );
153
153
assertThatExceptionOfType (HttpSessionRequiredException .class ).isThrownBy (() ->
154
154
modelFactory .initModel (this .webRequest , this .mavContainer , handlerMethod ));
155
155
156
156
// Now add attribute and try again
157
157
this .attributeStore .storeAttribute (this .webRequest , "sessionAttr" , "sessionAttrValue" );
158
-
159
158
modelFactory .initModel (this .webRequest , this .mavContainer , handlerMethod );
160
159
assertThat (this .mavContainer .getModel ().get ("sessionAttr" )).isEqualTo ("sessionAttrValue" );
161
160
}
162
161
163
162
@ Test
164
- public void updateModelBindingResult () throws Exception {
163
+ void updateModelBindingResult () throws Exception {
165
164
String commandName = "attr1" ;
166
165
Object command = new Object ();
167
166
ModelAndViewContainer container = new ModelAndViewContainer ();
@@ -181,7 +180,7 @@ public void updateModelBindingResult() throws Exception {
181
180
}
182
181
183
182
@ Test
184
- public void updateModelSessionAttributesSaved () throws Exception {
183
+ void updateModelSessionAttributesSaved () throws Exception {
185
184
String attributeName = "sessionAttr" ;
186
185
String attribute = "value" ;
187
186
ModelAndViewContainer container = new ModelAndViewContainer ();
@@ -199,7 +198,7 @@ public void updateModelSessionAttributesSaved() throws Exception {
199
198
}
200
199
201
200
@ Test
202
- public void updateModelSessionAttributesRemoved () throws Exception {
201
+ void updateModelSessionAttributesRemoved () throws Exception {
203
202
String attributeName = "sessionAttr" ;
204
203
String attribute = "value" ;
205
204
ModelAndViewContainer container = new ModelAndViewContainer ();
@@ -221,7 +220,7 @@ public void updateModelSessionAttributesRemoved() throws Exception {
221
220
}
222
221
223
222
@ Test // SPR-12542
224
- public void updateModelWhenRedirecting () throws Exception {
223
+ void updateModelWhenRedirecting () throws Exception {
225
224
String attributeName = "sessionAttr" ;
226
225
String attribute = "value" ;
227
226
ModelAndViewContainer container = new ModelAndViewContainer ();
@@ -286,7 +285,7 @@ public Boolean nullModelAttr() {
286
285
return null ;
287
286
}
288
287
289
- @ ModelAttribute (name = "foo" , binding = false )
288
+ @ ModelAttribute (name = "foo" , binding = false )
290
289
public Foo modelAttrWithBindingDisabled () {
291
290
return new Foo ();
292
291
}
0 commit comments