6464 */
6565public class ModelInitializerTests {
6666
67+ private static final Duration TIMEOUT = Duration .ofMillis (5000 );
68+
69+
6770 private ModelInitializer modelInitializer ;
6871
6972 private final ServerWebExchange exchange = MockServerWebExchange .from (MockServerHttpRequest .get ("/path" ));
@@ -93,7 +96,7 @@ public void initBinderMethod() {
9396
9497 Method method = ResolvableMethod .on (TestController .class ).annotPresent (GetMapping .class ).resolveMethod ();
9598 HandlerMethod handlerMethod = new HandlerMethod (controller , method );
96- this .modelInitializer .initModel (handlerMethod , context , this .exchange ).block (Duration . ofMillis ( 5000 ) );
99+ this .modelInitializer .initModel (handlerMethod , context , this .exchange ).block (TIMEOUT );
97100
98101 WebExchangeDataBinder binder = context .createDataBinder (this .exchange , "name" );
99102 assertThat (binder .getValidators ()).isEqualTo (Collections .singletonList (validator ));
@@ -107,7 +110,7 @@ public void modelAttributeMethods() {
107110
108111 Method method = ResolvableMethod .on (TestController .class ).annotPresent (GetMapping .class ).resolveMethod ();
109112 HandlerMethod handlerMethod = new HandlerMethod (controller , method );
110- this .modelInitializer .initModel (handlerMethod , context , this .exchange ).block (Duration . ofMillis ( 5000 ) );
113+ this .modelInitializer .initModel (handlerMethod , context , this .exchange ).block (TIMEOUT );
111114
112115 Map <String , Object > model = context .getModel ().asMap ();
113116 assertThat (model .size ()).isEqualTo (5 );
@@ -116,7 +119,7 @@ public void modelAttributeMethods() {
116119 assertThat (((TestBean ) value ).getName ()).isEqualTo ("Bean" );
117120
118121 value = model .get ("monoBean" );
119- assertThat (((Mono <TestBean >) value ).block (Duration . ofMillis ( 5000 ) ).getName ()).isEqualTo ("Mono Bean" );
122+ assertThat (((Mono <TestBean >) value ).block (TIMEOUT ).getName ()).isEqualTo ("Mono Bean" );
120123
121124 value = model .get ("singleBean" );
122125 assertThat (((Single <TestBean >) value ).toBlocking ().value ().getName ()).isEqualTo ("Single Bean" );
@@ -135,7 +138,7 @@ public void saveModelAttributeToSession() {
135138
136139 Method method = ResolvableMethod .on (TestController .class ).annotPresent (GetMapping .class ).resolveMethod ();
137140 HandlerMethod handlerMethod = new HandlerMethod (controller , method );
138- this .modelInitializer .initModel (handlerMethod , context , this .exchange ).block (Duration . ofMillis ( 5000 ) );
141+ this .modelInitializer .initModel (handlerMethod , context , this .exchange ).block (TIMEOUT );
139142
140143 WebSession session = this .exchange .getSession ().block (Duration .ZERO );
141144 assertThat (session ).isNotNull ();
@@ -148,7 +151,7 @@ public void saveModelAttributeToSession() {
148151
149152 @ Test
150153 public void retrieveModelAttributeFromSession () {
151- WebSession session = this .exchange .getSession ().block (Duration . ZERO );
154+ WebSession session = this .exchange .getSession ().block (TIMEOUT );
152155 assertThat (session ).isNotNull ();
153156
154157 TestBean testBean = new TestBean ("Session Bean" );
@@ -159,7 +162,7 @@ public void retrieveModelAttributeFromSession() {
159162
160163 Method method = ResolvableMethod .on (TestController .class ).annotPresent (GetMapping .class ).resolveMethod ();
161164 HandlerMethod handlerMethod = new HandlerMethod (controller , method );
162- this .modelInitializer .initModel (handlerMethod , context , this .exchange ).block (Duration . ofMillis ( 5000 ) );
165+ this .modelInitializer .initModel (handlerMethod , context , this .exchange ).block (TIMEOUT );
163166
164167 context .saveModel ();
165168 assertThat (session .getAttributes ().size ()).isEqualTo (1 );
@@ -174,13 +177,13 @@ public void requiredSessionAttributeMissing() {
174177 Method method = ResolvableMethod .on (TestController .class ).annotPresent (PostMapping .class ).resolveMethod ();
175178 HandlerMethod handlerMethod = new HandlerMethod (controller , method );
176179 assertThatIllegalArgumentException ().isThrownBy (() ->
177- this .modelInitializer .initModel (handlerMethod , context , this .exchange ).block (Duration . ofMillis ( 5000 ) ))
180+ this .modelInitializer .initModel (handlerMethod , context , this .exchange ).block (TIMEOUT ))
178181 .withMessage ("Required attribute 'missing-bean' is missing." );
179182 }
180183
181184 @ Test
182185 public void clearModelAttributeFromSession () {
183- WebSession session = this .exchange .getSession ().block (Duration . ZERO );
186+ WebSession session = this .exchange .getSession ().block (TIMEOUT );
184187 assertThat (session ).isNotNull ();
185188
186189 TestBean testBean = new TestBean ("Session Bean" );
@@ -191,7 +194,7 @@ public void clearModelAttributeFromSession() {
191194
192195 Method method = ResolvableMethod .on (TestController .class ).annotPresent (GetMapping .class ).resolveMethod ();
193196 HandlerMethod handlerMethod = new HandlerMethod (controller , method );
194- this .modelInitializer .initModel (handlerMethod , context , this .exchange ).block (Duration . ofMillis ( 5000 ) );
197+ this .modelInitializer .initModel (handlerMethod , context , this .exchange ).block (TIMEOUT );
195198
196199 context .getSessionStatus ().setComplete ();
197200 context .saveModel ();
0 commit comments