parent
140de5b0b2
commit
aeb33fe72d
|
@ -33,3 +33,7 @@ spring-openid/src/main/resources/application.properties
|
|||
spring-security-openid/src/main/resources/application.properties
|
||||
|
||||
spring-all/*.log
|
||||
|
||||
*.jar
|
||||
|
||||
SpringDataInjectionDemo/.mvn/wrapper/maven-wrapper.properties
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
nbproject/private/
|
||||
build/
|
||||
nbbuild/
|
||||
dist/
|
||||
nbdist/
|
||||
.nb-gradle/
|
|
@ -0,0 +1,65 @@
|
|||
package com.baeldung.didemo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.baeldung.didemo.model.Order;
|
||||
import com.baeldung.didemo.service.CustomerServiceConstructorDI;
|
||||
import com.baeldung.didemo.service.CustomerServiceFieldDI;
|
||||
import com.baeldung.didemo.service.CustomerServiceSetterDI;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class SpringDataInjectionDemoApplicationTests {
|
||||
|
||||
@Autowired
|
||||
CustomerServiceConstructorDI constructorDI;
|
||||
|
||||
@Autowired
|
||||
CustomerServiceFieldDI fieldDI;
|
||||
|
||||
@Autowired
|
||||
CustomerServiceSetterDI setterDI;
|
||||
|
||||
@Test
|
||||
public void testConstructorDI() {
|
||||
List<Order> orders = constructorDI.getCustomerOrders(1l);
|
||||
Assert.assertNotNull(orders);
|
||||
Assert.assertTrue(orders.size() == 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldDI() {
|
||||
List<Order> orders = fieldDI.getCustomerOrders(1l);
|
||||
Assert.assertNotNull(orders);
|
||||
Assert.assertTrue(orders.size() == 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetterDI() {
|
||||
List<Order> orders = setterDI.getCustomerOrders(1l);
|
||||
Assert.assertNotNull(orders);
|
||||
Assert.assertTrue(orders.size() == 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCombined() {
|
||||
List<Order> ordersSetter = setterDI.getCustomerOrders(1l);
|
||||
List<Order> ordersConstructor = constructorDI.getCustomerOrders(1l);
|
||||
List<Order> ordersField = fieldDI.getCustomerOrders(1l);
|
||||
|
||||
Assert.assertNotNull(ordersSetter);
|
||||
Assert.assertNotNull(ordersConstructor);
|
||||
Assert.assertNotNull(ordersField);
|
||||
Assert.assertTrue(ordersSetter.size() == 2 && ordersConstructor.size() == ordersSetter.size() && ordersField.size() == ordersSetter.size());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue