/** * Resolve current method generic return type to a {@link GenericMetadataSupport}. * * @param method Method to resolve the return type. * @return {@link GenericMetadataSupport} representing this generic return type. */ public GenericMetadataSupport resolveGenericReturnType(Method method) { Type genericReturnType = method.getGenericReturnType(); // logger.log("Method '" + method.toGenericString() + "' has return type : " + // genericReturnType.getClass().getInterfaces()[0].getSimpleName() + " : " + genericReturnType); if (genericReturnType instanceof Class) { return new NotGenericReturnTypeSupport(genericReturnType); } if (genericReturnType instanceof ParameterizedType) { return new ParameterizedReturnType( this, method.getTypeParameters(), (ParameterizedType) method.getGenericReturnType()); } if (genericReturnType instanceof TypeVariable) { return new TypeVariableReturnType( this, method.getTypeParameters(), (TypeVariable) genericReturnType); } throw new MockitoException( "Ouch, it shouldn't happen, type '" + genericReturnType.getClass().getCanonicalName() + "' on method : '" + method.toGenericString() + "' is not supported : " + genericReturnType); }
static { try { Map<String, Method> orderedMethods = new TreeMap<String, Method>(); for (Method m : MBeanServerConnection.class.getDeclaredMethods()) { orderedMethods.put(m.toGenericString(), m); } Method[] methods = orderedMethods.values().toArray(new Method[orderedMethods.size()]); Map<String, Method> asynchMethods = new TreeMap<String, Method>(); for (Method asynchMethod : AsynchJMXResponseListener.class.getDeclaredMethods()) { asynchMethods.put(asynchMethod.getName(), asynchMethod); } Map<Method, Byte> m2k = new HashMap<Method, Byte>(methods.length); Map<Byte, Method> k2m = new HashMap<Byte, Method>(methods.length); Map<Byte, Method> k2am = new HashMap<Byte, Method>(methods.length); for (int i = 0; i < methods.length; i++) { m2k.put(methods[i], (byte) i); k2m.put((byte) i, methods[i]); Method asynchMethod = asynchMethods.get(methods[i].getName() + "Response"); if (asynchMethod == null) throw new RuntimeException( "Failed to find asynch handler for [" + methods[i].toGenericString() + "]", new Throwable()); k2am.put((byte) i, asynchMethod); } methodToKey = Collections.unmodifiableMap(m2k); keyToMethod = Collections.unmodifiableMap(k2m); keyToAsynchMethod = Collections.unmodifiableMap(k2am); } catch (Exception ex) { throw new RuntimeException(ex); } }