@Test public void resolveNotRequired() { MethodParameter param = initMethodParameter(2); Mono<Object> mono = this.resolver.resolveArgument(param, new BindingContext(), this.exchange); assertNull(mono.block()); Foo foo = new Foo(); when(this.session.getAttribute("foo")).thenReturn(foo); mono = this.resolver.resolveArgument(param, new BindingContext(), this.exchange); assertSame(foo, mono.block()); }
@Test public void resolveWithName() { MethodParameter param = initMethodParameter(1); Foo foo = new Foo(); when(this.session.getAttribute("specialFoo")).thenReturn(foo); Mono<Object> mono = this.resolver.resolveArgument(param, new BindingContext(), this.exchange); assertSame(foo, mono.block()); }
@Test public void resolve() { MethodParameter param = initMethodParameter(0); Mono<Object> mono = this.resolver.resolveArgument(param, new BindingContext(), this.exchange); StepVerifier.create(mono).expectError(ServerWebInputException.class).verify(); Foo foo = new 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() { MethodParameter param = initMethodParameter(3); 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(foo); actual = (Optional<Object>) this.resolver.resolveArgument(param, bindingContext, this.exchange).block(); assertNotNull(actual); assertTrue(actual.isPresent()); assertSame(foo, actual.get()); }