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 724a1501f54 Add more test cases for FirebirdConnectPacketTest and 
FirebirdAttachPacketTest (#38163)
724a1501f54 is described below

commit 724a1501f54b81682eb4970c5a06f978b16bb70e
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Feb 23 20:29:58 2026 +0800

    Add more test cases for FirebirdConnectPacketTest and 
FirebirdAttachPacketTest (#38163)
    
    * Add more test cases for FirebirdConnectPacketTest and 
FirebirdAttachPacketTest
    
    * Add more test cases for FirebirdConnectPacketTest and 
FirebirdAttachPacketTest
---
 .../packet/handshake/FirebirdAttachPacket.java     |   1 -
 .../packet/handshake/FirebirdAttachPacketTest.java |  73 +++++++++----
 .../handshake/FirebirdConnectPacketTest.java       | 121 ++++++++++++++-------
 3 files changed, 132 insertions(+), 63 deletions(-)

diff --git 
a/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/packet/handshake/FirebirdAttachPacket.java
 
b/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/packet/handshake/FirebirdAttachPacket.java
index df9d8247582..94f9ed964e0 100644
--- 
a/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/packet/handshake/FirebirdAttachPacket.java
+++ 
b/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/packet/handshake/FirebirdAttachPacket.java
@@ -59,6 +59,5 @@ public final class FirebirdAttachPacket extends 
FirebirdPacket {
     
     @Override
     protected void write(final FirebirdPacketPayload payload) {
-        
     }
 }
diff --git 
a/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/handshake/FirebirdAttachPacketTest.java
 
b/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/handshake/FirebirdAttachPacketTest.java
index 08046e5949c..6ee46d22539 100644
--- 
a/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/handshake/FirebirdAttachPacketTest.java
+++ 
b/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/handshake/FirebirdAttachPacketTest.java
@@ -25,8 +25,11 @@ import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
 
-import static org.hamcrest.Matchers.is;
+import java.nio.charset.StandardCharsets;
+
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 import static org.mockito.ArgumentMatchers.anyInt;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -38,34 +41,56 @@ class FirebirdAttachPacketTest {
     private FirebirdPacketPayload payload;
     
     @Test
-    void assertAttachPacket() {
+    void assertConstructor() {
+        FirebirdAttachPacket actual = createPacket();
+        assertThat(actual.getId(), is(100));
+        assertThat(actual.getDatabase(), is("db"));
+    }
+    
+    @Test
+    void assertGetEncoding() {
+        assertThat(createPacket().getEncoding(), is("UTF8"));
+    }
+    
+    @Test
+    void assertGetAuthData() {
+        assertThat(createPacket().getAuthData(), is("ad"));
+    }
+    
+    @Test
+    void assertGetUsername() {
+        assertThat(createPacket().getUsername(), is("user"));
+    }
+    
+    @Test
+    void assertGetEncPassword() {
+        assertThat(createPacket().getEncPassword(), is("passwd"));
+    }
+    
+    @Test
+    void assertWrite() {
+        FirebirdAttachPacket packet = createPacket();
+        assertDoesNotThrow(() -> packet.write(payload));
+    }
+    
+    private FirebirdAttachPacket createPacket() {
         when(payload.readInt4()).thenReturn(100);
         when(payload.readString()).thenReturn("db");
         ByteBuf dpb = mock(ByteBuf.class);
         when(payload.readBuffer()).thenReturn(dpb);
-        when(dpb.readUnsignedByte()).thenReturn(
-                (short) 1,
-                (short) FirebirdDatabaseParameterBufferType.LC_CTYPE.getCode(),
-                (short) 
FirebirdDatabaseParameterBufferType.SPECIFIC_AUTH_DATA.getCode(),
-                (short) 
FirebirdDatabaseParameterBufferType.USER_NAME.getCode(),
-                (short) 
FirebirdDatabaseParameterBufferType.PASSWORD_ENC.getCode());
+        when(dpb.readUnsignedByte()).thenReturn((short) 1, (short) 
FirebirdDatabaseParameterBufferType.LC_CTYPE.getCode(), (short) 
FirebirdDatabaseParameterBufferType.SPECIFIC_AUTH_DATA.getCode(),
+                (short) 
FirebirdDatabaseParameterBufferType.USER_NAME.getCode(), (short) 
FirebirdDatabaseParameterBufferType.PASSWORD_ENC.getCode());
         when(dpb.isReadable()).thenReturn(true, true, true, true, false);
         when(dpb.readByte()).thenReturn((byte) 4, (byte) 2, (byte) 4, (byte) 
6);
-        ByteBuf slice1 = mock(ByteBuf.class);
-        
when(slice1.toString(java.nio.charset.StandardCharsets.UTF_8)).thenReturn("UTF8");
-        ByteBuf slice2 = mock(ByteBuf.class);
-        
when(slice2.toString(java.nio.charset.StandardCharsets.UTF_8)).thenReturn("ad");
-        ByteBuf slice3 = mock(ByteBuf.class);
-        
when(slice3.toString(java.nio.charset.StandardCharsets.UTF_8)).thenReturn("user");
-        ByteBuf slice4 = mock(ByteBuf.class);
-        
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);
-        assertThat(packet.getId(), is(100));
-        assertThat(packet.getDatabase(), is("db"));
-        assertThat(packet.getEncoding(), is("UTF8"));
-        assertThat(packet.getAuthData(), is("ad"));
-        assertThat(packet.getUsername(), is("user"));
-        assertThat(packet.getEncPassword(), is("passwd"));
+        ByteBuf encodingSlice = mock(ByteBuf.class);
+        
when(encodingSlice.toString(StandardCharsets.UTF_8)).thenReturn("UTF8");
+        ByteBuf authDataSlice = mock(ByteBuf.class);
+        when(authDataSlice.toString(StandardCharsets.UTF_8)).thenReturn("ad");
+        ByteBuf usernameSlice = mock(ByteBuf.class);
+        
when(usernameSlice.toString(StandardCharsets.UTF_8)).thenReturn("user");
+        ByteBuf encPasswordSlice = mock(ByteBuf.class);
+        
when(encPasswordSlice.toString(StandardCharsets.UTF_8)).thenReturn("passwd");
+        when(dpb.readSlice(anyInt())).thenReturn(encodingSlice, authDataSlice, 
usernameSlice, encPasswordSlice);
+        return new FirebirdAttachPacket(payload);
     }
 }
diff --git 
a/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/handshake/FirebirdConnectPacketTest.java
 
b/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/handshake/FirebirdConnectPacketTest.java
index 147dec7fc9b..93090f223fe 100644
--- 
a/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/handshake/FirebirdConnectPacketTest.java
+++ 
b/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/handshake/FirebirdConnectPacketTest.java
@@ -35,6 +35,7 @@ import java.util.List;
 
 import static org.hamcrest.Matchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -45,49 +46,93 @@ class FirebirdConnectPacketTest {
     private FirebirdPacketPayload payload;
     
     @Test
-    void assertConnectPacket() {
-        ByteBuf userInfo = mock(ByteBuf.class);
+    void assertConstructor() {
+        FirebirdConnectPacket actual = createPacketWithSpecificData();
+        assertThat(actual.getOpCode(), is(FirebirdCommandPacketType.CONNECT));
+        assertThat(actual.getConnectVersion(), is(1));
+        assertThat(actual.getArchType(), is(FirebirdArchType.ARCH_GENERIC));
+        assertThat(actual.getDatabase(), is("db"));
+        assertThat(actual.getProtocolsCount(), is(1));
+        List<FirebirdProtocol> actualProtocols = actual.getUserProtocols();
+        assertThat(actualProtocols.size(), is(1));
+        assertThat(actualProtocols.get(0).getVersion(), 
is(FirebirdProtocolVersion.PROTOCOL_VERSION10));
+    }
+    
+    @Test
+    void assertGetUsername() {
+        assertThat(createPacketWithSpecificData().getUsername(), is("user"));
+    }
+    
+    @Test
+    void assertGetPluginName() {
+        assertThat(createPacketWithSpecificData().getPluginName(), is("srp"));
+    }
+    
+    @Test
+    void assertGetPlugin() {
+        assertThat(createPacketWithSpecificData().getPlugin(), 
is(FirebirdAuthenticationMethod.SRP));
+    }
+    
+    @Test
+    void assertGetAuthData() {
+        assertThat(createPacketWithSpecificData().getAuthData(), is("AB"));
+    }
+    
+    @Test
+    void assertGetHost() {
+        assertThat(createPacketWithoutSpecificData().getHost(), is("host"));
+    }
+    
+    @Test
+    void assertGetLogin() {
+        assertThat(createPacketWithoutSpecificData().getLogin(), is("login"));
+    }
+    
+    @Test
+    void assertWrite() {
+        assertDoesNotThrow(() -> 
createPacketWithoutSpecificData().write(payload));
+    }
+    
+    private FirebirdConnectPacket createPacketWithSpecificData() {
+        
when(payload.readInt4()).thenReturn(FirebirdCommandPacketType.CONNECT.getValue(),
 1, FirebirdArchType.ARCH_GENERIC.getCode(), 1);
+        when(payload.readString()).thenReturn("db");
         ByteBuf userBuf = mock(ByteBuf.class);
+        when(userBuf.toString(StandardCharsets.UTF_8)).thenReturn("user");
         ByteBuf pluginBuf = mock(ByteBuf.class);
-        ByteBuf specBuf1 = mock(ByteBuf.class);
-        ByteBuf specBuf2 = mock(ByteBuf.class);
-        ByteBuf protocolBuf = mock(ByteBuf.class);
-        when(payload.readInt4()).thenReturn(
-                FirebirdCommandPacketType.CONNECT.getValue(),
-                1,
-                FirebirdArchType.ARCH_GENERIC.getCode(),
-                1);
-        when(payload.readString()).thenReturn("db");
-        when(payload.readBuffer()).thenReturn(userInfo);
-        when(payload.getByteBuf()).thenReturn(protocolBuf);
+        when(pluginBuf.toString(StandardCharsets.UTF_8)).thenReturn("srp");
+        ByteBuf specificDataFirstChunk = mock(ByteBuf.class);
+        when(specificDataFirstChunk.readUnsignedByte()).thenReturn((short) 0);
+        
when(specificDataFirstChunk.toString(StandardCharsets.US_ASCII)).thenReturn("A");
+        ByteBuf specificDataSecondChunk = mock(ByteBuf.class);
+        when(specificDataSecondChunk.readUnsignedByte()).thenReturn((short) 1);
+        
when(specificDataSecondChunk.toString(StandardCharsets.US_ASCII)).thenReturn("B");
+        ByteBuf userInfo = mock(ByteBuf.class);
         when(userInfo.isReadable()).thenReturn(true, true, true, true, false);
-        when(userInfo.readUnsignedByte()).thenReturn(
-                (short) FirebirdUserDataType.CNCT_USER.getCode(), (short) 4,
-                (short) FirebirdUserDataType.CNCT_PLUGIN_NAME.getCode(), 
(short) 3,
-                (short) FirebirdUserDataType.CNCT_SPECIFIC_DATA.getCode(), 
(short) 2,
-                (short) FirebirdUserDataType.CNCT_SPECIFIC_DATA.getCode(), 
(short) 2);
+        when(userInfo.readUnsignedByte()).thenReturn((short) 
FirebirdUserDataType.CNCT_USER.getCode(), (short) 4, (short) 
FirebirdUserDataType.CNCT_PLUGIN_NAME.getCode(), (short) 3,
+                (short) FirebirdUserDataType.CNCT_SPECIFIC_DATA.getCode(), 
(short) 2, (short) FirebirdUserDataType.CNCT_SPECIFIC_DATA.getCode(), (short) 
2);
         when(userInfo.readSlice(4)).thenReturn(userBuf);
         when(userInfo.readSlice(3)).thenReturn(pluginBuf);
-        when(userInfo.readSlice(2)).thenReturn(specBuf1, specBuf2);
-        when(userBuf.toString(StandardCharsets.UTF_8)).thenReturn("user");
-        when(pluginBuf.toString(StandardCharsets.UTF_8)).thenReturn("srp");
-        when(specBuf1.readUnsignedByte()).thenReturn((short) 0);
-        when(specBuf1.toString(StandardCharsets.US_ASCII)).thenReturn("A");
-        when(specBuf2.readUnsignedByte()).thenReturn((short) 1);
-        when(specBuf2.toString(StandardCharsets.US_ASCII)).thenReturn("B");
+        when(userInfo.readSlice(2)).thenReturn(specificDataFirstChunk, 
specificDataSecondChunk);
+        when(payload.readBuffer()).thenReturn(userInfo);
+        ByteBuf protocolBuf = mock(ByteBuf.class);
         
when(protocolBuf.readInt()).thenReturn(FirebirdProtocolVersion.PROTOCOL_VERSION10.getCode(),
 FirebirdArchType.ARCH_GENERIC.getCode(), 0, 5, 1);
-        FirebirdConnectPacket packet = new FirebirdConnectPacket(payload);
-        assertThat(packet.getOpCode(), is(FirebirdCommandPacketType.CONNECT));
-        assertThat(packet.getConnectVersion(), is(1));
-        assertThat(packet.getArchType(), is(FirebirdArchType.ARCH_GENERIC));
-        assertThat(packet.getDatabase(), is("db"));
-        assertThat(packet.getProtocolsCount(), is(1));
-        assertThat(packet.getUsername(), is("user"));
-        assertThat(packet.getPluginName(), is("srp"));
-        assertThat(packet.getPlugin(), is(FirebirdAuthenticationMethod.SRP));
-        assertThat(packet.getAuthData(), is("AB"));
-        List<FirebirdProtocol> protocols = packet.getUserProtocols();
-        assertThat(protocols.size(), is(1));
-        assertThat(protocols.get(0).getVersion(), 
is(FirebirdProtocolVersion.PROTOCOL_VERSION10));
+        when(payload.getByteBuf()).thenReturn(protocolBuf);
+        return new FirebirdConnectPacket(payload);
+    }
+    
+    private FirebirdConnectPacket createPacketWithoutSpecificData() {
+        
when(payload.readInt4()).thenReturn(FirebirdCommandPacketType.CONNECT.getValue(),
 1, FirebirdArchType.ARCH_GENERIC.getCode(), 0);
+        when(payload.readString()).thenReturn("db");
+        ByteBuf hostBuf = mock(ByteBuf.class);
+        when(hostBuf.toString(StandardCharsets.UTF_8)).thenReturn("host");
+        ByteBuf loginBuf = mock(ByteBuf.class);
+        when(loginBuf.toString(StandardCharsets.UTF_8)).thenReturn("login");
+        ByteBuf userInfo = mock(ByteBuf.class);
+        when(userInfo.isReadable()).thenReturn(true, true, false);
+        when(userInfo.readUnsignedByte()).thenReturn((short) 
FirebirdUserDataType.CNCT_HOST.getCode(), (short) 4, (short) 
FirebirdUserDataType.CNCT_LOGIN.getCode(), (short) 5);
+        when(userInfo.readSlice(4)).thenReturn(hostBuf);
+        when(userInfo.readSlice(5)).thenReturn(loginBuf);
+        when(payload.readBuffer()).thenReturn(userInfo);
+        return new FirebirdConnectPacket(payload);
     }
 }

Reply via email to