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

chengzhang 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 014994e1b19 Refactor ShowSingleTablesExecutorTest (#33099)
014994e1b19 is described below

commit 014994e1b1937a1435c7a2afcb499a0b9ebdf905
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Oct 2 17:11:25 2024 +0800

    Refactor ShowSingleTablesExecutorTest (#33099)
    
    * Refactor ShowSingleTablesExecutorTest
    
    * Refactor ShowSingleTablesExecutorTest
---
 .../query/ShowSingleTablesExecutorTest.java        | 52 +++++++++-------------
 1 file changed, 21 insertions(+), 31 deletions(-)

diff --git 
a/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/query/ShowSingleTablesExecutorTest.java
 
b/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/query/ShowSingleTablesExecutorTest.java
index dbcd9757667..3dbfc06b28d 100644
--- 
a/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/query/ShowSingleTablesExecutorTest.java
+++ 
b/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/query/ShowSingleTablesExecutorTest.java
@@ -30,10 +30,11 @@ import org.apache.shardingsphere.single.rule.SingleRule;
 import org.junit.jupiter.api.Test;
 
 import java.sql.SQLException;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 
@@ -45,10 +46,26 @@ import static org.mockito.Mockito.when;
 
 class ShowSingleTablesExecutorTest {
     
-    private DistSQLQueryExecuteEngine engine;
+    @Test
+    void assertExecuteQuery() throws SQLException {
+        DistSQLQueryExecuteEngine executeEngine = new 
DistSQLQueryExecuteEngine(mock(ShowSingleTablesStatement.class), "foo_db", 
mockContextManager(), mock(DistSQLConnectionContext.class));
+        executeEngine.executeQuery();
+        List<LocalDataQueryResultRow> actual = new 
ArrayList<>(executeEngine.getRows());
+        assertThat(actual.size(), is(2));
+        assertThat(actual.get(0).getCell(1), is("t_order"));
+        assertThat(actual.get(0).getCell(2), is("ds_1"));
+        assertThat(actual.get(1).getCell(1), is("t_order_item"));
+        assertThat(actual.get(1).getCell(2), is("ds_2"));
+    }
     
-    DistSQLQueryExecuteEngine setUp(final ShowSingleTablesStatement statement) 
{
-        return new DistSQLQueryExecuteEngine(statement, "foo_db", 
mockContextManager(), mock(DistSQLConnectionContext.class));
+    @Test
+    void assertExecuteQueryWithLikeLiteral() throws SQLException {
+        DistSQLQueryExecuteEngine executeEngine = new 
DistSQLQueryExecuteEngine(new ShowSingleTablesStatement(null, "%item"), 
"foo_db", mockContextManager(), mock(DistSQLConnectionContext.class));
+        executeEngine.executeQuery();
+        List<LocalDataQueryResultRow> actual = new 
ArrayList<>(executeEngine.getRows());
+        assertThat(actual.size(), is(1));
+        assertThat(actual.get(0).getCell(1), is("t_order_item"));
+        assertThat(actual.get(0).getCell(2), is("ds_2"));
     }
     
     private ContextManager mockContextManager() {
@@ -60,33 +77,6 @@ class ShowSingleTablesExecutorTest {
         return result;
     }
     
-    @Test
-    void assertGetRowData() throws SQLException {
-        engine = setUp(mock(ShowSingleTablesStatement.class));
-        engine.executeQuery();
-        Collection<LocalDataQueryResultRow> actual = engine.getRows();
-        assertThat(actual.size(), is(2));
-        Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
-        LocalDataQueryResultRow row = iterator.next();
-        assertThat(row.getCell(1), is("t_order"));
-        assertThat(row.getCell(2), is("ds_1"));
-        row = iterator.next();
-        assertThat(row.getCell(1), is("t_order_item"));
-        assertThat(row.getCell(2), is("ds_2"));
-    }
-    
-    @Test
-    void assertGetSingleTableWithLikeLiteral() throws SQLException {
-        engine = setUp(new ShowSingleTablesStatement(null, "%item"));
-        engine.executeQuery();
-        Collection<LocalDataQueryResultRow> actual = engine.getRows();
-        assertThat(actual.size(), is(1));
-        Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
-        LocalDataQueryResultRow row = iterator.next();
-        assertThat(row.getCell(1), is("t_order_item"));
-        assertThat(row.getCell(2), is("ds_2"));
-    }
-    
     private SingleRule mockSingleRule() {
         Map<String, Collection<DataNode>> singleTableDataNodeMap = new 
HashMap<>(2, 1F);
         singleTableDataNodeMap.put("t_order", Collections.singleton(new 
DataNode("ds_1", "t_order")));

Reply via email to