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

crazyhzm pushed a commit to branch 3.2
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.2 by this push:
     new a0c9017e8d Add more test coverage for 
org.apache.dubbo.rpc.protocol.dubbo.pu (#14503)
a0c9017e8d is described below

commit a0c9017e8d23b9fef5ce7e9e08903e98aff9c789
Author: guning <[email protected]>
AuthorDate: Thu Aug 8 07:11:53 2024 +0800

    Add more test coverage for org.apache.dubbo.rpc.protocol.dubbo.pu (#14503)
    
    * Add more test coverage for org.apache.dubbo.rpc.protocol.dubbo.pu
    
    * Add more test coverage for org.apache.dubbo.rpc.protocol.dubbo.pu
    
    * Add more test coverage for org.apache.dubbo.rpc.protocol.dubbo.pu
    
    * Add more test coverage for org.apache.dubbo.rpc.protocol.dubbo.pu
---
 .../rpc/protocol/dubbo/pu/DubboDetectorTest.java   | 47 ++++++++++++++++++
 .../protocol/dubbo/pu/DubboWireProtocolTest.java   | 55 ++++++++++++++++++++++
 2 files changed, 102 insertions(+)

diff --git 
a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/pu/DubboDetectorTest.java
 
b/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/pu/DubboDetectorTest.java
new file mode 100644
index 0000000000..3c433740aa
--- /dev/null
+++ 
b/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/pu/DubboDetectorTest.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.rpc.protocol.dubbo.pu;
+
+import org.apache.dubbo.remoting.buffer.ChannelBuffer;
+import org.apache.dubbo.remoting.buffer.ChannelBuffers;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class DubboDetectorTest {
+    @Test
+    void testDetect_Recognized() {
+        DubboDetector detector = new DubboDetector();
+        ChannelBuffer in = ChannelBuffers.wrappedBuffer(new byte[] {(byte) 
0xda, (byte) 0xbb});
+        assertEquals(DubboDetector.Result.RECOGNIZED, detector.detect(in));
+    }
+
+    @Test
+    void testDetect_Unrecognized() {
+        DubboDetector detector = new DubboDetector();
+        ChannelBuffer in = ChannelBuffers.wrappedBuffer(new byte[] {(byte) 
0x00, (byte) 0x00});
+        assertEquals(DubboDetector.Result.UNRECOGNIZED, detector.detect(in));
+    }
+
+    @Test
+    void testDetect_NeedMoreData() {
+        DubboDetector detector = new DubboDetector();
+        ChannelBuffer in = ChannelBuffers.wrappedBuffer(new byte[] {(byte) 
0xda});
+        assertEquals(DubboDetector.Result.NEED_MORE_DATA, detector.detect(in));
+    }
+}
diff --git 
a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/pu/DubboWireProtocolTest.java
 
b/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/pu/DubboWireProtocolTest.java
new file mode 100644
index 0000000000..8bd6c9edc0
--- /dev/null
+++ 
b/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/pu/DubboWireProtocolTest.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.rpc.protocol.dubbo.pu;
+
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.remoting.ChannelHandler;
+import org.apache.dubbo.remoting.api.pu.ChannelOperator;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import static org.mockito.Mockito.verify;
+
+class DubboWireProtocolTest {
+    @InjectMocks
+    private DubboWireProtocol dubboWireProtocol;
+
+    @Mock
+    private ChannelOperator channelOperator;
+
+    @BeforeEach
+    void setUp() throws Exception {
+        MockitoAnnotations.openMocks(this).close();
+    }
+
+    @Test
+    void testConfigServerProtocolHandler() {
+        URL url = URL.valueOf("dubbo://localhost:20880");
+        List<ChannelHandler> handlers = new ArrayList<>();
+
+        dubboWireProtocol.configServerProtocolHandler(url, channelOperator);
+
+        verify(channelOperator).configChannelHandler(handlers);
+    }
+}

Reply via email to