Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv6967/input/javasrc/biz/xsoftware/mock
Modified Files:
MockObjectImpl.java
Log Message:
fix mocklib and delete mocklib2
Index: MockObjectImpl.java
===================================================================
RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock/MockObjectImpl.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** MockObjectImpl.java 1 Sep 2006 16:31:43 -0000 1.10
--- MockObjectImpl.java 1 Sep 2006 17:07:24 -0000 1.11
***************
*** 10,14 ****
--- 10,17 ----
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+ import java.lang.reflect.Type;
+ import java.util.HashMap;
import java.util.HashSet;
+ import java.util.Map;
import java.util.Set;
***************
*** 20,25 ****
--- 23,31 ----
private static Set<Method> isMethodInSuper = new HashSet<Method>();
+ private static Map<Type, Class> primitiveToClass = new HashMap<Type, Class>();
private Class[] classes;
+ Class<?>[] primitiveTypes = {Integer.TYPE, Double.TYPE, Float.TYPE, Boolean.TYPE,
+ Character.TYPE, Byte.TYPE, Short.TYPE, Long.TYPE};
static {
//reflect and find all the methods of the superclass.
***************
*** 34,37 ****
--- 40,52 ----
isMethodInSuper.add(m[i]);
}
+
+ primitiveToClass.put(Integer.TYPE, Integer.class);
+ primitiveToClass.put(Double.TYPE, Double.class);
+ primitiveToClass.put(Float.TYPE, Float.class);
+ primitiveToClass.put(Boolean.TYPE, Boolean.class);
+ primitiveToClass.put(Character.TYPE, Character.class);
+ primitiveToClass.put(Byte.TYPE, Byte.class);
+ primitiveToClass.put(Short.TYPE, Short.class);
+ primitiveToClass.put(Long.TYPE, Long.class);
}
***************
*** 58,62 ****
//The return type is void
if(o != null)
! throw new IllegalArgumentException("You are trying to return something on a method that returns void. Method="+methodString+" value you tried to return="+o);
} else {
//Return type is not void...(could be primitive or Object)
--- 73,78 ----
//The return type is void
if(o != null)
! throw new IllegalArgumentException("You are trying to return something on a method that returns void.\n" +
! "Method="+methodString+" value you tried to return="+o);
} else {
//Return type is not void...(could be primitive or Object)
***************
*** 66,70 ****
throw new IllegalArgumentException("Must call addReturnValue and " +
"specify a non-null value as method="+methodString+" returns a primitive value");
! } else if(!returnType.isInstance(o))
throw new IllegalArgumentException("You specified an incorrect return type on method\n="+methodString+"\n"
+"You specified a return type of="+o.getClass()+" which needs to be or extend type="+returnType);
--- 82,92 ----
throw new IllegalArgumentException("Must call addReturnValue and " +
"specify a non-null value as method="+methodString+" returns a primitive value");
! } else if(returnType.isPrimitive()) {
! //TODO: this is not working correctly no matter what I do here.....
! Class primitiveClass = primitiveToClass.get(returnType);
! if(!primitiveClass.isInstance(o))
! throw new IllegalArgumentException("You specified an incorrect return type on method\n="+methodString+"\n"
! +"You specified a return type of="+o.getClass()+" which needs to be or extend type="+returnType);
! } else if(!returnType.isInstance(o)) //if not a primitive, make sure is assignable....
throw new IllegalArgumentException("You specified an incorrect return type on method\n="+methodString+"\n"
+"You specified a return type of="+o.getClass()+" which needs to be or extend type="+returnType);
***************
*** 73,76 ****
--- 95,99 ----
return o;
}
+
/**
* @param method
|