Added Test for BeanFactory methods

This commit is contained in:
Shubham Aggarwal 2016-11-14 20:22:24 +05:30
parent a18523a103
commit 40841f93e5
3 changed files with 24 additions and 2 deletions

View File

@ -50,6 +50,11 @@
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
<build>

View File

@ -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);
}
}

View File

@ -8,4 +8,6 @@
<constructor-arg name="name" value="Hello! My name is Java"/>
<constructor-arg name="age" value="18"/>
</bean>
<alias name="employee" alias="empalias" />
</beans>