Adding test cases

Adding test cases
This commit is contained in:
Himanshu Mantri 2017-05-24 16:30:32 +05:30
parent 140de5b0b2
commit aeb33fe72d
3 changed files with 93 additions and 0 deletions

4
.gitignore vendored
View File

@ -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

24
SpringDataInjectionDemo/.gitignore vendored Normal file
View File

@ -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/

View File

@ -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());
}
}