This is an automated email from the ASF dual-hosted git repository.

panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new ca794ba  Revise #11476 for DatabaseDatetimeServiceTest (#11483)
ca794ba is described below

commit ca794baa9e298f8b4aa3072254bda6207b221229
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Jul 24 18:32:33 2021 +0800

    Revise #11476 for DatabaseDatetimeServiceTest (#11483)
---
 .../database/impl/DatabaseDatetimeServiceTest.java | 23 ++++------------------
 1 file changed, 4 insertions(+), 19 deletions(-)

diff --git 
a/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/test/java/org/apache/shardingsphere/datetime/database/impl/DatabaseDatetimeServiceTest.java
 
b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/test/java/org/apache/shardingsphere/datetime/database/impl/DatabaseDatetimeServiceTest.java
index 1174471..6047646 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/test/java/org/apache/shardingsphere/datetime/database/impl/DatabaseDatetimeServiceTest.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/test/java/org/apache/shardingsphere/datetime/database/impl/DatabaseDatetimeServiceTest.java
@@ -20,42 +20,29 @@ package org.apache.shardingsphere.datetime.database.impl;
 import org.apache.shardingsphere.infra.datetime.DatetimeService;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.mockito.Answers;
 import org.mockito.Mock;
 import org.mockito.junit.MockitoJUnitRunner;
 
 import javax.sql.DataSource;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.Date;
 
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
-import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 @RunWith(MockitoJUnitRunner.class)
 public final class DatabaseDatetimeServiceTest {
     
-    @Mock
+    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     private DataSource dataSource;
     
-    @Mock
-    private PreparedStatement preparedStatement;
-    
-    @Mock
-    private ResultSet resultSet;
-    
     private final String sql = "SELECT NOW()";
     
     @Test
     public void assertMySQLDateTime() throws SQLException {
-        Connection connection = mock(Connection.class);
-        when(dataSource.getConnection()).thenReturn(connection);
-        when(connection.prepareStatement(sql)).thenReturn(preparedStatement);
-        when(preparedStatement.executeQuery()).thenReturn(resultSet);
-        when((Date) resultSet.getObject(1)).thenReturn(new Date());
+        
when(dataSource.getConnection().prepareStatement(sql).executeQuery().getObject(1)).thenReturn(new
 Date());
         DatetimeService datetimeService = new 
DatabaseDatetimeService(dataSource, sql);
         assertFalse(datetimeService.isDefault());
         assertNotNull(datetimeService.getDatetime());
@@ -63,9 +50,7 @@ public final class DatabaseDatetimeServiceTest {
     
     @Test
     public void assertNoExceptionInDateTimeService() throws SQLException {
-        Connection connection = mock(Connection.class);
-        when(dataSource.getConnection()).thenReturn(connection);
-        when(connection.prepareStatement(sql)).thenThrow(new SQLException());
+        when(dataSource.getConnection().prepareStatement(sql)).thenThrow(new 
SQLException());
         DatetimeService datetimeService = new 
DatabaseDatetimeService(dataSource, sql);
         assertFalse(datetimeService.isDefault());
         assertNotNull(datetimeService.getDatetime());

Reply via email to