You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2025/08/17 23:37:45 UTC
(shardingsphere) branch master updated: Use assertThat to instead of assertInstanceOf (#36330)
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 9f1a96396ad Use assertThat to instead of assertInstanceOf (#36330)
9f1a96396ad is described below
commit 9f1a96396ad19babc4eafc7f4857d203a073a1ab
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Mon Aug 18 07:37:40 2025 +0800
Use assertThat to instead of assertInstanceOf (#36330)
---
.../column/value/string/MySQLStringBinlogProtocolValueTest.java | 6 +++---
.../core/channel/memory/MemoryPipelineChannelCreatorTest.java | 6 +++---
.../table/TableDataConsistencyCheckerFactoryTest.java | 8 ++++----
.../client/netty/MySQLBinlogEventPacketDecoderTest.java | 6 +++---
.../ingest/incremental/wal/decode/MppdbDecodingPluginTest.java | 7 +++----
.../postgresql/ingest/incremental/wal/WALEventConverterTest.java | 7 +++----
.../distsql/ral/queryable/export/ExportMetaDataExecutorTest.java | 4 ++--
.../parser/internal/asserts/statement/comment/CommentAssert.java | 8 +++-----
8 files changed, 24 insertions(+), 28 deletions(-)
diff --git a/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/string/MySQLStringBinlogProtocolValueTest.java b/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/string/MySQLStringBinlogProtocolValueTest.java
index ea723824a8e..901843a09e2 100644
--- a/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/string/MySQLStringBinlogProtocolValueTest.java
+++ b/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/string/MySQLStringBinlogProtocolValueTest.java
@@ -30,9 +30,9 @@ import org.mockito.junit.jupiter.MockitoExtension;
import java.io.Serializable;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.when;
@@ -88,7 +88,7 @@ class MySQLStringBinlogProtocolValueTest {
when(byteBuf.readUnsignedByte()).thenReturn((short) expected.length());
when(payload.readStringFixByBytes(expected.length())).thenReturn(expected.getBytes());
Serializable actual = new MySQLStringBinlogProtocolValue().read(columnDef, payload);
- assertInstanceOf(MySQLBinaryString.class, actual);
+ assertThat(actual, instanceOf(MySQLBinaryString.class));
assertThat(((MySQLBinaryString) actual).getBytes(), is(expected.getBytes()));
}
@@ -100,7 +100,7 @@ class MySQLStringBinlogProtocolValueTest {
when(byteBuf.readUnsignedShortLE()).thenReturn(expected.length());
when(payload.readStringFixByBytes(expected.length())).thenReturn(expected.getBytes());
Serializable actual = new MySQLStringBinlogProtocolValue().read(columnDef, payload);
- assertInstanceOf(MySQLBinaryString.class, actual);
+ assertThat(actual, instanceOf(MySQLBinaryString.class));
assertThat(((MySQLBinaryString) actual).getBytes(), is(expected.getBytes()));
}
diff --git a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/channel/memory/MemoryPipelineChannelCreatorTest.java b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/channel/memory/MemoryPipelineChannelCreatorTest.java
index d994a44a5cd..bd0110475dd 100644
--- a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/channel/memory/MemoryPipelineChannelCreatorTest.java
+++ b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/channel/memory/MemoryPipelineChannelCreatorTest.java
@@ -30,9 +30,9 @@ import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.atomic.AtomicReference;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertInstanceOf;
class MemoryPipelineChannelCreatorTest {
@@ -41,7 +41,7 @@ class MemoryPipelineChannelCreatorTest {
PipelineChannelCreator creator = TypedSPILoader.getService(PipelineChannelCreator.class, "MEMORY", PropertiesBuilder.build(new Property("block-queue-size", "2000")));
assertThat(Plugins.getMemberAccessor().get(MemoryPipelineChannelCreator.class.getDeclaredField("queueSize"), creator), is(2000));
PipelineChannel channel = creator.newInstance(1000, new InventoryTaskAckCallback(new AtomicReference<>()));
- assertInstanceOf(ArrayBlockingQueue.class, Plugins.getMemberAccessor().get(MemoryPipelineChannel.class.getDeclaredField("queue"), channel));
+ assertThat(Plugins.getMemberAccessor().get(MemoryPipelineChannel.class.getDeclaredField("queue"), channel), instanceOf(ArrayBlockingQueue.class));
}
@Test
@@ -49,7 +49,7 @@ class MemoryPipelineChannelCreatorTest {
PipelineChannelCreator creator = TypedSPILoader.getService(PipelineChannelCreator.class, "MEMORY", PropertiesBuilder.build(new Property("block-queue-size", "0")));
assertThat(Plugins.getMemberAccessor().get(MemoryPipelineChannelCreator.class.getDeclaredField("queueSize"), creator), is(0));
PipelineChannel channel = creator.newInstance(1000, new InventoryTaskAckCallback(new AtomicReference<>()));
- assertInstanceOf(SynchronousQueue.class, Plugins.getMemberAccessor().get(MemoryPipelineChannel.class.getDeclaredField("queue"), channel));
+ assertThat(Plugins.getMemberAccessor().get(MemoryPipelineChannel.class.getDeclaredField("queue"), channel), instanceOf(SynchronousQueue.class));
}
@Test
diff --git a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/consistencycheck/table/TableDataConsistencyCheckerFactoryTest.java b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/consistencycheck/table/TableDataConsistencyCheckerFactoryTest.java
index 86329ec79a8..dc261ac84a0 100644
--- a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/consistencycheck/table/TableDataConsistencyCheckerFactoryTest.java
+++ b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/consistencycheck/table/TableDataConsistencyCheckerFactoryTest.java
@@ -21,17 +21,17 @@ import org.junit.jupiter.api.Test;
import java.util.Properties;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertInstanceOf;
class TableDataConsistencyCheckerFactoryTest {
@Test
void assertNewInstanceTypeMatched() {
- assertInstanceOf(DataMatchTableDataConsistencyChecker.class, TableDataConsistencyCheckerFactory.newInstance(null, new Properties()));
- assertInstanceOf(DataMatchTableDataConsistencyChecker.class, TableDataConsistencyCheckerFactory.newInstance("DATA_MATCH", new Properties()));
- assertInstanceOf(CRC32MatchTableDataConsistencyChecker.class, TableDataConsistencyCheckerFactory.newInstance("CRC32_MATCH", new Properties()));
+ assertThat(TableDataConsistencyCheckerFactory.newInstance(null, new Properties()), instanceOf(DataMatchTableDataConsistencyChecker.class));
+ assertThat(TableDataConsistencyCheckerFactory.newInstance("DATA_MATCH", new Properties()), instanceOf(DataMatchTableDataConsistencyChecker.class));
+ assertThat(TableDataConsistencyCheckerFactory.newInstance("CRC32_MATCH", new Properties()), instanceOf(CRC32MatchTableDataConsistencyChecker.class));
}
@Test
diff --git a/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/incremental/client/netty/MySQLBinlogEventPacketDecoderTest.java b/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/incremental/client/netty/MySQLBinlogEventPacketDecoderTest.java
index b4a6a798658..307c4026314 100644
--- a/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/incremental/client/netty/MySQLBinlogEventPacketDecoderTest.java
+++ b/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/incremental/client/netty/MySQLBinlogEventPacketDecoderTest.java
@@ -24,8 +24,8 @@ import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.util.internal.StringUtil;
import org.apache.shardingsphere.data.pipeline.mysql.ingest.incremental.binlog.MySQLBinlogContext;
-import org.apache.shardingsphere.data.pipeline.mysql.ingest.incremental.binlog.event.rows.MySQLDeleteRowsBinlogEvent;
import org.apache.shardingsphere.data.pipeline.mysql.ingest.incremental.binlog.event.query.MySQLQueryBinlogEvent;
+import org.apache.shardingsphere.data.pipeline.mysql.ingest.incremental.binlog.event.rows.MySQLDeleteRowsBinlogEvent;
import org.apache.shardingsphere.data.pipeline.mysql.ingest.incremental.binlog.event.rows.MySQLUpdateRowsBinlogEvent;
import org.apache.shardingsphere.data.pipeline.mysql.ingest.incremental.binlog.event.rows.MySQLWriteRowsBinlogEvent;
import org.apache.shardingsphere.data.pipeline.mysql.ingest.incremental.binlog.event.transaction.MySQLXidBinlogEvent;
@@ -52,7 +52,6 @@ import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when;
@@ -72,6 +71,7 @@ class MySQLBinlogEventPacketDecoderTest {
private List<MySQLBinlogColumnDef> columnDefs;
+ @SuppressWarnings("CollectionWithoutInitialCapacity")
@BeforeEach
void setUp() throws NoSuchFieldException, IllegalAccessException {
binlogEventPacketDecoder = new MySQLBinlogEventPacketDecoder(4, new ConcurrentHashMap<>(), true);
@@ -120,7 +120,7 @@ class MySQLBinlogEventPacketDecoderTest {
binlogEventPacketDecoder.decode(channelHandlerContext, byteBuf, decodedEvents);
assertFalse(decodedEvents.isEmpty());
Object actual = decodedEvents.get(0);
- assertInstanceOf(MySQLQueryBinlogEvent.class, actual);
+ assertThat(actual, instanceOf(MySQLQueryBinlogEvent.class));
assertThat(((MySQLQueryBinlogEvent) actual).getTimestamp(), is(1700193011L));
assertThat(((MySQLQueryBinlogEvent) actual).getPosition(), is(168785090L));
}
diff --git a/kernel/data-pipeline/dialect/opengauss/src/test/java/org/apache/shardingsphere/data/pipeline/opengauss/ingest/incremental/wal/decode/MppdbDecodingPluginTest.java b/kernel/data-pipeline/dialect/opengauss/src/test/java/org/apache/shardingsphere/data/pipeline/opengauss/ingest/incremental/wal/decode/MppdbDecodingPluginTest.java
index 219e35e25fa..5920cc52511 100644
--- a/kernel/data-pipeline/dialect/opengauss/src/test/java/org/apache/shardingsphere/data/pipeline/opengauss/ingest/incremental/wal/decode/MppdbDecodingPluginTest.java
+++ b/kernel/data-pipeline/dialect/opengauss/src/test/java/org/apache/shardingsphere/data/pipeline/opengauss/ingest/incremental/wal/decode/MppdbDecodingPluginTest.java
@@ -44,7 +44,6 @@ import java.util.stream.IntStream;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
@@ -243,9 +242,9 @@ class MppdbDecodingPluginTest {
}
assertThat(expectedEvent.size(), is(4));
AbstractWALEvent actualFirstEvent = expectedEvent.get(0);
- assertInstanceOf(BeginTXEvent.class, actualFirstEvent);
+ assertThat(actualFirstEvent, instanceOf(BeginTXEvent.class));
AbstractWALEvent actualLastEvent = expectedEvent.get(expectedEvent.size() - 1);
- assertInstanceOf(CommitTXEvent.class, actualLastEvent);
+ assertThat(actualLastEvent, instanceOf(CommitTXEvent.class));
assertThat(((CommitTXEvent) actualLastEvent).getCsn(), is(3468L));
assertThat(((CommitTXEvent) actualLastEvent).getXid(), is(1L));
}
@@ -265,7 +264,7 @@ class MppdbDecodingPluginTest {
actual.add(mppdbDecodingPlugin.decode(ByteBuffer.wrap(each.getBytes()), logSequenceNumber));
}
assertThat(actual.size(), is(4));
- assertInstanceOf(BeginTXEvent.class, actual.get(0));
+ assertThat(actual.get(0), instanceOf(BeginTXEvent.class));
assertThat(((BeginTXEvent) actual.get(0)).getCsn(), is(951909L));
assertThat(((WriteRowEvent) actual.get(1)).getAfterRow().get(0).toString(), is("7D"));
assertThat(((WriteRowEvent) actual.get(2)).getAfterRow().get(0).toString(), is("7D"));
diff --git a/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/incremental/wal/WALEventConverterTest.java b/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/incremental/wal/WALEventConverterTest.java
index fb3006a92d2..ed615d01024 100644
--- a/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/incremental/wal/WALEventConverterTest.java
+++ b/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/incremental/wal/WALEventConverterTest.java
@@ -64,7 +64,6 @@ import java.util.stream.Collectors;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertThrows;
class WALEventConverterTest {
@@ -152,7 +151,7 @@ class WALEventConverterTest {
BeginTXEvent beginTXEvent = new BeginTXEvent(100L, null);
beginTXEvent.setLogSequenceNumber(new PostgreSQLLogSequenceNumber(logSequenceNumber));
Record record = walEventConverter.convert(beginTXEvent);
- assertInstanceOf(PlaceholderRecord.class, record);
+ assertThat(record, instanceOf(PlaceholderRecord.class));
assertThat(((WALPosition) record.getPosition()).getLogSequenceNumber().asString(), is(logSequenceNumber.asString()));
}
@@ -161,7 +160,7 @@ class WALEventConverterTest {
CommitTXEvent commitTXEvent = new CommitTXEvent(1L, 3468L);
commitTXEvent.setLogSequenceNumber(new PostgreSQLLogSequenceNumber(logSequenceNumber));
Record record = walEventConverter.convert(commitTXEvent);
- assertInstanceOf(PlaceholderRecord.class, record);
+ assertThat(record, instanceOf(PlaceholderRecord.class));
assertThat(((WALPosition) record.getPosition()).getLogSequenceNumber().asString(), is(logSequenceNumber.asString()));
}
@@ -194,7 +193,7 @@ class WALEventConverterTest {
@Test
void assertUnknownTable() {
- assertInstanceOf(PlaceholderRecord.class, walEventConverter.convert(mockUnknownTableEvent()));
+ assertThat(walEventConverter.convert(mockUnknownTableEvent()), instanceOf(PlaceholderRecord.class));
}
@Test
diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/export/ExportMetaDataExecutorTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/export/ExportMetaDataExecutorTest.java
index 94128767e02..ba35419aad5 100644
--- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/export/ExportMetaDataExecutorTest.java
+++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/export/ExportMetaDataExecutorTest.java
@@ -71,9 +71,9 @@ import java.util.Optional;
import java.util.Properties;
import java.util.stream.Collectors;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -194,7 +194,7 @@ class ExportMetaDataExecutorTest {
private void assertMetaData(final Object actual, final String expected) {
assertNotNull(actual);
- assertInstanceOf(String.class, actual);
+ assertThat(actual, instanceOf(String.class));
assertMetaData(convertToExportedClusterInfo((String) actual), convertToExportedClusterInfo(expected));
}
diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/comment/CommentAssert.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/comment/CommentAssert.java
index 3e1db388523..6d249f73ea3 100644
--- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/comment/CommentAssert.java
+++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/comment/CommentAssert.java
@@ -27,9 +27,9 @@ import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.s
import java.util.Iterator;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
@@ -54,13 +54,11 @@ public final class CommentAssert {
}
private static void assertEmptyComment(final SQLCaseAssertContext assertContext, final SQLStatement actual) {
- if (actual instanceof SQLStatement) {
- assertTrue(actual.getComments().isEmpty(), assertContext.getText("Comment should be empty."));
- }
+ assertTrue(actual.getComments().isEmpty(), assertContext.getText("Comment should be empty."));
}
private static void assertCorrectComment(final SQLCaseAssertContext assertContext, final SQLStatement actual, final SQLParserTestCase expected) {
- assertInstanceOf(SQLStatement.class, actual, assertContext.getText("Comment should exist."));
+ assertThat(assertContext.getText("Comment should exist."), actual, instanceOf(SQLStatement.class));
assertThat(assertContext.getText("Comments size assertion error: "), actual.getComments().size(), is(expected.getComments().size()));
Iterator<CommentSegment> actualIterator = actual.getComments().iterator();
for (ExpectedComment each : expected.getComments()) {