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

wuweijie 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 1d1130db772 Refactor agent test cases (#30277)
1d1130db772 is described below

commit 1d1130db772dd0ff99067843c69879010a5d5375
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Feb 24 23:21:49 2024 +0800

    Refactor agent test cases (#30277)
    
    * Revise AgentPreconditionsTest
    
    * Revise PluginPreconditionsTest
    
    * Revise ShardingSphereURLLoadEngineTest
    
    * Revise ShardingSphereURLLoadEngineTest
---
 .../preconditions/AgentPreconditionsTest.java         | 17 ++++++++++++++---
 .../core/preconditions/PluginPreconditionsTest.java   | 10 ++++++++--
 .../url/core/ShardingSphereURLLoadEngineTest.java     | 19 ++++++-------------
 3 files changed, 28 insertions(+), 18 deletions(-)

diff --git 
a/agent/core/src/test/java/org/apache/shardingsphere/preconditions/AgentPreconditionsTest.java
 
b/agent/core/src/test/java/org/apache/shardingsphere/preconditions/AgentPreconditionsTest.java
index 87e0c867295..b1b665e6e5a 100644
--- 
a/agent/core/src/test/java/org/apache/shardingsphere/preconditions/AgentPreconditionsTest.java
+++ 
b/agent/core/src/test/java/org/apache/shardingsphere/preconditions/AgentPreconditionsTest.java
@@ -20,17 +20,28 @@ package org.apache.shardingsphere.preconditions;
 import org.apache.shardingsphere.agent.core.preconditions.AgentPreconditions;
 import org.junit.jupiter.api.Test;
 
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 
-public class AgentPreconditionsTest {
+class AgentPreconditionsTest {
     
     @Test
-    void assertCheckState() {
+    void assertCheckStateSuccess() {
+        assertDoesNotThrow(() -> AgentPreconditions.checkState(true, "Can not 
locate agent jar file by URL /var/tmp."));
+    }
+    
+    @Test
+    void assertCheckStateFailed() {
         assertThrows(IllegalStateException.class, () -> 
AgentPreconditions.checkState(false, "Can not locate agent jar file by URL 
/var/tmp."));
     }
     
     @Test
-    void assertCheckArgument() {
+    void assertCheckArgumentSuccess() {
+        assertDoesNotThrow(() -> AgentPreconditions.checkArgument(true, "SPI 
class MySQL is not interface."));
+    }
+    
+    @Test
+    void assertCheckArgumentFailed() {
         assertThrows(IllegalArgumentException.class, () -> 
AgentPreconditions.checkArgument(false, "SPI class MySQL is not interface."));
     }
 }
diff --git 
a/agent/plugins/core/src/test/java/org/apache/shardingsphere/agent/plugin/core/preconditions/PluginPreconditionsTest.java
 
b/agent/plugins/core/src/test/java/org/apache/shardingsphere/agent/plugin/core/preconditions/PluginPreconditionsTest.java
index 61b919c7feb..11d0534b57a 100644
--- 
a/agent/plugins/core/src/test/java/org/apache/shardingsphere/agent/plugin/core/preconditions/PluginPreconditionsTest.java
+++ 
b/agent/plugins/core/src/test/java/org/apache/shardingsphere/agent/plugin/core/preconditions/PluginPreconditionsTest.java
@@ -19,12 +19,18 @@ package 
org.apache.shardingsphere.agent.plugin.core.preconditions;
 
 import org.junit.jupiter.api.Test;
 
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 
-public class PluginPreconditionsTest {
+class PluginPreconditionsTest {
     
     @Test
-    void assertCheckArgument() {
+    void assertCheckArgumentSuccess() {
+        assertDoesNotThrow(() -> PluginPreconditions.checkArgument(true, "Port 
`-3306` of MySQL Service must be a positive number."));
+    }
+    
+    @Test
+    void assertCheckArgumentFailed() {
         assertThrows(IllegalArgumentException.class, () -> 
PluginPreconditions.checkArgument(false, "Port `-3306` of MySQL Service must be 
a positive number."));
     }
 }
diff --git 
a/infra/url/core/src/test/java/org/apache/shardingsphere/infra/url/core/ShardingSphereURLLoadEngineTest.java
 
b/infra/url/core/src/test/java/org/apache/shardingsphere/infra/url/core/ShardingSphereURLLoadEngineTest.java
index d2e9d7572ee..a13e173b3b1 100644
--- 
a/infra/url/core/src/test/java/org/apache/shardingsphere/infra/url/core/ShardingSphereURLLoadEngineTest.java
+++ 
b/infra/url/core/src/test/java/org/apache/shardingsphere/infra/url/core/ShardingSphereURLLoadEngineTest.java
@@ -22,8 +22,6 @@ import 
org.apache.shardingsphere.infra.url.spi.ShardingSphereURLLoader;
 import org.junit.jupiter.api.Test;
 import org.mockito.MockedStatic;
 
-import java.util.Properties;
-
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.mockito.ArgumentMatchers.any;
@@ -31,22 +29,17 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.mockStatic;
 import static org.mockito.Mockito.when;
 
-public class ShardingSphereURLLoadEngineTest {
+class ShardingSphereURLLoadEngineTest {
     
     @Test
     void assertLoadContent() {
         String content = "foo_driver_fixture_db=2\nstorage_unit_count=2\n";
-        ShardingSphereURL url = mock(ShardingSphereURL.class);
         ShardingSphereURLLoader urlLoader = 
mock(ShardingSphereURLLoader.class);
-        
-        when(url.getSourceType()).thenReturn("classpath:");
-        when(url.getQueryProps()).thenReturn(new Properties());
         when(urlLoader.load(any(), any())).thenReturn(content);
-        
-        MockedStatic<TypedSPILoader> typedSPILoaderMockedStatic = 
mockStatic(TypedSPILoader.class);
-        typedSPILoaderMockedStatic.when(() -> 
TypedSPILoader.getService(ShardingSphereURLLoader.class, 
"classpath:")).thenReturn(urlLoader);
-        ShardingSphereURLLoadEngine shardingSphereURLLoadEngine = new 
ShardingSphereURLLoadEngine(url);
-        
-        assertThat(shardingSphereURLLoadEngine.loadContent(), 
is(content.getBytes()));
+        try (MockedStatic<TypedSPILoader> typedSPILoaderMockedStatic = 
mockStatic(TypedSPILoader.class)) {
+            typedSPILoaderMockedStatic.when(() -> 
TypedSPILoader.getService(ShardingSphereURLLoader.class, 
"classpath:")).thenReturn(urlLoader);
+            ShardingSphereURLLoadEngine loadEngine = new 
ShardingSphereURLLoadEngine(ShardingSphereURL.parse("classpath:xxx"));
+            assertThat(loadEngine.loadContent(), is(content.getBytes()));
+        }
     }
 }

Reply via email to