From 5e97741b072cf19eec9e7c7e33ae4ebae2366f53 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Sat, 21 Mar 2020 11:29:55 -0600 Subject: [PATCH] Revert "BAEL-3069 Spring jdbcTemplate Unit Testing" This reverts commit d4a928cdfac363353c293a7f0b0abcd936a77919. --- .../spring-persistence-simple/pom.xml | 7 --- .../baeldung/jdbc/EmployeeDAOUnitTest.java | 49 ------------------- 2 files changed, 56 deletions(-) delete mode 100644 persistence-modules/spring-persistence-simple/src/test/java/com/baeldung/jdbc/EmployeeDAOUnitTest.java diff --git a/persistence-modules/spring-persistence-simple/pom.xml b/persistence-modules/spring-persistence-simple/pom.xml index 45605c853e..8a03310048 100644 --- a/persistence-modules/spring-persistence-simple/pom.xml +++ b/persistence-modules/spring-persistence-simple/pom.xml @@ -92,12 +92,6 @@ ${org.springframework.version} test - - org.mockito - mockito-core - ${mockito.version} - test - com.querydsl querydsl-jpa @@ -143,7 +137,6 @@ 9.0.0.M26 1.1 4.2.1 - 3.3.3 21.0 diff --git a/persistence-modules/spring-persistence-simple/src/test/java/com/baeldung/jdbc/EmployeeDAOUnitTest.java b/persistence-modules/spring-persistence-simple/src/test/java/com/baeldung/jdbc/EmployeeDAOUnitTest.java deleted file mode 100644 index 9894801a53..0000000000 --- a/persistence-modules/spring-persistence-simple/src/test/java/com/baeldung/jdbc/EmployeeDAOUnitTest.java +++ /dev/null @@ -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()); - } - -}