use of org.springframework.beans.testfixture.beans.TestBean in project spring-framework by spring-projects.
the class SelectTagTests method withNullValue.
@Test
public void withNullValue() throws Exception {
TestBean tb = getTestBean();
tb.setCountry(null);
this.tag.setPath("country");
this.tag.setItems(Country.getCountries());
assertList(false);
}
use of org.springframework.beans.testfixture.beans.TestBean in project spring-framework by spring-projects.
the class SelectTagTests method withOtherValue.
@Test
public void withOtherValue() throws Exception {
TestBean tb = getTestBean();
tb.setCountry("AT");
this.tag.setPath("country");
this.tag.setItems(Country.getCountries());
assertList(false);
}
use of org.springframework.beans.testfixture.beans.TestBean in project spring-framework by spring-projects.
the class ModelAttributeMethodProcessorTests method resolveArgumentOrdering.
// SPR-9378
@Test
public void resolveArgumentOrdering() throws Exception {
String name = "testBean";
Object testBean = new TestBean(name);
this.container.addAttribute(name, testBean);
this.container.addAttribute(BindingResult.MODEL_KEY_PREFIX + name, testBean);
Object anotherTestBean = new TestBean();
this.container.addAttribute("anotherTestBean", anotherTestBean);
StubRequestDataBinder dataBinder = new StubRequestDataBinder(testBean, name);
WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class);
given(binderFactory.createBinder(this.request, testBean, name)).willReturn(dataBinder);
this.processor.resolveArgument(this.paramModelAttr, this.container, this.request, binderFactory);
Object[] values = this.container.getModel().values().toArray();
assertThat(values[1]).as("Resolved attribute should be updated to be last").isSameAs(testBean);
assertThat(values[2]).as("BindingResult of resolved attr should be last").isSameAs(dataBinder.getBindingResult());
}
use of org.springframework.beans.testfixture.beans.TestBean in project spring-framework by spring-projects.
the class ModelAttributeMethodProcessorTests method resolveArgumentBindException.
@Test
public void resolveArgumentBindException() throws Exception {
String name = "testBean";
Object target = new TestBean();
this.container.getModel().addAttribute(target);
StubRequestDataBinder dataBinder = new StubRequestDataBinder(target, name);
dataBinder.getBindingResult().reject("error");
WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class);
given(binderFactory.createBinder(this.request, target, name)).willReturn(dataBinder);
assertThatExceptionOfType(BindException.class).isThrownBy(() -> this.processor.resolveArgument(this.paramNonSimpleType, this.container, this.request, binderFactory));
verify(binderFactory).createBinder(this.request, target, name);
}
use of org.springframework.beans.testfixture.beans.TestBean in project spring-framework by spring-projects.
the class ServletModelAttributeMethodProcessorTests method createAttributeUriTemplateVar.
@Test
public void createAttributeUriTemplateVar() throws Exception {
Map<String, String> uriTemplateVars = new HashMap<>();
uriTemplateVars.put("testBean1", "Patty");
request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars);
// Type conversion from "Patty" to TestBean via TestBean(String) constructor
TestBean testBean = (TestBean) processor.resolveArgument(testBeanModelAttr, mavContainer, webRequest, binderFactory);
assertThat(testBean.getName()).isEqualTo("Patty");
}
Aggregations