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 b97af2a9ffc Add more checkstyle check rule for junit (#38062)
b97af2a9ffc is described below

commit b97af2a9ffc820a5db829d00fbb8f065d88888bb
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Feb 16 19:42:56 2026 +0800

    Add more checkstyle check rule for junit (#38062)
---
 .../statement/dal/ExplainStatementBinderTest.java  | 36 ++++++----------------
 .../sql/SQLStatementParserEngineFactoryTest.java   |  7 +++--
 .../cdc/handler/CDCBackendHandlerTest.java         |  6 ++--
 .../PostgreSQLPortalContextRegistryTest.java       |  3 +-
 src/resources/checkstyle.xml                       |  2 +-
 5 files changed, 19 insertions(+), 35 deletions(-)

diff --git 
a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/engine/statement/dal/ExplainStatementBinderTest.java
 
b/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/engine/statement/dal/ExplainStatementBinderTest.java
index 15e570b129e..2a73ec974cc 100644
--- 
a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/engine/statement/dal/ExplainStatementBinderTest.java
+++ 
b/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/engine/statement/dal/ExplainStatementBinderTest.java
@@ -20,10 +20,6 @@ package 
org.apache.shardingsphere.infra.binder.engine.statement.dal;
 import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
 import 
org.apache.shardingsphere.infra.binder.engine.statement.SQLStatementBinderContext;
 import org.apache.shardingsphere.infra.hint.HintValueContext;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import 
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
-import 
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable;
 import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
 import 
org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement;
 import 
org.apache.shardingsphere.sql.parser.statement.core.statement.type.dal.DALStatement;
@@ -31,42 +27,30 @@ import 
org.apache.shardingsphere.sql.parser.statement.core.statement.type.dal.Ex
 import 
org.apache.shardingsphere.sql.parser.statement.core.statement.type.dml.DMLStatement;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
 
 import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
 import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertNotSame;
-import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.hamcrest.Matchers.isA;
+import static org.mockito.Mockito.mock;
 
 @ExtendWith(MockitoExtension.class)
 class ExplainStatementBinderTest {
     
     private final DatabaseType databaseType = 
TypedSPILoader.getService(DatabaseType.class, "FIXTURE");
     
-    @Mock
-    private ShardingSphereMetaData metaData;
-    
-    @Mock
-    private ShardingSphereDatabase database;
-    
-    @Mock
-    private ShardingSphereSchema schema;
-    
-    @Mock
-    private ShardingSphereTable table;
-    
     @Test
     void assertBindWithDMLStatement() {
         DMLStatement dmlStatement = new TestDMLStatement(databaseType);
         ExplainStatement original = new ExplainStatement(databaseType, 
dmlStatement);
         HintValueContext hintValueContext = new HintValueContext();
         hintValueContext.setSkipMetadataValidate(true);
-        SQLStatementBinderContext binderContext = new 
SQLStatementBinderContext(metaData, "foo_db", hintValueContext, original);
+        SQLStatementBinderContext binderContext = new 
SQLStatementBinderContext(mock(), "foo_db", hintValueContext, original);
         ExplainStatement actual = new ExplainStatementBinder().bind(original, 
binderContext);
-        assertNotSame(original, actual);
-        assertThat(actual.getExplainableSQLStatement().getClass(), 
is(TestDMLStatement.class));
-        assertSame(dmlStatement, actual.getExplainableSQLStatement());
+        assertThat(original, not(actual));
+        assertThat(actual.getExplainableSQLStatement(), 
isA(TestDMLStatement.class));
+        assertThat(dmlStatement, is(actual.getExplainableSQLStatement()));
     }
     
     @Test
@@ -75,10 +59,10 @@ class ExplainStatementBinderTest {
         ExplainStatement original = new ExplainStatement(databaseType, 
nonDMLStatement);
         HintValueContext hintValueContext = new HintValueContext();
         hintValueContext.setSkipMetadataValidate(true);
-        SQLStatementBinderContext binderContext = new 
SQLStatementBinderContext(metaData, "foo_db", hintValueContext, original);
+        SQLStatementBinderContext binderContext = new 
SQLStatementBinderContext(mock(), "foo_db", hintValueContext, original);
         ExplainStatement actual = new ExplainStatementBinder().bind(original, 
binderContext);
-        assertNotSame(original, actual);
-        assertSame(nonDMLStatement, actual.getExplainableSQLStatement());
+        assertThat(original, not(actual));
+        assertThat(nonDMLStatement, is(actual.getExplainableSQLStatement()));
     }
     
     private static final class TestDMLStatement extends DMLStatement {
diff --git 
a/infra/parser/src/test/java/org/apache/shardingsphere/infra/parser/sql/SQLStatementParserEngineFactoryTest.java
 
b/infra/parser/src/test/java/org/apache/shardingsphere/infra/parser/sql/SQLStatementParserEngineFactoryTest.java
index 31b47a8eb2a..f84ff6d9486 100644
--- 
a/infra/parser/src/test/java/org/apache/shardingsphere/infra/parser/sql/SQLStatementParserEngineFactoryTest.java
+++ 
b/infra/parser/src/test/java/org/apache/shardingsphere/infra/parser/sql/SQLStatementParserEngineFactoryTest.java
@@ -22,7 +22,8 @@ import 
org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
 import org.apache.shardingsphere.sql.parser.engine.api.CacheOption;
 import org.junit.jupiter.api.Test;
 
-import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
 
 class SQLStatementParserEngineFactoryTest {
     
@@ -32,13 +33,13 @@ class SQLStatementParserEngineFactoryTest {
     void assertGetSQLStatementParserEngineNotSame() {
         SQLStatementParserEngine before = 
SQLStatementParserEngineFactory.getSQLStatementParserEngine(databaseType, new 
CacheOption(2000, 65535L), new CacheOption(64, 1024L));
         SQLStatementParserEngine after = 
SQLStatementParserEngineFactory.getSQLStatementParserEngine(databaseType, new 
CacheOption(2000, 65535L), new CacheOption(128, 1024L));
-        assertSame(before, after);
+        assertThat(before, is(after));
     }
     
     @Test
     void assertGetSQLStatementParserEngineSame() {
         SQLStatementParserEngine before = 
SQLStatementParserEngineFactory.getSQLStatementParserEngine(databaseType, new 
CacheOption(2000, 65535L), new CacheOption(128, 1024L));
         SQLStatementParserEngine after = 
SQLStatementParserEngineFactory.getSQLStatementParserEngine(databaseType, new 
CacheOption(2000, 65535L), new CacheOption(128, 1024L));
-        assertSame(before, after);
+        assertThat(before, is(after));
     }
 }
diff --git 
a/kernel/data-pipeline/scenario/cdc/core/src/test/java/org/apache/shardingsphere/data/pipeline/cdc/handler/CDCBackendHandlerTest.java
 
b/kernel/data-pipeline/scenario/cdc/core/src/test/java/org/apache/shardingsphere/data/pipeline/cdc/handler/CDCBackendHandlerTest.java
index f953ccfdf51..77599c0cfd4 100644
--- 
a/kernel/data-pipeline/scenario/cdc/core/src/test/java/org/apache/shardingsphere/data/pipeline/cdc/handler/CDCBackendHandlerTest.java
+++ 
b/kernel/data-pipeline/scenario/cdc/core/src/test/java/org/apache/shardingsphere/data/pipeline/cdc/handler/CDCBackendHandlerTest.java
@@ -71,8 +71,8 @@ import java.util.LinkedHashSet;
 import java.util.Properties;
 
 import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.instanceOf;
 import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.isA;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyCollection;
@@ -152,7 +152,7 @@ class CDCBackendHandlerTest {
         
when(CDCSchemaTableUtils.parseTableExpressionWithoutSchema(eq(database), 
anyList())).thenReturn(Collections.emptySet());
         StreamDataRequestBody requestBody = 
StreamDataRequestBody.newBuilder().setDatabase("foo_db").addSourceSchemaTable(SchemaTable.newBuilder().setTable("foo_tbl")).build();
         CDCExceptionWrapper actualException = 
assertThrows(CDCExceptionWrapper.class, () -> 
backendHandler.streamData("foo_req", requestBody, createConnectionContext(), 
mock()));
-        assertThat(actualException.getCause(), 
is(instanceOf(MissingRequiredStreamDataSourceException.class)));
+        assertThat(actualException.getCause(), 
isA(MissingRequiredStreamDataSourceException.class));
     }
     
     @Test
@@ -162,7 +162,7 @@ class CDCBackendHandlerTest {
         
when(PipelineContextManager.getProxyContext()).thenReturn(contextManager);
         StreamDataRequestBody requestBody = 
StreamDataRequestBody.newBuilder().setDatabase("missing_db").build();
         CDCExceptionWrapper actualException = 
assertThrows(CDCExceptionWrapper.class, () -> 
backendHandler.streamData("foo_req", requestBody, createConnectionContext(), 
mock()));
-        assertThat(actualException.getCause(), 
is(instanceOf(StreamDatabaseNotFoundException.class)));
+        assertThat(actualException.getCause(), 
isA(StreamDatabaseNotFoundException.class));
     }
     
     @Test
diff --git 
a/proxy/frontend/dialect/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLPortalContextRegistryTest.java
 
b/proxy/frontend/dialect/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLPortalContextRegistryTest.java
index 003d89434ab..e0a54e8894d 100644
--- 
a/proxy/frontend/dialect/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLPortalContextRegistryTest.java
+++ 
b/proxy/frontend/dialect/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLPortalContextRegistryTest.java
@@ -22,7 +22,6 @@ import org.junit.jupiter.api.Test;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertSame;
 
 class PostgreSQLPortalContextRegistryTest {
     
@@ -31,7 +30,7 @@ class PostgreSQLPortalContextRegistryTest {
         PostgreSQLPortalContextRegistry registry = 
PostgreSQLPortalContextRegistry.getInstance();
         PortalContext first = registry.get(1);
         PortalContext second = registry.get(1);
-        assertSame(first, second);
+        assertThat(first, is(second));
         assertThat(registry.remove(1), is(first));
         assertNull(registry.remove(2));
     }
diff --git a/src/resources/checkstyle.xml b/src/resources/checkstyle.xml
index 8ef7d0dbd6a..8154e308230 100644
--- a/src/resources/checkstyle.xml
+++ b/src/resources/checkstyle.xml
@@ -144,7 +144,7 @@
         <!-- Imports -->
         <module name="AvoidStarImport" />
         <module name="AvoidStaticImport">
-            <property name="excludes" 
value="org.junit.jupiter.api.Assertions.assertTrue,org.junit.jupiter.api.Assertions.assertFalse,org.junit.jupiter.api.Assertions.assertNull,org.junit.jupiter.api.Assertions.assertNotNull,org.junit.jupiter.api.Assertions.assertSame,org.junit.jupiter.api.Assertions.assertNotSame,org.junit.jupiter.api.Assertions.assertArrayEquals,org.junit.jupiter.api.Assertions.assertThrows,org.junit.jupiter.api.Assertions.assertDoesNotThrow,org.junit.jupiter.api.Asser
 [...]
+            <property name="excludes" 
value="org.junit.jupiter.api.Assertions.assertTrue,org.junit.jupiter.api.Assertions.assertFalse,org.junit.jupiter.api.Assertions.assertNull,org.junit.jupiter.api.Assertions.assertNotNull,org.junit.jupiter.api.Assertions.assertArrayEquals,org.junit.jupiter.api.Assertions.assertThrows,org.junit.jupiter.api.Assertions.assertDoesNotThrow,org.junit.jupiter.api.Assertions.assertTimeout,org.junit.jupiter.api.Assertions.fail,org.junit.jupiter.api.Assumptions
 [...]
         </module>
         <module name="IllegalImport" />
         <module name="RedundantImport" />

Reply via email to