Commit f3df7ca0 by jorgecacs

Test implements

parent 12833a46
Pipeline #4 failed with stages
in 0 seconds
...@@ -55,6 +55,20 @@ ...@@ -55,6 +55,20 @@
<artifactId>mssql-jdbc</artifactId> <artifactId>mssql-jdbc</artifactId>
<version>6.1.0.jre8</version> <version>6.1.0.jre8</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
......
...@@ -14,6 +14,14 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -14,6 +14,14 @@ public class CustomerServiceImpl implements CustomerService {
@Autowired @Autowired
private CustomerDao customerDao; private CustomerDao customerDao;
public CustomerServiceImpl() {
}
public CustomerServiceImpl(CustomerDao customerDao) {
this.customerDao = customerDao;
}
public Customer getCustomer(String document) { public Customer getCustomer(String document) {
return customerDao.getCustomer(document); return customerDao.getCustomer(document);
......
package com.rshka.mcs.services;
import static org.junit.Assert.assertNotNull;
import javax.ws.rs.ext.ExceptionMapper;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.dao.EmptyResultDataAccessException;
import com.rshka.mcs.beans.Customer;
import com.rshka.mcs.dao.CustomerDaoImpl;
import com.rshka.mcs.service.CustomerServiceImpl;
import static com.rshka.mcs.utils.TestUtils.getCustomerByDocument;
@RunWith(MockitoJUnitRunner.class)
public class CustomerServiceImplTest {
@InjectMocks
CustomerServiceImpl customerServiceImpl;
@Mock
private CustomerDaoImpl customerDaoImpl;
@Rule
public ExpectedException thrown = ExpectedException.none();
public CustomerServiceImplTest() {
}
@Test
public void testGetCustomerOk() {
Mockito.when(this.customerDaoImpl.getCustomer(Mockito.anyString())).thenReturn(getCustomerByDocument());
this.customerServiceImpl = new CustomerServiceImpl(customerDaoImpl);
Customer customer = this.customerServiceImpl.getCustomer(Mockito.anyString());
assertNotNull(customer);
}
@Test
public void testGetCustomerNotOk() {
this.customerServiceImpl = new CustomerServiceImpl(customerDaoImpl);
Mockito.when(this.customerDaoImpl.getCustomer(Mockito.anyString())).thenThrow(new EmptyResultDataAccessException("Cannot find customer", 1));
EmptyResultDataAccessException expectedException = new EmptyResultDataAccessException("Cannot find customer", 1);
thrown.expect(EmptyResultDataAccessException.class);
Customer customer = this.customerServiceImpl.getCustomer(Mockito.anyString());
}
}
\ No newline at end of file
package com.rshka.mcs.utils;
import com.rshka.mcs.beans.Customer;
public class TestUtils {
public static Customer getCustomerByDocument() {
return new Customer(1, "Persona Nombre", "Avenida 1", "133 443", "12312312");
}
}
#Generated by Maven Integration for Eclipse #Generated by Maven Integration for Eclipse
#Thu Jan 16 22:35:34 PYST 2020 #Fri Jan 17 07:51:57 PYST 2020
version=0.0.1-SNAPSHOT version=0.0.1-SNAPSHOT
groupId=com.rshk.demo.mcs groupId=com.rshk.demo.mcs
m2e.projectName=demo_mcs m2e.projectName=demo_mcs
......
...@@ -55,6 +55,20 @@ ...@@ -55,6 +55,20 @@
<artifactId>mssql-jdbc</artifactId> <artifactId>mssql-jdbc</artifactId>
<version>6.1.0.jre8</version> <version>6.1.0.jre8</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment