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

zhangliang 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 ea6e728b84a Refactor JdbcUrlAppenderTest and QuoteCharacterTest 
(#37594)
ea6e728b84a is described below

commit ea6e728b84abf86f78da9cd0dedb78a02a137a0e
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Dec 31 18:53:53 2025 +0800

    Refactor JdbcUrlAppenderTest and QuoteCharacterTest (#37594)
    
    * Refactor JdbcUrlAppenderTest and QuoteCharacterTest
    
    * Refactor JdbcUrlAppenderTest and QuoteCharacterTest
    
    * Refactor JdbcUrlAppenderTest and QuoteCharacterTest
---
 .../core/jdbcurl/appender/JdbcUrlAppenderTest.java | 66 +++++++++++-----------
 .../database/enums/QuoteCharacterTest.java         | 43 +++-----------
 2 files changed, 42 insertions(+), 67 deletions(-)

diff --git 
a/database/connector/core/src/test/java/org/apache/shardingsphere/database/connector/core/jdbcurl/appender/JdbcUrlAppenderTest.java
 
b/database/connector/core/src/test/java/org/apache/shardingsphere/database/connector/core/jdbcurl/appender/JdbcUrlAppenderTest.java
index d2096e3f589..20bcc050285 100644
--- 
a/database/connector/core/src/test/java/org/apache/shardingsphere/database/connector/core/jdbcurl/appender/JdbcUrlAppenderTest.java
+++ 
b/database/connector/core/src/test/java/org/apache/shardingsphere/database/connector/core/jdbcurl/appender/JdbcUrlAppenderTest.java
@@ -19,9 +19,12 @@ package 
org.apache.shardingsphere.database.connector.core.jdbcurl.appender;
 
 import org.apache.shardingsphere.infra.util.props.PropertiesBuilder;
 import org.apache.shardingsphere.infra.util.props.PropertiesBuilder.Property;
-import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
 
 import java.util.Properties;
+import java.util.stream.Stream;
 
 import static org.hamcrest.CoreMatchers.containsString;
 import static org.hamcrest.CoreMatchers.startsWith;
@@ -29,38 +32,37 @@ import static org.hamcrest.MatcherAssert.assertThat;
 
 class JdbcUrlAppenderTest {
     
-    @Test
-    void assertAppendQueryPropertiesWithoutToBeAppendedQueryProperties() {
-        String actual = new 
JdbcUrlAppender().appendQueryProperties("jdbc:trunk://192.168.0.1:3306/foo_ds?useSSL=false&rewriteBatchedStatements=true",
 new Properties());
-        assertThat(actual, startsWith("jdbc:trunk://192.168.0.1:3306/foo_ds"));
-        assertThat(actual, containsString("rewriteBatchedStatements=true"));
-        assertThat(actual, containsString("useSSL=false"));
+    @ParameterizedTest(name = "{index}: url={0}")
+    @MethodSource("appendQueryPropertiesProvider")
+    void assertAppendQueryProperties(final String url, final Properties 
properties, final String expectedPrefix, final String[] expectedFragments) {
+        String actual = new JdbcUrlAppender().appendQueryProperties(url, 
properties);
+        assertThat(actual, startsWith(expectedPrefix));
+        for (String each : expectedFragments) {
+            assertThat(actual, containsString(each));
+        }
     }
     
-    @Test
-    void assertAppendQueryPropertiesWithoutOriginalQueryProperties() {
-        String actual = new 
JdbcUrlAppender().appendQueryProperties("jdbc:trunk://192.168.0.1:3306/foo_ds",
-                PropertiesBuilder.build(new Property("useSSL", 
Boolean.FALSE.toString()), new Property("rewriteBatchedStatements", 
Boolean.TRUE.toString())));
-        assertThat(actual, 
startsWith("jdbc:trunk://192.168.0.1:3306/foo_ds?"));
-        assertThat(actual, containsString("rewriteBatchedStatements=true"));
-        assertThat(actual, containsString("useSSL=false"));
-    }
-    
-    @Test
-    void assertAppendQueryPropertiesWithConflictedQueryProperties() {
-        String actual = new 
JdbcUrlAppender().appendQueryProperties("jdbc:trunk://192.168.0.1:3306/foo_ds?useSSL=false&rewriteBatchedStatements=true",
-                PropertiesBuilder.build(new Property("useSSL", 
Boolean.FALSE.toString()), new Property("rewriteBatchedStatements", 
Boolean.TRUE.toString())));
-        assertThat(actual, 
startsWith("jdbc:trunk://192.168.0.1:3306/foo_ds?"));
-        assertThat(actual, containsString("rewriteBatchedStatements=true"));
-        assertThat(actual, containsString("useSSL=false"));
-    }
-    
-    @Test
-    void assertAppendQueryPropertiesWithoutConflictedQueryProperties() {
-        String actual = new 
JdbcUrlAppender().appendQueryProperties("jdbc:trunk://192.168.0.1:3306/foo_ds?useSSL=false",
-                PropertiesBuilder.build(new 
Property("rewriteBatchedStatements", Boolean.TRUE.toString())));
-        assertThat(actual, 
startsWith("jdbc:trunk://192.168.0.1:3306/foo_ds?"));
-        assertThat(actual, containsString("rewriteBatchedStatements=true"));
-        assertThat(actual, containsString("useSSL=false"));
+    private static Stream<Arguments> appendQueryPropertiesProvider() {
+        return Stream.of(
+                Arguments.arguments(
+                        
"jdbc:trunk://192.168.0.1:3306/foo_ds?useSSL=false&rewriteBatchedStatements=true",
+                        new Properties(),
+                        "jdbc:trunk://192.168.0.1:3306/foo_ds",
+                        new String[]{"rewriteBatchedStatements=true", 
"useSSL=false"}),
+                Arguments.arguments(
+                        "jdbc:trunk://192.168.0.1:3306/foo_ds",
+                        PropertiesBuilder.build(new Property("useSSL", 
Boolean.FALSE.toString()), new Property("rewriteBatchedStatements", 
Boolean.TRUE.toString())),
+                        "jdbc:trunk://192.168.0.1:3306/foo_ds?",
+                        new String[]{"rewriteBatchedStatements=true", 
"useSSL=false"}),
+                Arguments.arguments(
+                        
"jdbc:trunk://192.168.0.1:3306/foo_ds?useSSL=false&rewriteBatchedStatements=true",
+                        PropertiesBuilder.build(new Property("useSSL", 
Boolean.FALSE.toString()), new Property("rewriteBatchedStatements", 
Boolean.TRUE.toString())),
+                        "jdbc:trunk://192.168.0.1:3306/foo_ds?",
+                        new String[]{"rewriteBatchedStatements=true", 
"useSSL=false"}),
+                Arguments.arguments(
+                        "jdbc:trunk://192.168.0.1:3306/foo_ds?useSSL=false",
+                        PropertiesBuilder.build(new 
Property("rewriteBatchedStatements", Boolean.TRUE.toString())),
+                        "jdbc:trunk://192.168.0.1:3306/foo_ds?",
+                        new String[]{"rewriteBatchedStatements=true", 
"useSSL=false"}));
     }
 }
diff --git 
a/database/connector/core/src/test/java/org/apache/shardingsphere/database/connector/core/metadata/database/enums/QuoteCharacterTest.java
 
b/database/connector/core/src/test/java/org/apache/shardingsphere/database/connector/core/metadata/database/enums/QuoteCharacterTest.java
index 4c22e8eb574..8f32a37c5b9 100644
--- 
a/database/connector/core/src/test/java/org/apache/shardingsphere/database/connector/core/metadata/database/enums/QuoteCharacterTest.java
+++ 
b/database/connector/core/src/test/java/org/apache/shardingsphere/database/connector/core/metadata/database/enums/QuoteCharacterTest.java
@@ -27,37 +27,13 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 class QuoteCharacterTest {
     
     @Test
-    void assertGetQuoteCharacterWithNullValue() {
+    void assertGetQuoteCharacter() {
         assertThat(QuoteCharacter.getQuoteCharacter(null), 
is(QuoteCharacter.NONE));
-    }
-    
-    @Test
-    void assertGetQuoteCharacterWithEmptyValue() {
         assertThat(QuoteCharacter.getQuoteCharacter(""), 
is(QuoteCharacter.NONE));
-    }
-    
-    @Test
-    void assertGetQuoteCharacterWithNone() {
         assertThat(QuoteCharacter.getQuoteCharacter("test"), 
is(QuoteCharacter.NONE));
-    }
-    
-    @Test
-    void assertGetQuoteCharacterWithBackQuote() {
         assertThat(QuoteCharacter.getQuoteCharacter("`test`"), 
is(QuoteCharacter.BACK_QUOTE));
-    }
-    
-    @Test
-    void assertGetQuoteCharacterWithSingleQuote() {
         assertThat(QuoteCharacter.getQuoteCharacter("'test'"), 
is(QuoteCharacter.SINGLE_QUOTE));
-    }
-    
-    @Test
-    void assertGetQuoteCharacterWithQuote() {
         assertThat(QuoteCharacter.getQuoteCharacter("\"test\""), 
is(QuoteCharacter.QUOTE));
-    }
-    
-    @Test
-    void assertGetQuoteCharacterWithBrackets() {
         assertThat(QuoteCharacter.getQuoteCharacter("[test]"), 
is(QuoteCharacter.BRACKETS));
     }
     
@@ -67,23 +43,15 @@ class QuoteCharacterTest {
     }
     
     @Test
-    void assertUnwrapWithWrappedValue() {
+    void assertUnwrap() {
         assertThat(QuoteCharacter.BACK_QUOTE.unwrap("`test`"), is("test"));
     }
     
-    @Test
-    void assertUnwrapWithoutWrappedValue() {
-        assertThat(QuoteCharacter.BACK_QUOTE.unwrap("[test]"), is("[test]"));
-    }
-    
     @Test
     void assertIsWrapped() {
         assertTrue(QuoteCharacter.SINGLE_QUOTE.isWrapped("'test'"));
-    }
-    
-    @Test
-    void assertIsNotWrapped() {
         assertFalse(QuoteCharacter.SINGLE_QUOTE.isWrapped("'test\""));
+        assertTrue(QuoteCharacter.NONE.isWrapped("test"));
     }
     
     @Test
@@ -96,4 +64,9 @@ class QuoteCharacterTest {
         assertThat(QuoteCharacter.unwrapText("(test)"), is("test"));
         assertThat(QuoteCharacter.unwrapText("{test}"), is("{test}"));
     }
+    
+    @Test
+    void assertUnwrapAndTrimText() {
+        assertThat(QuoteCharacter.unwrapAndTrimText("` test `"), is("test"));
+    }
 }

Reply via email to