BAEL-3744: Corrected test method names and added XML-based tests.
This commit is contained in:
parent
76df3d0117
commit
53183ba166
@ -1,36 +1,61 @@
|
|||||||
package com.baeldung.spring.patterns.factory;
|
package com.baeldung.spring.patterns.factory;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
public class AnnotationConfigApplicationContextTest {
|
|
||||||
|
public class AnnotationConfigApplicationContextTest {
|
||||||
@Test
|
|
||||||
@SuppressWarnings("resource")
|
@Test
|
||||||
public void whenGetSimpleBean_ThenReturnConstructedBean() {
|
@SuppressWarnings("resource")
|
||||||
|
public void whenGetSimpleBean_thenReturnConstructedBean() {
|
||||||
ApplicationContext context = new AnnotationConfigApplicationContext(ApplicationConfig.class);
|
|
||||||
|
ApplicationContext context = new AnnotationConfigApplicationContext(ApplicationConfig.class);
|
||||||
Foo foo = context.getBean(Foo.class);
|
|
||||||
|
Foo foo = context.getBean(Foo.class);
|
||||||
assertNotNull(foo);
|
|
||||||
}
|
assertNotNull(foo);
|
||||||
|
}
|
||||||
@Test
|
|
||||||
@SuppressWarnings("resource")
|
@Test
|
||||||
public void whenGetPrototypeBean_ThenReturnConstructedBean() {
|
@SuppressWarnings("resource")
|
||||||
|
public void whenGetPrototypeBean_thenReturnConstructedBean() {
|
||||||
String expectedName = "Some name";
|
|
||||||
ApplicationContext context = new AnnotationConfigApplicationContext(ApplicationConfig.class);
|
String expectedName = "Some name";
|
||||||
|
ApplicationContext context = new AnnotationConfigApplicationContext(ApplicationConfig.class);
|
||||||
Bar bar = context.getBean(Bar.class, expectedName);
|
|
||||||
|
Bar bar = context.getBean(Bar.class, expectedName);
|
||||||
assertNotNull(bar);
|
|
||||||
assertThat(bar.getName(), is(expectedName));
|
assertNotNull(bar);
|
||||||
}
|
assertThat(bar.getName(), is(expectedName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("resource")
|
||||||
|
public void givenXmlConfiguration_whenGetSimpleBean_thenReturnConstructedBean() {
|
||||||
|
|
||||||
|
ApplicationContext context = new ClassPathXmlApplicationContext("patterns-context.xml");
|
||||||
|
|
||||||
|
Foo foo = context.getBean(Foo.class);
|
||||||
|
|
||||||
|
assertNotNull(foo);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("resource")
|
||||||
|
public void givenXmlConfiguration_whenGetPrototypeBean_thenReturnConstructedBean() {
|
||||||
|
|
||||||
|
String expectedName = "Some name";
|
||||||
|
ApplicationContext context = new ClassPathXmlApplicationContext("patterns-context.xml");
|
||||||
|
|
||||||
|
Bar bar = context.getBean(Bar.class, expectedName);
|
||||||
|
|
||||||
|
assertNotNull(bar);
|
||||||
|
assertThat(bar.getName(), is(expectedName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
9
spring-core-3/src/test/resources/patterns-context.xml
Normal file
9
spring-core-3/src/test/resources/patterns-context.xml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||||
|
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
|
||||||
|
|
||||||
|
<bean id="foo" class="com.baeldung.spring.patterns.factory.Foo" />
|
||||||
|
<bean id="bar" scope="prototype" class="com.baeldung.spring.patterns.factory.Bar" />
|
||||||
|
</beans>
|
Loading…
x
Reference in New Issue
Block a user