add prototype bean ex with function

This commit is contained in:
Loredana Crusoveanu
2018-06-24 13:03:31 +03:00
parent 0242d74b93
commit 1cea9ee088
6 changed files with 115 additions and 0 deletions
@@ -1,6 +1,8 @@
package com.baeldung.scope;
import com.baeldung.scope.prototype.PrototypeBean;
import com.baeldung.scope.prototype.PrototypeBeanWithParam;
import com.baeldung.scope.singletone.SingletonFunctionBean;
import com.baeldung.scope.singletone.SingletonLookupBean;
import com.baeldung.scope.singletone.SingletonObjectFactoryBean;
import com.baeldung.scope.singletone.SingletonProviderBean;
@@ -58,4 +60,20 @@ public class PrototypeBeanInjectionIntegrationTest {
Assert.assertTrue("New instance expected", firstInstance != secondInstance);
}
@Test
public void givenPrototypeInjection_WhenFunction_ThenNewInstanceReturn() {
AbstractApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
SingletonFunctionBean firstContext = context.getBean(SingletonFunctionBean.class);
SingletonFunctionBean secondContext = context.getBean(SingletonFunctionBean.class);
PrototypeBeanWithParam firstInstance = firstContext.getPrototypeInstance("instance1");
PrototypeBeanWithParam secondInstance = secondContext.getPrototypeInstance("instance2");
Assert.assertTrue("New instance expected", firstInstance != secondInstance);
}
}