JAVA-959: Migrate spring-di to com.baeldung

This commit is contained in:
Krzysiek
2020-03-11 21:09:04 +01:00
parent 5a9ac3ce57
commit 6906bb047d
9 changed files with 50 additions and 50 deletions
@@ -0,0 +1,35 @@
package com.baeldung.store;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = AppConfig.class)
public class AppConfigUnitTest {
@Autowired
@Qualifier("storeThroughConstructorInjection")
private Store storeByConstructorInjection;
@Autowired
@Qualifier("storeThroughSetterInjection")
private Store storeBySetterInjection;
@Test
public void givenValidXmlConfig_WhenInjectStoreByConstructorInjection_ThenBeanIsNotNull() {
assertNotNull(storeByConstructorInjection);
assertNotNull(storeByConstructorInjection.getItem());
}
@Test
public void givenValidXmlConfig_WhenInjectStoreBySetterInjection_ThenBeanIsNotNull() {
assertNotNull(storeBySetterInjection);
assertNotNull(storeByConstructorInjection.getItem());
}
}
@@ -0,0 +1,30 @@
package com.baeldung.store;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* Separate unit test class where only one Item object is available for
* autowiring. If the ioc-context.xml were used for autowiring by type, there
* would be multiple qualifying Item objects, causing a failure.
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:/ioc-context-by-type.xml")
public class XmlAppConfigByTypeUnitTest {
@Autowired
@Qualifier("xml-store-by-autowire-type")
private Store storeByAutowireInjectionByType;
@Test
public void givenValidXmlConfig_WhenInjectStoreByAutowireInjectionByType_ThenBeanIsNotNull() {
assertNotNull(storeByAutowireInjectionByType);
assertNotNull(storeByAutowireInjectionByType.getItem());
}
}
@@ -0,0 +1,55 @@
package com.baeldung.store;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:/ioc-context.xml")
public class XmlAppConfigUnitTest {
@Autowired
@Qualifier("xml-store-by-constructor")
private Store storeByConstructorInjection;
@Autowired
@Qualifier("xml-store-by-setter")
private Store storeBySetterInjection;
@Autowired
@Qualifier("xml-store-by-autowire-name")
private Store storeByAutowireInjectionByName;
@Autowired
@Qualifier("xml-store-by-setter-lazy")
private Store storeBySetterInjectionLazy;
@Test
public void givenValidXmlConfig_WhenInjectStoreByConstructorInjection_ThenBeanIsNotNull() {
assertNotNull(storeByConstructorInjection);
assertNotNull(storeByConstructorInjection.getItem());
}
@Test
public void givenValidXmlConfig_WhenInjectStoreBySetterInjection_ThenBeanIsNotNull() {
assertNotNull(storeBySetterInjection);
assertNotNull(storeByConstructorInjection.getItem());
}
@Test
public void givenValidXmlConfig_WhenInjectStoreByAutowireInjectionByName_ThenBeanIsNotNull() {
assertNotNull(storeByAutowireInjectionByName);
assertNotNull(storeByAutowireInjectionByName.getItem());
}
@Test
public void givenValidXmlConfig_WhenInjectStoreBySetterInjectionLazy_ThenBeanIsNotNull() {
assertNotNull(storeBySetterInjectionLazy);
assertNotNull(storeByConstructorInjection.getItem());
}
}