use of org.springframework.beans.testfixture.beans.ITestBean in project spring-framework by spring-projects.
the class AbstractPropertyAccessorTests method setPropertyValuesIgnoresInvalidNestedOnRequest.
@Test
void setPropertyValuesIgnoresInvalidNestedOnRequest() {
ITestBean target = new TestBean();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.addPropertyValue(new PropertyValue("name", "rod"));
pvs.addPropertyValue(new PropertyValue("graceful.rubbish", "tony"));
pvs.addPropertyValue(new PropertyValue("more.garbage", new Object()));
AbstractPropertyAccessor accessor = createAccessor(target);
accessor.setPropertyValues(pvs, true);
assertThat(target.getName().equals("rod")).as("Set valid and ignored invalid").isTrue();
assertThatExceptionOfType(NotWritablePropertyException.class).isThrownBy(() -> accessor.setPropertyValues(pvs, false));
}
use of org.springframework.beans.testfixture.beans.ITestBean in project spring-framework by spring-projects.
the class AbstractPropertyAccessorTests method setAnotherPropertyIntermediatePropertyIsNull.
@Test
void setAnotherPropertyIntermediatePropertyIsNull() throws Exception {
ITestBean target = new TestBean("rod", 31);
AbstractPropertyAccessor accessor = createAccessor(target);
assertThatExceptionOfType(NullValueInNestedPathException.class).isThrownBy(() -> accessor.setPropertyValue("spouse.age", 31)).satisfies(ex -> assertThat(ex.getPropertyName()).isEqualTo("spouse"));
}
use of org.springframework.beans.testfixture.beans.ITestBean in project spring-framework by spring-projects.
the class SimplePropertyNamespaceHandlerTests method innerBeanConfigured.
@Test
public void innerBeanConfigured() throws Exception {
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions(new ClassPathResource("simplePropertyNamespaceHandlerTests.xml", getClass()));
TestBean sally = (TestBean) beanFactory.getBean("sally2");
ITestBean rob = sally.getSpouse();
assertThat(rob.getName()).isEqualTo("Rob Harrop");
assertThat(rob.getAge()).isEqualTo(24);
assertThat(sally).isEqualTo(rob.getSpouse());
}
use of org.springframework.beans.testfixture.beans.ITestBean in project spring-framework by spring-projects.
the class SimplePropertyNamespaceHandlerTests method simpleBeanConfigured.
@Test
public void simpleBeanConfigured() throws Exception {
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions(new ClassPathResource("simplePropertyNamespaceHandlerTests.xml", getClass()));
ITestBean rob = (TestBean) beanFactory.getBean("rob");
ITestBean sally = (TestBean) beanFactory.getBean("sally");
assertThat(rob.getName()).isEqualTo("Rob Harrop");
assertThat(rob.getAge()).isEqualTo(24);
assertThat(sally).isEqualTo(rob.getSpouse());
}
use of org.springframework.beans.testfixture.beans.ITestBean in project spring-framework by spring-projects.
the class CounterAspect method testProgrammaticProxyCreation.
@Test
public void testProgrammaticProxyCreation() {
ITestBean testBean = new TestBean();
AspectJProxyFactory factory = new AspectJProxyFactory();
factory.setTarget(testBean);
CounterAspect myCounterAspect = new CounterAspect();
factory.addAspect(myCounterAspect);
ITestBean proxyTestBean = factory.getProxy();
boolean condition = proxyTestBean instanceof Advised;
assertThat(condition).as("Expected a proxy").isTrue();
proxyTestBean.setAge(20);
assertThat(myCounterAspect.count).as("Programmatically created proxy shouldn't match bean()").isEqualTo(0);
}
Aggregations