separate configs

This commit is contained in:
Loredana Crusoveanu
2018-06-24 19:22:26 +03:00
parent fd34932f4c
commit 32a9212fc9
4 changed files with 67 additions and 33 deletions
@@ -60,19 +60,4 @@ 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);
PrototypeBean firstInstance = firstContext.getPrototypeInstance("instance1");
PrototypeBean secondInstance = secondContext.getPrototypeInstance("instance2");
Assert.assertTrue("New instance expected", firstInstance != secondInstance);
}
}
@@ -0,0 +1,35 @@
package com.baeldung.scope;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import com.baeldung.factorybean.FactoryBeanAppConfig;
import com.baeldung.scope.prototype.PrototypeBean;
import com.baeldung.scope.singletone.SingletonFunctionBean;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(loader = AnnotationConfigContextLoader.class, classes = FactoryBeanAppConfig.class)
public class PrototypeFunctionBeanIntegrationTest {
@Test
public void givenPrototypeInjection_WhenFunction_ThenNewInstanceReturn() {
AbstractApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
SingletonFunctionBean firstContext = context.getBean(SingletonFunctionBean.class);
SingletonFunctionBean secondContext = context.getBean(SingletonFunctionBean.class);
PrototypeBean firstInstance = firstContext.getPrototypeInstance("instance1");
PrototypeBean secondInstance = secondContext.getPrototypeInstance("instance2");
Assert.assertTrue("New instance expected", firstInstance != secondInstance);
}
}