JAVA-959: Migrate spring-di to com.baeldung
This commit is contained in:
parent
5a9ac3ce57
commit
6906bb047d
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.store;
|
||||
package com.baeldung.store;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.store;
|
||||
package com.baeldung.store;
|
||||
|
||||
public interface Item {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.store;
|
||||
package com.baeldung.store;
|
||||
|
||||
public class ItemImpl1 implements Item {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.store;
|
||||
package com.baeldung.store;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
@ -6,9 +6,9 @@
|
|||
|
||||
<!-- Autowired injection -->
|
||||
|
||||
<bean id="item" class="org.baeldung.store.ItemImpl1" />
|
||||
<bean id="item" class="com.baeldung.store.ItemImpl1" />
|
||||
|
||||
<bean id="xml-store-by-autowire-type" class="org.baeldung.store.Store" autowire="byType">
|
||||
<bean id="xml-store-by-autowire-type" class="com.baeldung.store.Store" autowire="byType">
|
||||
</bean>
|
||||
|
||||
</beans>
|
|
@ -6,28 +6,28 @@
|
|||
|
||||
<!-- Constructor injection -->
|
||||
|
||||
<bean id="item1" class="org.baeldung.store.ItemImpl1" />
|
||||
<bean id="xml-store-by-constructor" class="org.baeldung.store.Store">
|
||||
<bean id="item1" class="com.baeldung.store.ItemImpl1" />
|
||||
<bean id="xml-store-by-constructor" class="com.baeldung.store.Store">
|
||||
<constructor-arg type="Item" index="0" name="item" ref="item1" />
|
||||
</bean>
|
||||
|
||||
<!-- Setter injection -->
|
||||
|
||||
<bean id="xml-store-by-setter" class="org.baeldung.store.Store">
|
||||
<bean id="xml-store-by-setter" class="com.baeldung.store.Store">
|
||||
<property name="item" ref="item1" />
|
||||
</bean>
|
||||
|
||||
<!-- Autowired injection -->
|
||||
|
||||
<bean id="item" class="org.baeldung.store.ItemImpl1" />
|
||||
<bean id="item" class="com.baeldung.store.ItemImpl1" />
|
||||
|
||||
<bean id="xml-store-by-autowire-name" class="org.baeldung.store.Store" autowire="byName">
|
||||
<bean id="xml-store-by-autowire-name" class="com.baeldung.store.Store" autowire="byName">
|
||||
</bean>
|
||||
|
||||
<!-- Lazy instantiation -->
|
||||
|
||||
<bean id="item1-lazy" class="org.baeldung.store.ItemImpl1" lazy-init="true" />
|
||||
<bean id="xml-store-by-setter-lazy" class="org.baeldung.store.Store">
|
||||
<bean id="item1-lazy" class="com.baeldung.store.ItemImpl1" lazy-init="true" />
|
||||
<bean id="xml-store-by-setter-lazy" class="com.baeldung.store.Store">
|
||||
<property name="item" ref="item1-lazy" />
|
||||
</bean>
|
||||
|
||||
|
|
|
@ -1,35 +1,35 @@
|
|||
package org.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());
|
||||
}
|
||||
}
|
||||
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());
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.store;
|
||||
package com.baeldung.store;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.store;
|
||||
package com.baeldung.store;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
Loading…
Reference in New Issue