Revert "BAEL-3069 Spring jdbcTemplate Unit Testing"
This reverts commit d4a928cdfa
.
This commit is contained in:
parent
d4a928cdfa
commit
5e97741b07
|
@ -92,12 +92,6 @@
|
|||
<version>${org.springframework.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>${mockito.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.querydsl</groupId>
|
||||
<artifactId>querydsl-jpa</artifactId>
|
||||
|
@ -143,7 +137,6 @@
|
|||
<tomcat-dbcp.version>9.0.0.M26</tomcat-dbcp.version>
|
||||
<jta.version>1.1</jta.version>
|
||||
<querydsl.version>4.2.1</querydsl.version>
|
||||
<mockito.version>3.3.3</mockito.version>
|
||||
|
||||
<!-- util -->
|
||||
<guava.version>21.0</guava.version>
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
package com.baeldung.jdbc;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
|
||||
public class EmployeeDAOUnitTest {
|
||||
|
||||
@Mock
|
||||
JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Test
|
||||
public void whenMockJdbcTemplate_thenReturnCorrectEmployeeCount() {
|
||||
EmployeeDAO employeeDAO = new EmployeeDAO();
|
||||
ReflectionTestUtils.setField(employeeDAO, "jdbcTemplate", jdbcTemplate);
|
||||
Mockito.when(jdbcTemplate.queryForObject("SELECT COUNT(*) FROM EMPLOYEE", Integer.class))
|
||||
.thenReturn(4);
|
||||
assertEquals(4, employeeDAO.getCountOfEmployees());
|
||||
|
||||
Mockito.when(jdbcTemplate.queryForObject(Mockito.anyString(), Mockito.eq(Integer.class)))
|
||||
.thenReturn(3);
|
||||
assertEquals(3, employeeDAO.getCountOfEmployees());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInjectInMemoryDataSource_thenReturnCorrectEmployeeCount() {
|
||||
DataSource dataSource = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2)
|
||||
.addScript("classpath:jdbc/schema.sql")
|
||||
.addScript("classpath:jdbc/test-data.sql")
|
||||
.build();
|
||||
EmployeeDAO employeeDAO = new EmployeeDAO();
|
||||
employeeDAO.setDataSource(dataSource);
|
||||
assertEquals(4, employeeDAO.getCountOfEmployees());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue