RpcUtils { public static Class<?>[] getParameterTypes(Invocation invocation) { if ($INVOKE.equals(invocation.getMethodName()) && invocation.getArguments() != null && invocation.getArguments().length > 1 && invocation.getArguments()[1] instanceof String[]) { String[] types = (String[]) invocation.getArguments()[1]; if (types == null) { return new Class<?>[0]; } Class<?>[] parameterTypes = new Class<?>[types.length]; for (int i = 0; i < types.length; i++) { parameterTypes[i] = ReflectUtils.forName(types[0]); } return parameterTypes; } return invocation.getParameterTypes(); }  static Class<?> getReturnType(Invocation invocation); static Type[] getReturnTypes(Invocation invocation); static Long getInvocationId(Invocation inv); static void attachInvocationIdIfAsync(URL url, Invocation inv); static String getMethodName(Invocation invocation); static Object[] getArguments(Invocation invocation); static Class<?>[] getParameterTypes(Invocation invocation); static boolean isAsync(URL url, Invocation inv); static boolean isReturnTypeFuture(Invocation inv); static boolean isGenericAsync(Invocation inv); static boolean isGenericCall(String parameterTypesDesc, String method); static boolean isEcho(String parameterTypesDesc, String method); static InvokeMode getInvokeMode(URL url, Invocation inv); static boolean isOneway(URL url, Invocation inv); static long getTimeout(Invocation invocation, long defaultTimeout); static long getTimeout(URL url, String methodName, RpcContext context, long defaultTimeout);  }
@Test public void testGetParameterTypes() { Class<?> demoServiceClass = DemoService.class; String serviceName = demoServiceClass.getName(); Invoker invoker = mock(Invoker.class); RpcInvocation inv1 = new RpcInvocation("sayHello", serviceName, "", new Class<?>[]{String.class}, null, null, invoker, null); Class<?>[] parameterTypes1 = RpcUtils.getParameterTypes(inv1); Assertions.assertNotNull(parameterTypes1); Assertions.assertEquals(1, parameterTypes1.length); Assertions.assertEquals(String.class, parameterTypes1[0]); RpcInvocation inv2 = new RpcInvocation("timestamp", serviceName, "", null, null, null, invoker, null); Class<?>[] parameterTypes2 = RpcUtils.getParameterTypes(inv2); Assertions.assertEquals(0, parameterTypes2.length); RpcInvocation inv3 = new RpcInvocation("enumlength", serviceName, "", new Class<?>[]{Type.class, Type.class}, null, null, invoker, null); Class<?>[] parameterTypes3 = RpcUtils.getParameterTypes(inv3); Assertions.assertNotNull(parameterTypes3); Assertions.assertEquals(2, parameterTypes3.length); Assertions.assertEquals(Type.class, parameterTypes3[0]); Assertions.assertEquals(Type.class, parameterTypes3[1]); RpcInvocation inv4 = new RpcInvocation("getbyte", serviceName, "", new Class<?>[]{byte.class}, null, null, invoker, null); Class<?>[] parameterTypes4 = RpcUtils.getParameterTypes(inv4); Assertions.assertNotNull(parameterTypes4); Assertions.assertEquals(1, parameterTypes4.length); Assertions.assertEquals(byte.class, parameterTypes4[0]); RpcInvocation inv5 = new RpcInvocation("$invoke", serviceName, "", new Class<?>[]{String.class, String[].class}, new Object[]{"method", new String[]{"java.lang.String", "void", "java.lang.Object"}}, null, invoker, null); Class<?>[] parameterTypes5 = RpcUtils.getParameterTypes(inv5); Assertions.assertNotNull(parameterTypes5); Assertions.assertEquals(3, parameterTypes5.length); Assertions.assertEquals(String.class, parameterTypes5[0]); Assertions.assertEquals(String.class, parameterTypes5[1]); Assertions.assertEquals(String.class, parameterTypes5[2]); }