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 9d9ffdc4b2a Add more test cases on PostgreSQLBinaryTimestampUtilsTest, 
PostgreSQLTextBitUtilsTest, PostgreSQLTextBoolUtilsTest (#38213)
9d9ffdc4b2a is described below

commit 9d9ffdc4b2a98dd3fcb4e78a6d8f86eda11220a7
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Feb 26 17:00:40 2026 +0800

    Add more test cases on PostgreSQLBinaryTimestampUtilsTest, 
PostgreSQLTextBitUtilsTest, PostgreSQLTextBoolUtilsTest (#38213)
---
 .../util/PostgreSQLBinaryTimestampUtilsTest.java   | 26 +++++++++++++++++-----
 .../protocol/util/PostgreSQLTextBitUtilsTest.java  | 24 ++++++++++++++------
 .../protocol/util/PostgreSQLTextBoolUtilsTest.java | 24 ++++++++++++++------
 3 files changed, 55 insertions(+), 19 deletions(-)

diff --git 
a/database/protocol/dialect/postgresql/src/test/java/org/apache/shardingsphere/database/protocol/postgresql/packet/command/query/extended/bind/protocol/util/PostgreSQLBinaryTimestampUtilsTest.java
 
b/database/protocol/dialect/postgresql/src/test/java/org/apache/shardingsphere/database/protocol/postgresql/packet/command/query/extended/bind/protocol/util/PostgreSQLBinaryTimestampUtilsTest.java
index ccd091c7d0f..06a34fbd5d7 100644
--- 
a/database/protocol/dialect/postgresql/src/test/java/org/apache/shardingsphere/database/protocol/postgresql/packet/command/query/extended/bind/protocol/util/PostgreSQLBinaryTimestampUtilsTest.java
+++ 
b/database/protocol/dialect/postgresql/src/test/java/org/apache/shardingsphere/database/protocol/postgresql/packet/command/query/extended/bind/protocol/util/PostgreSQLBinaryTimestampUtilsTest.java
@@ -17,19 +17,35 @@
 
 package 
org.apache.shardingsphere.database.protocol.postgresql.packet.command.query.extended.bind.protocol.util;
 
-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.sql.Timestamp;
+import java.util.stream.Stream;
 import java.util.TimeZone;
 
 import static org.hamcrest.Matchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 class PostgreSQLBinaryTimestampUtilsTest {
     
-    @Test
-    void assertToPostgreSQLTimeWithoutTimeZone() {
-        long expected = 688123357272000L + 
TimeZone.getDefault().getRawOffset() * 1000L;
-        assertThat(PostgreSQLBinaryTimestampUtils.toPostgreSQLTime(new 
Timestamp(1634808157272L)), is(expected));
+    @ParameterizedTest(name = "{0}")
+    @MethodSource("assertToPostgreSQLTimeArguments")
+    void assertToPostgreSQLTime(final String name, final long epochSeconds, 
final int nanos, final long expectedPostgreSQLTime) {
+        Timestamp timestamp = mock(Timestamp.class);
+        when(timestamp.getNanos()).thenReturn(nanos);
+        when(timestamp.getTime()).thenReturn(epochSeconds * 1000L + nanos / 
1000000L - TimeZone.getDefault().getRawOffset());
+        assertThat(PostgreSQLBinaryTimestampUtils.toPostgreSQLTime(timestamp), 
is(expectedPostgreSQLTime));
+    }
+    
+    private static Stream<Arguments> assertToPostgreSQLTimeArguments() {
+        return Stream.of(
+                Arguments.of("modern-epoch", 0L, 0, -946684800000000L),
+                Arguments.of("julian-without-year-adjustment", -12219292801L, 
0, -13166841601000000L),
+                Arguments.of("julian-with-year-adjustment", -14825808001L, 0, 
-15773270401000000L),
+                Arguments.of("nanos-overflow-adjusts-second", 0L, 1000000000, 
-946684799000000L));
     }
 }
diff --git 
a/database/protocol/dialect/postgresql/src/test/java/org/apache/shardingsphere/database/protocol/postgresql/packet/command/query/extended/bind/protocol/util/PostgreSQLTextBitUtilsTest.java
 
b/database/protocol/dialect/postgresql/src/test/java/org/apache/shardingsphere/database/protocol/postgresql/packet/command/query/extended/bind/protocol/util/PostgreSQLTextBitUtilsTest.java
index 5800fa1f32b..f16d7ec7689 100644
--- 
a/database/protocol/dialect/postgresql/src/test/java/org/apache/shardingsphere/database/protocol/postgresql/packet/command/query/extended/bind/protocol/util/PostgreSQLTextBitUtilsTest.java
+++ 
b/database/protocol/dialect/postgresql/src/test/java/org/apache/shardingsphere/database/protocol/postgresql/packet/command/query/extended/bind/protocol/util/PostgreSQLTextBitUtilsTest.java
@@ -17,17 +17,27 @@
 
 package 
org.apache.shardingsphere.database.protocol.postgresql.packet.command.query.extended.bind.protocol.util;
 
-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.stream.Stream;
 
-import static org.hamcrest.Matchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
 
 class PostgreSQLTextBitUtilsTest {
     
-    @Test
-    void assertGetTextBitValue() {
-        Object jdbcBitValue = true;
-        String textValue = PostgreSQLTextBitUtils.getTextValue(jdbcBitValue);
-        assertThat(textValue, is("1"));
+    @ParameterizedTest(name = "{0}")
+    @MethodSource("assertGetTextValueArguments")
+    void assertGetTextValue(final String name, final Object jdbcBitValue, 
final String expectedTextValue) {
+        assertThat(PostgreSQLTextBitUtils.getTextValue(jdbcBitValue), 
is(expectedTextValue));
+    }
+    
+    private static Stream<Arguments> assertGetTextValueArguments() {
+        return Stream.of(
+                Arguments.of("null-input", null, null),
+                Arguments.of("true-input", true, "1"),
+                Arguments.of("false-input", false, "0"));
     }
 }
diff --git 
a/database/protocol/dialect/postgresql/src/test/java/org/apache/shardingsphere/database/protocol/postgresql/packet/command/query/extended/bind/protocol/util/PostgreSQLTextBoolUtilsTest.java
 
b/database/protocol/dialect/postgresql/src/test/java/org/apache/shardingsphere/database/protocol/postgresql/packet/command/query/extended/bind/protocol/util/PostgreSQLTextBoolUtilsTest.java
index 27fd9288fff..eadc3763dd8 100644
--- 
a/database/protocol/dialect/postgresql/src/test/java/org/apache/shardingsphere/database/protocol/postgresql/packet/command/query/extended/bind/protocol/util/PostgreSQLTextBoolUtilsTest.java
+++ 
b/database/protocol/dialect/postgresql/src/test/java/org/apache/shardingsphere/database/protocol/postgresql/packet/command/query/extended/bind/protocol/util/PostgreSQLTextBoolUtilsTest.java
@@ -17,17 +17,27 @@
 
 package 
org.apache.shardingsphere.database.protocol.postgresql.packet.command.query.extended.bind.protocol.util;
 
-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.stream.Stream;
 
-import static org.hamcrest.Matchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
 
 class PostgreSQLTextBoolUtilsTest {
     
-    @Test
-    void assertGetTextValue() {
-        Object jdbcBoolValue = true;
-        String textValue = PostgreSQLTextBoolUtils.getTextValue(jdbcBoolValue);
-        assertThat(textValue, is("t"));
+    @ParameterizedTest(name = "{0}")
+    @MethodSource("assertGetTextValueArguments")
+    void assertGetTextValue(final String name, final Object jdbcBoolValue, 
final String expectedTextValue) {
+        assertThat(PostgreSQLTextBoolUtils.getTextValue(jdbcBoolValue), 
is(expectedTextValue));
+    }
+    
+    private static Stream<Arguments> assertGetTextValueArguments() {
+        return Stream.of(
+                Arguments.of("null-input", null, null),
+                Arguments.of("true-input", true, "t"),
+                Arguments.of("false-input", false, "f"));
     }
 }

Reply via email to