You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by xi...@apache.org on 2021/02/05 10:17:46 UTC

[shardingsphere] branch master updated: For code format of MySQL format test (#9354)

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

xiaoyu 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 78c9ec3  For code format of MySQL format test (#9354)
78c9ec3 is described below

commit 78c9ec39e2b8aabeb6c050e02b06b202dbbf899e
Author: Liang Zhang <te...@163.com>
AuthorDate: Fri Feb 5 18:17:20 2021 +0800

    For code format of MySQL format test (#9354)
    
    * Fix #9240
    
    * Fix test case
    
    * For code format of MySQL format test
---
 .../sql/parser/mysql/MySQLFormatTest.java          | 34 +++++++++----------
 .../sql/parser/mysql/MySQLParameterizedTest.java   | 34 +++++++++----------
 ...leVisterTest.java => MySQLTableVistorTest.java} | 38 ++++++++++------------
 3 files changed, 47 insertions(+), 59 deletions(-)

diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/MySQLFormatTest.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/MySQLFormatTest.java
index d4cbcf0..cafd783 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/MySQLFormatTest.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/MySQLFormatTest.java
@@ -17,6 +17,7 @@
 
 package org.apache.shardingsphere.sql.parser.mysql;
 
+import lombok.RequiredArgsConstructor;
 import org.antlr.v4.runtime.CodePointBuffer;
 import org.antlr.v4.runtime.CodePointCharStream;
 import org.antlr.v4.runtime.CommonTokenStream;
@@ -34,13 +35,15 @@ import java.nio.CharBuffer;
 import java.util.Collection;
 import java.util.LinkedList;
 
-import static org.junit.Assert.assertTrue;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
 
 @RunWith(Parameterized.class)
+@RequiredArgsConstructor
 public final class MySQLFormatTest {
-
-    private static Collection<String[]> testUnits = new LinkedList();
-
+    
+    private static Collection<String[]> testUnits = new LinkedList<>();
+    
     static {
         testUnits.add(new String[]{"select_with_union", "select a+1 as b, name n from table1 join table2 where id=1 and name='lu';", "SELECT a + 1 AS b, name n\n"
                 + "FROM table1 JOIN table2\n"
@@ -132,33 +135,26 @@ public final class MySQLFormatTest {
                 + "\t@@query_cache_type AS query_cache_type, @@sql_mode AS sql_mode, @@system_time_zone AS system_time_zone, \n"
                 + "\t@@time_zone AS time_zone, @@tx_isolation AS transaction_isolation, @@wait_timeout AS wait_timeout;"});
     }
-
+    
     private final String caseId;
-
+    
     private final String inputSql;
-
-    private final String expectFormartedSql;
-
-    public MySQLFormatTest(final String caseId, final String inputSql, final String expectFormartedSql) {
-        this.caseId = caseId;
-        this.inputSql = inputSql;
-        this.expectFormartedSql = expectFormartedSql;
-    }
-
+    
+    private final String expectFormattedSQL;
+    
     @Parameterized.Parameters(name = "{0}")
     public static Collection<String[]> getTestParameters() {
         return testUnits;
     }
-
+    
     @Test
-    public void assertSqlFormat() {
+    public void assertSQLFormat() {
         CodePointBuffer buffer = CodePointBuffer.withChars(CharBuffer.wrap(inputSql.toCharArray()));
         MySQLLexer lexer = new MySQLLexer(CodePointCharStream.fromBuffer(buffer));
         MySQLParser parser = new MySQLParser(new CommonTokenStream(lexer));
         ParseTree tree = ((ParseASTNode) parser.parse()).getRootNode();
         MySQLFormatSQLVisitor visitor = new MySQLDMLFormatSQLVisitor();
         visitor.setParameterized(false);
-        String result = visitor.visit(tree);
-        assertTrue("SQL format error", expectFormartedSql.equals(result));
+        assertThat("SQL format error", expectFormattedSQL, is(visitor.visit(tree)));
     }
 }
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/MySQLParameterizedTest.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/MySQLParameterizedTest.java
index c087012..41c77c8 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/MySQLParameterizedTest.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/MySQLParameterizedTest.java
@@ -17,6 +17,7 @@
 
 package org.apache.shardingsphere.sql.parser.mysql;
 
+import lombok.RequiredArgsConstructor;
 import org.antlr.v4.runtime.CodePointBuffer;
 import org.antlr.v4.runtime.CodePointCharStream;
 import org.antlr.v4.runtime.CommonTokenStream;
@@ -34,13 +35,15 @@ import java.nio.CharBuffer;
 import java.util.Collection;
 import java.util.LinkedList;
 
-import static org.junit.Assert.assertTrue;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
 
 @RunWith(Parameterized.class)
+@RequiredArgsConstructor
 public final class MySQLParameterizedTest {
-
-    private static Collection<String[]> testUnits = new LinkedList();
-
+    
+    private static Collection<String[]> testUnits = new LinkedList<>();
+    
     static {
         testUnits.add(new String[]{"select_with_union", "select a+1 as b, name n from table1 join table2 where id=1 and name='lu';", "SELECT a + ? AS b, name n\n"
                 + "FROM table1 JOIN table2\n"
@@ -100,32 +103,25 @@ public final class MySQLParameterizedTest {
                 + "\tPRIMARY KEY (`runoob_id`)\n"
                 + ") ENGINE = InnoDB DEFAULT CHARSET = utf8"});
     }
-
+    
     private final String caseId;
-
+    
     private final String inputSql;
-
-    private final String expectFormartedSql;
-
-    public MySQLParameterizedTest(final String caseId, final String inputSql, final String expectFormartedSql) {
-        this.caseId = caseId;
-        this.inputSql = inputSql;
-        this.expectFormartedSql = expectFormartedSql;
-    }
-
+    
+    private final String expectFormattedSQL;
+    
     @Parameterized.Parameters(name = "{0}")
     public static Collection<String[]> getTestParameters() {
         return testUnits;
     }
-
+    
     @Test
-    public void assertSqlFormat() {
+    public void assertSQLFormat() {
         CodePointBuffer buffer = CodePointBuffer.withChars(CharBuffer.wrap(inputSql.toCharArray()));
         MySQLLexer lexer = new MySQLLexer(CodePointCharStream.fromBuffer(buffer));
         MySQLParser parser = new MySQLParser(new CommonTokenStream(lexer));
         ParseTree tree = ((ParseASTNode) parser.parse()).getRootNode();
         MySQLFormatSQLVisitor visitor = new MySQLDMLFormatSQLVisitor();
-        String result = visitor.visit(tree);
-        assertTrue("SQL format error", expectFormartedSql.equals(result));
+        assertThat("SQL format error", expectFormattedSQL, is(visitor.visit(tree)));
     }
 }
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/MySQLTableVisterTest.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/MySQLTableVistorTest.java
similarity index 85%
rename from shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/MySQLTableVisterTest.java
rename to shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/MySQLTableVistorTest.java
index 9da2e76..c54e300 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/MySQLTableVisterTest.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/MySQLTableVistorTest.java
@@ -17,6 +17,7 @@
 
 package org.apache.shardingsphere.sql.parser.mysql;
 
+import lombok.RequiredArgsConstructor;
 import org.antlr.v4.runtime.CodePointBuffer;
 import org.antlr.v4.runtime.CodePointCharStream;
 import org.antlr.v4.runtime.CommonTokenStream;
@@ -34,13 +35,15 @@ import java.nio.CharBuffer;
 import java.util.Collection;
 import java.util.LinkedList;
 
-import org.hamcrest.Matchers;
-import org.junit.Assert;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
 
 @RunWith(Parameterized.class)
-public final class MySQLTableVisterTest {
-    private static Collection<Object[]> testUnits = new LinkedList();
-
+@RequiredArgsConstructor
+public final class MySQLTableVistorTest {
+    
+    private static Collection<Object[]> testUnits = new LinkedList<>();
+    
     static {
         testUnits.add(new Object[]{"select_with_union", "select a+1 as b, name n from table1 join table2 where id=1 and name='lu';", 2, 3});
         testUnits.add(new Object[]{"select_item_nums", "select id, name, age, sex, ss, yy from table1 where id=1", 1, 6});
@@ -56,36 +59,29 @@ public final class MySQLTableVisterTest {
                 + "PRIMARY KEY ( `runoob_id` )\n"
                 + ")ENGINE=InnoDB DEFAULT CHARSET=utf8;", 1, 5});
     }
-
+    
     private final String caseId;
-
+    
     private final String inputSql;
-
+    
     private final int tableNum;
-
+    
     private final int columnNum;
-
-    public MySQLTableVisterTest(final String caseId, final String inputSql, final int tableNum, final int columnNum) {
-        this.caseId = caseId;
-        this.inputSql = inputSql;
-        this.tableNum = tableNum;
-        this.columnNum = columnNum;
-    }
-
+    
     @Parameterized.Parameters(name = "{0}")
     public static Collection<Object[]> getTestParameters() {
         return testUnits;
     }
-
+    
     @Test
-    public void assertSqlStats() {
+    public void assertSQLStats() {
         CodePointBuffer buffer = CodePointBuffer.withChars(CharBuffer.wrap(inputSql.toCharArray()));
         MySQLLexer lexer = new MySQLLexer(CodePointCharStream.fromBuffer(buffer));
         MySQLParser parser = new MySQLParser(new CommonTokenStream(lexer));
         ParseTree tree = ((ParseASTNode) parser.parse()).getRootNode();
         MySQLSQLStatVisitor visitor = new MySQLSQLStatVisitor();
         SqlStats sqlStats = visitor.visit(tree);
-        Assert.assertThat("table assert error", sqlStats.getTables().keySet().size(), Matchers.is(tableNum));
-        Assert.assertThat("column assert error", sqlStats.getColumns().keySet().size(), Matchers.is(columnNum));
+        assertThat("table assert error", sqlStats.getTables().keySet().size(), is(tableNum));
+        assertThat("column assert error", sqlStats.getColumns().keySet().size(), is(columnNum));
     }
 }