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 13c718a1a8f Add test cases for HintManager.getDataSourceName() (#36955)
13c718a1a8f is described below

commit 13c718a1a8f62b158b57a68fce511c10f9067bd3
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Oct 28 17:38:30 2025 +0800

    Add test cases for HintManager.getDataSourceName() (#36955)
    
    - Add assertGetDataSourceNameWithValue() to test with data source name set
    - Add assertGetDataSourceNameWithoutValue() to test without value
    - Achieve 100% branch coverage for getDataSourceName() method
    - Follow elegant test patterns: minimal methods, clean assertions, proper 
resource cleanup
    
    🤖 Generated with [Claude Code](https://claude.com/claude-code)
    
    Co-authored-by: Claude <[email protected]>
---
 .../shardingsphere/infra/hint/HintManagerTest.java     | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git 
a/infra/common/src/test/java/org/apache/shardingsphere/infra/hint/HintManagerTest.java
 
b/infra/common/src/test/java/org/apache/shardingsphere/infra/hint/HintManagerTest.java
index 5c5a8460d74..9b08ff2382a 100644
--- 
a/infra/common/src/test/java/org/apache/shardingsphere/infra/hint/HintManagerTest.java
+++ 
b/infra/common/src/test/java/org/apache/shardingsphere/infra/hint/HintManagerTest.java
@@ -21,6 +21,7 @@ import org.junit.jupiter.api.Test;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Optional;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
@@ -207,4 +208,21 @@ class HintManagerTest {
         hintManager.close();
         assertFalse(HintManager.isInstantiated());
     }
+    
+    @Test
+    void assertGetDataSourceNameWithValue() {
+        try (HintManager hintManager = HintManager.getInstance()) {
+            hintManager.setDataSourceName("foo_ds");
+            Optional<String> actual = HintManager.getDataSourceName();
+            assertTrue(actual.isPresent());
+            assertThat(actual.get(), is("foo_ds"));
+        }
+    }
+    
+    @Test
+    void assertGetDataSourceNameWithoutValue() {
+        try (HintManager ignored = HintManager.getInstance()) {
+            assertFalse(HintManager.getDataSourceName().isPresent());
+        }
+    }
 }

Reply via email to