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

albumenj 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 78bb3dc049 Update EchoFilterTest.java (#13215)
78bb3dc049 is described below

commit 78bb3dc0496fa149d0317f667c859a6f7e1448fd
Author: gzhao9 <[email protected]>
AuthorDate: Tue Oct 17 04:55:42 2023 -0400

    Update EchoFilterTest.java (#13215)
---
 .../apache/dubbo/rpc/filter/EchoFilterTest.java    | 34 ++++++++++------------
 1 file changed, 16 insertions(+), 18 deletions(-)

diff --git 
a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/EchoFilterTest.java
 
b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/EchoFilterTest.java
index 2c67db6ffc..3408b2ebc5 100644
--- 
a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/EchoFilterTest.java
+++ 
b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/EchoFilterTest.java
@@ -38,20 +38,9 @@ class EchoFilterTest {
     @SuppressWarnings("unchecked")
     @Test
     void testEcho() {
-        Invocation invocation = mock(RpcInvocation.class);
+        Invocation invocation = createMockRpcInvocation();
+        Invoker<DemoService> invoker = createMockInvoker(invocation);
         given(invocation.getMethodName()).willReturn("$echo");
-        given(invocation.getParameterTypes()).willReturn(new 
Class<?>[]{Enum.class});
-        given(invocation.getArguments()).willReturn(new Object[]{"hello"});
-        given(invocation.getObjectAttachments()).willReturn(null);
-
-        Invoker<DemoService> invoker = mock(Invoker.class);
-        given(invoker.isAvailable()).willReturn(true);
-        given(invoker.getInterface()).willReturn(DemoService.class);
-        AppResponse result = new AppResponse();
-        result.setValue("High");
-        given(invoker.invoke(invocation)).willReturn(result);
-        URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
-        given(invoker.getUrl()).willReturn(url);
 
         Result filterResult = echoFilter.invoke(invoker, invocation);
         assertEquals("hello", filterResult.getValue());
@@ -60,22 +49,31 @@ class EchoFilterTest {
     @SuppressWarnings("unchecked")
     @Test
     void testNonEcho() {
-        Invocation invocation = mock(Invocation.class);
+        Invocation invocation = createMockRpcInvocation();
+        Invoker<DemoService> invoker = createMockInvoker(invocation);
         given(invocation.getMethodName()).willReturn("echo");
+
+        Result filterResult = echoFilter.invoke(invoker, invocation);
+        assertEquals("High", filterResult.getValue());
+    }
+
+    Invocation createMockRpcInvocation() {
+        Invocation invocation = mock(RpcInvocation.class);
         given(invocation.getParameterTypes()).willReturn(new 
Class<?>[]{Enum.class});
         given(invocation.getArguments()).willReturn(new Object[]{"hello"});
         given(invocation.getObjectAttachments()).willReturn(null);
-
+        return invocation;
+    }
+    Invoker<DemoService> createMockInvoker(Invocation invocation){
         Invoker<DemoService> invoker = mock(Invoker.class);
         given(invoker.isAvailable()).willReturn(true);
         given(invoker.getInterface()).willReturn(DemoService.class);
+
         AppResponse result = new AppResponse();
         result.setValue("High");
         given(invoker.invoke(invocation)).willReturn(result);
         URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
         given(invoker.getUrl()).willReturn(url);
-
-        Result filterResult = echoFilter.invoke(invoker, invocation);
-        assertEquals("High", filterResult.getValue());
+        return invoker;
     }
 }

Reply via email to