Update EchoFilterTest.java (#13215)
This commit is contained in:
parent
bf0522d7e0
commit
78bb3dc049
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue