use of org.springframework.beans.testfixture.beans.SideEffectBean in project spring-framework by spring-projects.
the class CommonsPool2TargetSourceTests method testConfigMixin.
@Test
void testConfigMixin() {
SideEffectBean pooled = (SideEffectBean) beanFactory.getBean("pooledWithMixin");
assertThat(pooled.getCount()).isEqualTo(INITIAL_COUNT);
PoolingConfig conf = (PoolingConfig) beanFactory.getBean("pooledWithMixin");
// TODO one invocation from setup
// assertEquals(1, conf.getInvocations());
pooled.doWork();
// assertEquals("No objects active", 0, conf.getActive());
assertThat(conf.getMaxSize()).as("Correct target source").isEqualTo(25);
// assertTrue("Some free", conf.getFree() > 0);
// assertEquals(2, conf.getInvocations());
assertThat(conf.getMaxSize()).isEqualTo(25);
}
use of org.springframework.beans.testfixture.beans.SideEffectBean in project spring-framework by spring-projects.
the class PrototypeTargetSourceTests method testPrototypeAndSingletonBehaveDifferently.
/**
* Test that multiple invocations of the prototype bean will result
* in no change to visible state, as a new instance is used.
* With the singleton, there will be change.
*/
@Test
public void testPrototypeAndSingletonBehaveDifferently() {
SideEffectBean singleton = (SideEffectBean) beanFactory.getBean("singleton");
assertThat(singleton.getCount()).isEqualTo(INITIAL_COUNT);
singleton.doWork();
assertThat(singleton.getCount()).isEqualTo((INITIAL_COUNT + 1));
SideEffectBean prototype = (SideEffectBean) beanFactory.getBean("prototype");
assertThat(prototype.getCount()).isEqualTo(INITIAL_COUNT);
prototype.doWork();
assertThat(prototype.getCount()).isEqualTo(INITIAL_COUNT);
}
use of org.springframework.beans.testfixture.beans.SideEffectBean in project spring-framework by spring-projects.
the class HotSwappableTargetSourceTests method testValidSwaps.
@Test
public void testValidSwaps() {
SideEffectBean target1 = (SideEffectBean) beanFactory.getBean("target1");
SideEffectBean target2 = (SideEffectBean) beanFactory.getBean("target2");
SideEffectBean proxied = (SideEffectBean) beanFactory.getBean("swappable");
assertThat(proxied.getCount()).isEqualTo(target1.getCount());
proxied.doWork();
assertThat(proxied.getCount()).isEqualTo((INITIAL_COUNT + 1));
HotSwappableTargetSource swapper = (HotSwappableTargetSource) beanFactory.getBean("swapper");
Object old = swapper.swap(target2);
assertThat(old).as("Correct old target was returned").isEqualTo(target1);
// TODO should be able to make this assertion: need to fix target handling
// in AdvisedSupport
// assertEquals(target2, ((Advised) proxied).getTarget());
assertThat(proxied.getCount()).isEqualTo(20);
proxied.doWork();
assertThat(target2.getCount()).isEqualTo(21);
// Swap it back
swapper.swap(target1);
assertThat(proxied.getCount()).isEqualTo(target1.getCount());
}
use of org.springframework.beans.testfixture.beans.SideEffectBean in project spring-framework by spring-projects.
the class ThreadLocalTargetSourceTests method testReuseInSameThread.
@Test
public void testReuseInSameThread() {
SideEffectBean apartment = (SideEffectBean) beanFactory.getBean("apartment");
assertThat(apartment.getCount()).isEqualTo(INITIAL_COUNT);
apartment.doWork();
assertThat(apartment.getCount()).isEqualTo((INITIAL_COUNT + 1));
apartment = (SideEffectBean) beanFactory.getBean("apartment");
assertThat(apartment.getCount()).isEqualTo((INITIAL_COUNT + 1));
}
use of org.springframework.beans.testfixture.beans.SideEffectBean in project spring-framework by spring-projects.
the class CommonsPool2TargetSourceTests method testFunctionality.
private void testFunctionality(String name) {
SideEffectBean pooled = (SideEffectBean) beanFactory.getBean(name);
assertThat(pooled.getCount()).isEqualTo(INITIAL_COUNT);
pooled.doWork();
assertThat(pooled.getCount()).isEqualTo((INITIAL_COUNT + 1));
pooled = (SideEffectBean) beanFactory.getBean(name);
// Just check that it works--we can't make assumptions
// about the count
pooled.doWork();
// assertEquals(INITIAL_COUNT + 1, apartment.getCount());
}
Aggregations