Dispatcher { protected Method getConformingMethod(String methodName, Object[] arguments, Class<?> cls) { Method[] publicMethods = cls.getMethods(); Method result = null; methodLoop: for (int iMethod = 0; iMethod < publicMethods.length; iMethod++) { Method m = publicMethods[iMethod]; if (m.getName().equals(methodName)) { Class<?>[] formalParameters = m.getParameterTypes(); if (arguments.length == formalParameters.length) { for (int iParam = 0; iParam < arguments.length; iParam++) { Class<?> param = formalParameters[iParam]; Class<?> argParam = arguments[iParam].getClass(); if (!param.isAssignableFrom(argParam) && param != Utils.autobox(argParam)) { if (!(arguments[iParam] instanceof Reference && Utils.isRemoteObject(param))){ continue methodLoop; } else { arguments[iParam] = Utils.createProxy( (Reference) arguments[iParam], param); } } } result = m; break; } } } return result; } protected  Dispatcher(Bridge bridge); Reference storeRandomObject(Object object);  }
@Test public void testGetConformingMethod() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { ConformingMethodTestClass testInstance = new ConformingMethodTestClass(); Object[] methodArgs = new Object[] { 1.0f, new ArrayList<String>() }; Method method = dispatcher.getConformingMethod("nonPolymorphic", methodArgs, ConformingMethodTestClass.class); assertNotNull(method); assertTrue((Boolean) method.invoke(testInstance, methodArgs)); Object[] polyMethodArgs = new Object[] { 1.0f, new ArrayList<String>(), new ArrayList<String>() }; Method polyMethod = dispatcher.getConformingMethod("polymorphic", polyMethodArgs, ConformingMethodTestClass.class); assertNotNull(polyMethod); assertTrue((Boolean) polyMethod.invoke(testInstance, polyMethodArgs)); Object[] erasedMethodArgs = new Object[] { new HashMap<String, Object>(), new ArrayList<String>() }; Method erasedMethod = dispatcher.getConformingMethod( "collectionsTypeErased", erasedMethodArgs, ConformingMethodTestClass.class); assertNotNull(erasedMethod); assertTrue((Boolean) erasedMethod .invoke(testInstance, erasedMethodArgs)); Object[] typedMethodArgs = new Object[] { new HashMap<String, Object>(), new ArrayList<String>() }; Method typedMethod = dispatcher.getConformingMethod( "collectionsWithTypes", typedMethodArgs, ConformingMethodTestClass.class); assertNotNull(typedMethod); assertTrue((Boolean) typedMethod.invoke(testInstance, typedMethodArgs)); Object[] nxTypedMethodArgs = new Object[] { new HashMap<Float, Object>(), new ArrayList<Float>() }; Method nxTypedMethod = dispatcher.getConformingMethod( "collectionsWithTypes", nxTypedMethodArgs, ConformingMethodTestClass.class); assertTrue((Boolean) nxTypedMethod.invoke(testInstance, nxTypedMethodArgs)); Method nxMethod = dispatcher.getConformingMethod("doesNotExist", new Object[] { new HashMap<String, Object>(), new ArrayList<String>() }, ConformingMethodTestClass.class); assertNull(nxMethod); }