Update EchoFilterTest.java (#13215)

This commit is contained in:
gzhao9 2023-10-17 04:55:42 -04:00 committed by GitHub
parent bf0522d7e0
commit 78bb3dc049
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 18 deletions

View File

@ -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;
}
}