diff --git a/persistence-modules/spring-persistence-simple-2/src/main/java/com/baeldung/jdbc/EmployeeDAO.java b/persistence-modules/spring-persistence-simple-2/src/main/java/com/baeldung/jdbc/EmployeeDAO.java index a7adb7933a..b5bf9452ed 100644 --- a/persistence-modules/spring-persistence-simple-2/src/main/java/com/baeldung/jdbc/EmployeeDAO.java +++ b/persistence-modules/spring-persistence-simple-2/src/main/java/com/baeldung/jdbc/EmployeeDAO.java @@ -9,7 +9,7 @@ import org.springframework.stereotype.Repository; public class EmployeeDAO { private JdbcTemplate jdbcTemplate; - public void setDataSource(final DataSource dataSource) { + public void setDataSource(DataSource dataSource) { jdbcTemplate = new JdbcTemplate(dataSource); } diff --git a/persistence-modules/spring-persistence-simple-2/src/test/java/com/baeldung/jdbc/EmployeeDAOUnitTest.java b/persistence-modules/spring-persistence-simple-2/src/test/java/com/baeldung/jdbc/EmployeeDAOUnitTest.java index a64ba9b2f0..71e8fb4263 100644 --- a/persistence-modules/spring-persistence-simple-2/src/test/java/com/baeldung/jdbc/EmployeeDAOUnitTest.java +++ b/persistence-modules/spring-persistence-simple-2/src/test/java/com/baeldung/jdbc/EmployeeDAOUnitTest.java @@ -27,10 +27,12 @@ public class EmployeeDAOUnitTest { 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()); } @@ -40,8 +42,10 @@ public class EmployeeDAOUnitTest { .addScript("classpath:jdbc/schema.sql") .addScript("classpath:jdbc/test-data.sql") .build(); + EmployeeDAO employeeDAO = new EmployeeDAO(); employeeDAO.setDataSource(dataSource); + assertEquals(4, employeeDAO.getCountOfEmployees()); } }