Update of /cvsroot/mocklib/mocklib3/input/javasrc/biz/xsoftware/impl/mock
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv20712/input/javasrc/biz/xsoftware/impl/mock
Modified Files:
MessageHelper.java MethodVerifier.java
Log Message:
test overloaded method and get exception messages working.
Index: MethodVerifier.java
===================================================================
RCS file: /cvsroot/mocklib/mocklib3/input/javasrc/biz/xsoftware/impl/mock/MethodVerifier.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** MethodVerifier.java 12 Sep 2006 02:20:59 -0000 1.1
--- MethodVerifier.java 14 Sep 2006 22:36:53 -0000 1.2
***************
*** 24,28 ****
}
! private static boolean paramsNotNeedMatch(Class c, Method method) {
Method[] classMethods = c.getMethods();
int matches = 0;
--- 24,37 ----
}
! /**
! * Returns true if their are no overloaded versions of the method expected in the Class.
! * ie. only one version of write exists. There is not a method write(byte[] b) and write(int i). If
! * there is an overloaded version, this returns false.
! *
! * @param c
! * @param method
! * @return
! */
! private static boolean noOverloadedVersionsExist(Class c, Method method) {
Method[] classMethods = c.getMethods();
int matches = 0;
***************
*** 46,53 ****
if(!isVerifyArgs)
return methods[i];
! else if(paramsNotNeedMatch(c, methods[i]))
return methods[i];
else if(paramsMatch(methods[i], argTypes))
! return methods[i];
}
--- 55,65 ----
if(!isVerifyArgs)
return methods[i];
! else if(noOverloadedVersionsExist(c, methods[i]))
return methods[i];
else if(paramsMatch(methods[i], argTypes))
! return methods[i];
! else {
! throwException(c, method);
! }
}
***************
*** 56,60 ****
}
! static Method getMethod(Class[] classes, boolean isVerifyArgs, String method, Class ... argTypes) {
if(method == null)
throw new IllegalArgumentException("method parameter cannot be null");
--- 68,88 ----
}
! /**
! * @param c
! * @param method
! */
! private static void throwException(Class c, String method)
! {
! String msg = "The following methods match the method expected:\n";
! for(Method m : c.getMethods()) {
! if(m.getName().equals(method))
! msg += MessageHelper.getMethodSignature(m, "")+"\n";
! }
! msg += "You need to clarify which method you would like to add the return value to by " +
! "specifying the Class arguments which are the type of overloaded method";
! throw new IllegalArgumentException(msg);
! }
!
! static Method getMethod(Class[] classes, boolean isVerifyArgs, String method, Class ... argTypes) {
if(method == null)
throw new IllegalArgumentException("method parameter cannot be null");
Index: MessageHelper.java
===================================================================
RCS file: /cvsroot/mocklib/mocklib3/input/javasrc/biz/xsoftware/impl/mock/MessageHelper.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** MessageHelper.java 12 Sep 2006 02:20:58 -0000 1.1
--- MessageHelper.java 14 Sep 2006 22:36:53 -0000 1.2
***************
*** 14,22 ****
public static String getMethodSignature(Method method, String postfix) {
! String methodSig = "public "+method.getReturnType()+" "+method.getName()+postfix+"(";
for(Class c : method.getParameterTypes()) {
methodSig += c.getName()+", ";
}
! return methodSig.substring(0, methodSig.length()-2)+")";
}
--- 14,29 ----
public static String getMethodSignature(Method method, String postfix) {
! String methodSig = "public "+method.getReturnType();
! methodSig += " "+method.getName();
! methodSig += postfix;
! methodSig += "(";
! boolean needChop = false;
for(Class c : method.getParameterTypes()) {
methodSig += c.getName()+", ";
+ needChop = true;
}
! if(needChop)
! return methodSig.substring(0, methodSig.length()-2)+")";
! return methodSig+")";
}
|