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/18 00:00:25 UTC
(shardingsphere) branch master updated: Use assertThat to instead of assertEquals (#36331)
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 b8e227f4c12 Use assertThat to instead of assertEquals (#36331)
b8e227f4c12 is described below
commit b8e227f4c126b72ce33d050de78ca6a74e593008
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Mon Aug 18 08:00:19 2025 +0800
Use assertThat to instead of assertEquals (#36331)
---
.../firebird/packet/handshake/FirebirdAcceptPacketTest.java | 9 ++++-----
.../firebird/packet/handshake/FirebirdAttachPacketTest.java | 3 +--
.../firebird/packet/handshake/FirebirdConnectPacketTest.java | 8 ++------
.../statement/FirebirdAllocateStatementCommandExecutorTest.java | 8 ++++----
.../transaction/FirebirdStartTransactionCommandExecutorTest.java | 8 ++++----
5 files changed, 15 insertions(+), 21 deletions(-)
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/handshake/FirebirdAcceptPacketTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/handshake/FirebirdAcceptPacketTest.java
index 7aa897dd069..b98bce789a1 100644
--- a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/handshake/FirebirdAcceptPacketTest.java
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/handshake/FirebirdAcceptPacketTest.java
@@ -30,12 +30,11 @@ import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
-import java.util.ArrayList;
+import java.util.LinkedList;
import java.util.List;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -54,18 +53,18 @@ class FirebirdAcceptPacketTest {
when(byteBuf.readInt()).thenReturn(FirebirdProtocolVersion.PROTOCOL_VERSION11.getCode(), FirebirdArchType.ARCH_GENERIC.getCode(), 0, 5, 1);
ByteBuf buf2 = mock(ByteBuf.class);
when(buf2.readInt()).thenReturn(FirebirdProtocolVersion.PROTOCOL_VERSION11.getCode(), FirebirdArchType.ARCH_GENERIC.getCode(), 0, 5, 2);
- List<FirebirdProtocol> list = new ArrayList<>();
+ List<FirebirdProtocol> list = new LinkedList<>();
list.add(new FirebirdProtocol(byteBuf));
list.add(new FirebirdProtocol(buf2));
FirebirdAcceptPacket packet = new FirebirdAcceptPacket(list);
- assertEquals(FirebirdCommandPacketType.ACCEPT, packet.getOpCode());
+ assertThat(packet.getOpCode(), is(FirebirdCommandPacketType.ACCEPT));
assertThat(packet.getProtocol().getWeight(), is(2));
}
@Test
void assertWriteWithAcceptDataPacket() {
when(byteBuf.readInt()).thenReturn(FirebirdProtocolVersion.PROTOCOL_VERSION11.getCode(), FirebirdArchType.ARCH_GENERIC.getCode(), 0, 5, 1);
- List<FirebirdProtocol> list = new ArrayList<>();
+ List<FirebirdProtocol> list = new LinkedList<>();
list.add(new FirebirdProtocol(byteBuf));
FirebirdAcceptPacket packet = new FirebirdAcceptPacket(list);
packet.setAcceptDataPacket(new byte[0], "", FirebirdAuthenticationMethod.SRP, 0, "");
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/handshake/FirebirdAttachPacketTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/handshake/FirebirdAttachPacketTest.java
index a49b835c372..a09c6759791 100644
--- a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/handshake/FirebirdAttachPacketTest.java
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/handshake/FirebirdAttachPacketTest.java
@@ -27,7 +27,6 @@ import org.mockito.junit.jupiter.MockitoExtension;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -62,7 +61,7 @@ class FirebirdAttachPacketTest {
when(slice4.toString(java.nio.charset.StandardCharsets.UTF_8)).thenReturn("passwd");
when(dpb.readSlice(anyInt())).thenReturn(slice1, slice2, slice3, slice4);
FirebirdAttachPacket packet = new FirebirdAttachPacket(payload);
- assertEquals(100, packet.getId());
+ assertThat(packet.getId(), is(100));
assertThat(packet.getDatabase(), is("db"));
assertThat(packet.getEncoding(), is("UTF8"));
assertThat(packet.getAuthData(), is("ad"));
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/handshake/FirebirdConnectPacketTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/handshake/FirebirdConnectPacketTest.java
index aa408da9344..eed74dbfda4 100644
--- a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/handshake/FirebirdConnectPacketTest.java
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/handshake/FirebirdConnectPacketTest.java
@@ -35,7 +35,6 @@ import java.util.List;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -76,12 +75,9 @@ class FirebirdConnectPacketTest {
when(specBuf1.toString(StandardCharsets.US_ASCII)).thenReturn("A");
when(specBuf2.readUnsignedByte()).thenReturn((short) 1);
when(specBuf2.toString(StandardCharsets.US_ASCII)).thenReturn("B");
- when(protocolBuf.readInt()).thenReturn(
- FirebirdProtocolVersion.PROTOCOL_VERSION10.getCode(),
- FirebirdArchType.ARCH_GENERIC.getCode(),
- 0, 5, 1);
+ when(protocolBuf.readInt()).thenReturn(FirebirdProtocolVersion.PROTOCOL_VERSION10.getCode(), FirebirdArchType.ARCH_GENERIC.getCode(), 0, 5, 1);
FirebirdConnectPacket packet = new FirebirdConnectPacket(payload);
- assertEquals(FirebirdCommandPacketType.CONNECT, packet.getOpCode());
+ assertThat(packet.getOpCode(), is(FirebirdCommandPacketType.CONNECT));
assertThat(packet.getConnectVersion(), is(1));
assertThat(packet.getArchType(), is(FirebirdArchType.ARCH_GENERIC));
assertThat(packet.getDatabase(), is("db"));
diff --git a/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/statement/FirebirdAllocateStatementCommandExecutorTest.java b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/statement/FirebirdAllocateStatementCommandExecutorTest.java
index 22a808f987c..a1efd06feaa 100644
--- a/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/statement/FirebirdAllocateStatementCommandExecutorTest.java
+++ b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/statement/FirebirdAllocateStatementCommandExecutorTest.java
@@ -24,17 +24,17 @@ import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
-import org.junit.jupiter.api.extension.ExtendWith;
import java.sql.SQLException;
import java.util.Collection;
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.assertEquals;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
@@ -63,8 +63,8 @@ class FirebirdAllocateStatementCommandExecutorTest {
void assertExecute() throws SQLException {
FirebirdAllocateStatementCommandExecutor executor = new FirebirdAllocateStatementCommandExecutor(packet, connectionSession);
Collection<DatabasePacket> actual = executor.execute();
- assertEquals(1, actual.size());
+ assertThat(actual.size(), is(1));
assertThat(actual.iterator().next(), instanceOf(FirebirdGenericResponsePacket.class));
- assertEquals(1, ((FirebirdGenericResponsePacket) actual.iterator().next()).getHandle());
+ assertThat(((FirebirdGenericResponsePacket) actual.iterator().next()).getHandle(), is(1));
}
}
diff --git a/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/transaction/FirebirdStartTransactionCommandExecutorTest.java b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/transaction/FirebirdStartTransactionCommandExecutorTest.java
index 61182265946..2d90f018d7f 100644
--- a/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/transaction/FirebirdStartTransactionCommandExecutorTest.java
+++ b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/transaction/FirebirdStartTransactionCommandExecutorTest.java
@@ -21,21 +21,21 @@ import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.trans
import org.apache.shardingsphere.db.protocol.firebird.packet.generic.FirebirdGenericResponsePacket;
import org.apache.shardingsphere.db.protocol.packet.DatabasePacket;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
+import org.apache.shardingsphere.sql.parser.statement.core.enums.TransactionIsolationLevel;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.apache.shardingsphere.sql.parser.statement.core.enums.TransactionIsolationLevel;
import java.sql.SQLException;
import java.util.Collection;
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.assertEquals;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -70,7 +70,7 @@ class FirebirdStartTransactionCommandExecutorTest {
Collection<DatabasePacket> actual = executor.execute();
DatabasePacket first = actual.iterator().next();
assertThat(first, instanceOf(FirebirdGenericResponsePacket.class));
- assertEquals(1, ((FirebirdGenericResponsePacket) first).getHandle());
+ assertThat(((FirebirdGenericResponsePacket) first).getHandle(), is(1));
verify(connectionSession).setAutoCommit(true);
verify(connectionSession).setReadOnly(true);
verify(connectionSession).setIsolationLevel(TransactionIsolationLevel.SERIALIZABLE);