@@ -44,6 +44,8 @@ public class CacheFilterTest {
4444 private Invoker <?> invoker = mock (Invoker .class );
4545 private Invoker <?> invoker1 = mock (Invoker .class );
4646 private Invoker <?> invoker2 = mock (Invoker .class );
47+ private Invoker <?> invoker3 = mock (Invoker .class );
48+ private Invoker <?> invoker4 = mock (Invoker .class );
4749 private String cacheType ;
4850 private CacheFactory cacheFactory ;
4951
@@ -77,6 +79,11 @@ public void setUp() throws Exception {
7779 given (invoker2 .invoke (invocation )).willReturn (new RpcResult ("value2" ));
7880 given (invoker2 .getUrl ()).willReturn (url );
7981
82+ given (invoker3 .invoke (invocation )).willReturn (new RpcResult (new RuntimeException ()));
83+ given (invoker3 .getUrl ()).willReturn (url );
84+
85+ given (invoker4 .invoke (invocation )).willReturn (new RpcResult ());
86+ given (invoker4 .getUrl ()).willReturn (url );
8087 }
8188
8289 @ Test
@@ -89,6 +96,7 @@ public void testNonArgsMethod() {
8996 RpcResult rpcResult1 = (RpcResult ) cacheFilter .invoke (invoker1 , invocation );
9097 RpcResult rpcResult2 = (RpcResult ) cacheFilter .invoke (invoker2 , invocation );
9198 Assert .assertEquals (rpcResult1 .getValue (), rpcResult2 .getValue ());
99+ Assert .assertEquals (rpcResult1 .getValue (), "value" );
92100 }
93101
94102 @ Test
@@ -101,5 +109,30 @@ public void testMethodWithArgs() {
101109 RpcResult rpcResult1 = (RpcResult ) cacheFilter .invoke (invoker1 , invocation );
102110 RpcResult rpcResult2 = (RpcResult ) cacheFilter .invoke (invoker2 , invocation );
103111 Assert .assertEquals (rpcResult1 .getValue (), rpcResult2 .getValue ());
112+ Assert .assertEquals (rpcResult1 .getValue (), "value" );
113+ }
114+
115+ @ Test
116+ public void testException () {
117+ invocation .setMethodName ("echo1" );
118+ invocation .setParameterTypes (new Class <?>[]{String .class });
119+ invocation .setArguments (new Object []{"arg2" });
120+
121+ cacheFilter .invoke (invoker3 , invocation );
122+ RpcResult rpcResult = (RpcResult ) cacheFilter .invoke (invoker2 , invocation );
123+ Assert .assertEquals (rpcResult .getValue (), "value2" );
124+ }
125+
126+ @ Test
127+ public void testNull () {
128+ invocation .setMethodName ("echo1" );
129+ invocation .setParameterTypes (new Class <?>[]{String .class });
130+ invocation .setArguments (new Object []{"arg3" });
131+
132+ cacheFilter .invoke (invoker4 , invocation );
133+ RpcResult rpcResult1 = (RpcResult ) cacheFilter .invoke (invoker1 , invocation );
134+ RpcResult rpcResult2 = (RpcResult ) cacheFilter .invoke (invoker2 , invocation );
135+ Assert .assertEquals (rpcResult1 .getValue (), "value1" );
136+ Assert .assertEquals (rpcResult2 .getValue (), "value1" );
104137 }
105138}
0 commit comments