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 4689614a492 Add more test cases on LocalDataQueryResultRow (#33181)
4689614a492 is described below

commit 4689614a492eb5018fdaf3414549e88a6d1caa99
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Oct 9 12:53:07 2024 +0800

    Add more test cases on LocalDataQueryResultRow (#33181)
    
    * Refactor LocalDataMergedResultTest
    
    * Add more test cases on LocalDataQueryResultRow
---
 .../impl/local/LocalDataMergedResultTest.java      | 12 +++---
 .../impl/local/LocalDataQueryResultRowTest.java    | 49 ++++++++++++++++++----
 2 files changed, 48 insertions(+), 13 deletions(-)

diff --git 
a/infra/merge/src/test/java/org/apache/shardingsphere/infra/merge/result/impl/local/LocalDataMergedResultTest.java
 
b/infra/merge/src/test/java/org/apache/shardingsphere/infra/merge/result/impl/local/LocalDataMergedResultTest.java
index bd8aca0b624..ba43e9616be 100644
--- 
a/infra/merge/src/test/java/org/apache/shardingsphere/infra/merge/result/impl/local/LocalDataMergedResultTest.java
+++ 
b/infra/merge/src/test/java/org/apache/shardingsphere/infra/merge/result/impl/local/LocalDataMergedResultTest.java
@@ -35,7 +35,7 @@ class LocalDataMergedResultTest {
     @Test
     void assertNext() {
         LocalDataQueryResultRow row = new LocalDataQueryResultRow("value");
-        LocalDataMergedResult actual = new 
LocalDataMergedResult(Collections.singletonList(row));
+        LocalDataMergedResult actual = new 
LocalDataMergedResult(Collections.singleton(row));
         assertTrue(actual.next());
         assertFalse(actual.next());
     }
@@ -43,7 +43,7 @@ class LocalDataMergedResultTest {
     @Test
     void assertGetValue() {
         LocalDataQueryResultRow row = new LocalDataQueryResultRow("value");
-        LocalDataMergedResult actual = new 
LocalDataMergedResult(Collections.singletonList(row));
+        LocalDataMergedResult actual = new 
LocalDataMergedResult(Collections.singleton(row));
         assertTrue(actual.next());
         assertThat(actual.getValue(1, Object.class).toString(), is("value"));
     }
@@ -51,26 +51,26 @@ class LocalDataMergedResultTest {
     @Test
     void assertGetCalendarValue() {
         LocalDataQueryResultRow row = new LocalDataQueryResultRow(new 
Date(0L));
-        LocalDataMergedResult actual = new 
LocalDataMergedResult(Collections.singletonList(row));
+        LocalDataMergedResult actual = new 
LocalDataMergedResult(Collections.singleton(row));
         assertTrue(actual.next());
         assertThat(actual.getCalendarValue(1, Object.class, 
Calendar.getInstance()), is("0"));
     }
     
     @Test
     void assertGetInputStream() {
-        LocalDataMergedResult actual = new 
LocalDataMergedResult(Collections.singletonList(new 
LocalDataQueryResultRow("value")));
+        LocalDataMergedResult actual = new 
LocalDataMergedResult(Collections.singleton(new 
LocalDataQueryResultRow("value")));
         assertThrows(SQLFeatureNotSupportedException.class, () -> 
actual.getInputStream(1, "Ascii"));
     }
     
     @Test
     void assertGetCharacterStream() {
-        LocalDataMergedResult actual = new 
LocalDataMergedResult(Collections.singletonList(new 
LocalDataQueryResultRow("value")));
+        LocalDataMergedResult actual = new 
LocalDataMergedResult(Collections.singleton(new 
LocalDataQueryResultRow("value")));
         assertThrows(SQLFeatureNotSupportedException.class, () -> 
actual.getCharacterStream(1));
     }
     
     @Test
     void assertWasNull() {
-        LocalDataMergedResult actual = new 
LocalDataMergedResult(Collections.singletonList(new 
LocalDataQueryResultRow("value")));
+        LocalDataMergedResult actual = new 
LocalDataMergedResult(Collections.singleton(new 
LocalDataQueryResultRow("value")));
         assertTrue(actual.next());
         assertFalse(actual.wasNull());
     }
diff --git 
a/infra/merge/src/test/java/org/apache/shardingsphere/infra/merge/result/impl/local/LocalDataQueryResultRowTest.java
 
b/infra/merge/src/test/java/org/apache/shardingsphere/infra/merge/result/impl/local/LocalDataQueryResultRowTest.java
index 14eb4cc9cfd..ff6f19b9b3d 100644
--- 
a/infra/merge/src/test/java/org/apache/shardingsphere/infra/merge/result/impl/local/LocalDataQueryResultRowTest.java
+++ 
b/infra/merge/src/test/java/org/apache/shardingsphere/infra/merge/result/impl/local/LocalDataQueryResultRowTest.java
@@ -21,6 +21,8 @@ import org.apache.shardingsphere.test.util.PropertiesBuilder;
 import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
 import org.junit.jupiter.api.Test;
 
+import java.time.LocalDateTime;
+import java.util.Collections;
 import java.util.Optional;
 import java.util.Properties;
 
@@ -47,6 +49,21 @@ class LocalDataQueryResultRowTest {
         assertThat(actual.getCell(2), is(""));
     }
     
+    @Test
+    void assertGetCellWithOptional() {
+        LocalDataQueryResultRow actual = new 
LocalDataQueryResultRow(Optional.empty(), Optional.of("foo"), Optional.of(1), 
Optional.of(PropertiesBuilder.build(new Property("foo", "bar"))));
+        assertThat(actual.getCell(1), is(""));
+        assertThat(actual.getCell(2), is("foo"));
+        assertThat(actual.getCell(3), is("1"));
+        assertThat(actual.getCell(4), is("{\"foo\":\"bar\"}"));
+    }
+    
+    @Test
+    void assertGetCellWithStringValue() {
+        LocalDataQueryResultRow actual = new LocalDataQueryResultRow("foo");
+        assertThat(actual.getCell(1), is("foo"));
+    }
+    
     @Test
     void assertGetCellWithBooleanValue() {
         LocalDataQueryResultRow actual = new LocalDataQueryResultRow(true, 
Boolean.FALSE);
@@ -70,6 +87,13 @@ class LocalDataQueryResultRowTest {
         assertThat(actual.getCell(2), is("2"));
     }
     
+    @Test
+    void assertGetCellWithLocalDateTimeValue() {
+        LocalDateTime localDateTime = LocalDateTime.of(2000, 1, 1, 0, 0, 0);
+        LocalDataQueryResultRow actual = new 
LocalDataQueryResultRow(localDateTime);
+        assertThat(actual.getCell(1), is(localDateTime.toString()));
+    }
+    
     @Test
     void assertGetCellWithEnum() {
         LocalDataQueryResultRow actual = new 
LocalDataQueryResultRow(FixtureEnum.FOO, FixtureEnum.BAR);
@@ -79,18 +103,29 @@ class LocalDataQueryResultRowTest {
     
     @Test
     void assertGetCellWithProperties() {
-        LocalDataQueryResultRow actual = new LocalDataQueryResultRow(new 
Properties(), PropertiesBuilder.build(new Property("foo", "bar")));
+        LocalDataQueryResultRow actual = new LocalDataQueryResultRow(new 
Properties(), PropertiesBuilder.build(new Property("k", "v")));
         assertThat(actual.getCell(1), is(""));
-        assertThat(actual.getCell(2), is("{\"foo\":\"bar\"}"));
+        assertThat(actual.getCell(2), is("{\"k\":\"v\"}"));
     }
     
     @Test
-    void assertGetCellWithOptional() {
-        LocalDataQueryResultRow actual = new 
LocalDataQueryResultRow(Optional.empty(), Optional.of("foo"), Optional.of(1), 
Optional.of(PropertiesBuilder.build(new Property("foo", "bar"))));
+    void assertGetCellWithMap() {
+        LocalDataQueryResultRow actual = new 
LocalDataQueryResultRow(Collections.emptyMap(), Collections.singletonMap("k", 
"v"));
         assertThat(actual.getCell(1), is(""));
-        assertThat(actual.getCell(2), is("foo"));
-        assertThat(actual.getCell(3), is("1"));
-        assertThat(actual.getCell(4), is("{\"foo\":\"bar\"}"));
+        assertThat(actual.getCell(2), is("{\"k\":\"v\"}"));
+    }
+    
+    @Test
+    void assertGetCellWithCollection() {
+        LocalDataQueryResultRow actual = new 
LocalDataQueryResultRow(Collections.emptyList(), Collections.singleton("foo"));
+        assertThat(actual.getCell(1), is(""));
+        assertThat(actual.getCell(2), is("[\"foo\"]"));
+    }
+    
+    @Test
+    void assertGetCellWithObject() {
+        LocalDataQueryResultRow actual = new LocalDataQueryResultRow(new 
Object());
+        assertThat(actual.getCell(1), is("{}"));
     }
     
     private enum FixtureEnum {

Reply via email to