Added Test for BeanFactory methods
This commit is contained in:
parent
a18523a103
commit
40841f93e5
|
@ -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>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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>
|
Loading…
Reference in New Issue