From 78bb3dc0496fa149d0317f667c859a6f7e1448fd Mon Sep 17 00:00:00 2001 From: gzhao9 <74684732+gzhao9@users.noreply.github.com> Date: Tue, 17 Oct 2023 04:55:42 -0400 Subject: [PATCH] Update EchoFilterTest.java (#13215) --- .../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 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 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 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 createMockInvoker(Invocation invocation){ Invoker 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; } }