diff --git a/spring-core/pom.xml b/spring-core/pom.xml index 9b94ba7b35..9b6addf0f4 100644 --- a/spring-core/pom.xml +++ b/spring-core/pom.xml @@ -50,6 +50,11 @@ javax.inject 1 + + junit + junit + 4.12 + diff --git a/spring-core/src/main/java/com/baeldung/beanfactory/BeanFactoryWithClassPathResource.java b/spring-core/src/main/java/com/baeldung/beanfactory/BeanFactoryWithClassPathResource.java index aff425a87b..bb9309f394 100644 --- a/spring-core/src/main/java/com/baeldung/beanfactory/BeanFactoryWithClassPathResource.java +++ b/spring-core/src/main/java/com/baeldung/beanfactory/BeanFactoryWithClassPathResource.java @@ -1,16 +1,31 @@ package com.baeldung.beanfactory; +import org.junit.Test; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + public class BeanFactoryWithClassPathResource { + Resource res = new ClassPathResource("spring-app.xml"); + BeanFactory factory = new XmlBeanFactory(res); + + @Test public void createBeanFactory() { - Resource res = new ClassPathResource("spring-app.xml"); - BeanFactory factory = new XmlBeanFactory(res); Employee emp = (Employee) factory.getBean("employee"); + + assertFalse(factory.isSingleton("employee")); + + assertTrue(factory.getBean("employee") instanceof Employee); + + assertTrue(factory.isTypeMatch("employee", Employee.class)); + + //we have empalias as an alias for employee + assertTrue(factory.getAliases("employee").length > 0); } } diff --git a/spring-core/src/main/java/com/baeldung/beanfactory/spring-app.xml b/spring-core/src/main/java/com/baeldung/beanfactory/spring-app.xml index 5bdc3e601a..7b3d4f29ed 100644 --- a/spring-core/src/main/java/com/baeldung/beanfactory/spring-app.xml +++ b/spring-core/src/main/java/com/baeldung/beanfactory/spring-app.xml @@ -8,4 +8,6 @@ + + \ No newline at end of file