@ -47,7 +47,6 @@ import org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver;
@@ -47,7 +47,6 @@ import org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver;
import org.springframework.web.server.session.MockWebSessionManager ;
import org.springframework.web.server.session.WebSessionManager ;
import static org.junit.Assert.assertEquals ;
import static org.junit.Assert.assertFalse ;
import static org.junit.Assert.assertNotNull ;
import static org.junit.Assert.assertNull ;
@ -103,7 +102,7 @@ public class SessionAttributeMethodArgumentResolverTests {
@@ -103,7 +102,7 @@ public class SessionAttributeMethodArgumentResolverTests {
StepVerifier . create ( mono ) . expectError ( ServerWebInputException . class ) . verify ( ) ;
Foo foo = new Foo ( ) ;
when ( this . session . getAttribute ( "foo" ) ) . thenReturn ( Optional . of ( foo ) ) ;
when ( this . session . getAttribute ( "foo" ) ) . thenReturn ( foo ) ;
mono = this . resolver . resolveArgument ( param , new BindingContext ( ) , this . exchange ) ;
assertSame ( foo , mono . block ( ) ) ;
}
@ -112,7 +111,7 @@ public class SessionAttributeMethodArgumentResolverTests {
@@ -112,7 +111,7 @@ public class SessionAttributeMethodArgumentResolverTests {
public void resolveWithName ( ) throws Exception {
MethodParameter param = initMethodParameter ( 1 ) ;
Foo foo = new Foo ( ) ;
when ( this . session . getAttribute ( "specialFoo" ) ) . thenReturn ( Optional . of ( foo ) ) ;
when ( this . session . getAttribute ( "specialFoo" ) ) . thenReturn ( foo ) ;
Mono < Object > mono = this . resolver . resolveArgument ( param , new BindingContext ( ) , this . exchange ) ;
assertSame ( foo , mono . block ( ) ) ;
}
@ -124,32 +123,32 @@ public class SessionAttributeMethodArgumentResolverTests {
@@ -124,32 +123,32 @@ public class SessionAttributeMethodArgumentResolverTests {
assertNull ( mono . block ( ) ) ;
Foo foo = new Foo ( ) ;
when ( this . session . getAttribute ( "foo" ) ) . thenReturn ( Optional . of ( foo ) ) ;
when ( this . session . getAttribute ( "foo" ) ) . thenReturn ( foo ) ;
mono = this . resolver . resolveArgument ( param , new BindingContext ( ) , this . exchange ) ;
assertSame ( foo , mono . block ( ) ) ;
}
@SuppressWarnings ( "unchecked" )
@Test
public void resolveOptional ( ) throws Exception {
MethodParameter param = initMethodParameter ( 3 ) ;
Mono < Object > mono = this . resolver . resolveArgument ( param , new BindingContext ( ) , this . exchange ) ;
assertNotNull ( mono . block ( ) ) ;
assertEquals ( Optional . class , mono . block ( ) . getClass ( ) ) ;
assertFalse ( ( ( Optional < ? > ) mono . block ( ) ) . isPresent ( ) ) ;
Optional < Object > actual = ( Optional < Object > ) this . resolver
. resolveArgument ( param , new BindingContext ( ) , this . exchange ) . block ( ) ;
assertNotNull ( actual ) ;
assertFalse ( actual . isPresent ( ) ) ;
ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer ( ) ;
initializer . setConversionService ( new DefaultFormattingConversionService ( ) ) ;
BindingContext bindingContext = new BindingContext ( initializer ) ;
Foo foo = new Foo ( ) ;
when ( this . session . getAttribute ( "foo" ) ) . thenReturn ( Optional . of ( foo ) ) ;
mono = this . resolver . resolveArgument ( param , bindingContext , this . exchange ) ;
assertNotNull ( mono . block ( ) ) ;
assertEquals ( Optional . class , mono . block ( ) . getClass ( ) ) ;
Optional < ? > optional = ( Optional < ? > ) mono . block ( ) ;
assertTrue ( optional . isPresent ( ) ) ;
assertSame ( foo , optional . get ( ) ) ;
when ( this . session . getAttribute ( "foo" ) ) . thenReturn ( foo ) ;
actual = ( Optional < Object > ) this . resolver . resolveArgument ( param , bindingContext , this . exchange ) . block ( ) ;
assertNotNull ( actual ) ;
assertTrue ( actual . isPresent ( ) ) ;
assertSame ( foo , actual . get ( ) ) ;
}