Update of /cvsroot/mocklib/mocklib3/input/javasrc/biz/xsoftware/impl/mock
In directory sc8-pr-cvs16:/tmp/cvs-serv20175/input/javasrc/biz/xsoftware/impl/mock
Modified Files:
MessageHelper.java MethodVerifier.java MockSuperclass.java
BehaviorInfo.java MockObjectImpl.java
MockObjectFactoryImpl.java
Log Message:
fix generics warnings and some other stuff.
Index: BehaviorInfo.java
===================================================================
RCS file: /cvsroot/mocklib/mocklib3/input/javasrc/biz/xsoftware/impl/mock/BehaviorInfo.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** BehaviorInfo.java 1 Oct 2006 04:02:00 -0000 1.3
--- BehaviorInfo.java 14 May 2007 18:31:28 -0000 1.4
***************
*** 12,17 ****
private Method clonerMethod;
! public BehaviorInfo(Behavior behavior) {
this.behavior = behavior;
}
--- 12,22 ----
private Method clonerMethod;
! public BehaviorInfo(Behavior behavior, Method method) {
! if(behavior == null)
! throw new IllegalArgumentException("behavior cannot be null");
! else if(method == null)
! throw new IllegalArgumentException("method should not be null");
this.behavior = behavior;
+ this.behaviorMethod = method;
}
***************
*** 30,37 ****
return (Object[])clonerMethod.invoke(behavior, args);
}
-
- public void setBehaviorMethod(Method behaviorMethod) {
- this.behaviorMethod = behaviorMethod;
- }
public void setClonerMethod(Method clonerMethod) {
--- 35,38 ----
Index: MockObjectFactoryImpl.java
===================================================================
RCS file: /cvsroot/mocklib/mocklib3/input/javasrc/biz/xsoftware/impl/mock/MockObjectFactoryImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** MockObjectFactoryImpl.java 12 Sep 2006 02:20:59 -0000 1.1
--- MockObjectFactoryImpl.java 14 May 2007 18:31:30 -0000 1.2
***************
*** 8,13 ****
public class MockObjectFactoryImpl extends MockObjectFactory {
! public MockObject createMockImpl(String id, Class[] interfaces) {
! Class[] interfacesPlusMock = new Class[interfaces.length+1];
interfacesPlusMock[0] = MockObject.class;
for(int i = 1; i < interfacesPlusMock.length; i++) {
--- 8,13 ----
public class MockObjectFactoryImpl extends MockObjectFactory {
! public MockObject createMockImpl(String id, Class<?>[] interfaces) {
! Class<?>[] interfacesPlusMock = new Class[interfaces.length+1];
interfacesPlusMock[0] = MockObject.class;
for(int i = 1; i < interfacesPlusMock.length; i++) {
Index: MockSuperclass.java
===================================================================
RCS file: /cvsroot/mocklib/mocklib3/input/javasrc/biz/xsoftware/impl/mock/MockSuperclass.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** MockSuperclass.java 14 May 2007 14:26:16 -0000 1.8
--- MockSuperclass.java 14 May 2007 18:31:27 -0000 1.9
***************
*** 124,131 ****
public void addIgnore(String method)
{
! addIgnore(method, new Class[] {});
}
! public void addIgnore(String method, Class ... argTypes)
{
ignoreImpl(method);
--- 124,131 ----
public void addIgnore(String method)
{
! addIgnore(method, new Class<?>[] {});
}
! public void addIgnore(String method, Class<?> ... argTypes)
{
ignoreImpl(method);
***************
*** 134,141 ****
public void removeIgnore(String method)
{
! removeIgnore(method, new Class[] {});
}
! public void removeIgnore(String method, Class ... argTypes)
{
removeIgnoreImpl(method);
--- 134,141 ----
public void removeIgnore(String method)
{
! removeIgnore(method, new Class<?>[] {});
}
! public void removeIgnore(String method, Class<?> ... argTypes)
{
removeIgnoreImpl(method);
***************
*** 519,538 ****
public void setDefaultBehavior(String method, Behavior b)
{
! setDefaultBehavior(method, b, new Class[] {});
}
! public void setDefaultBehavior(String method, Behavior b, Class... argTypes) {
checkMethod(method, argTypes);
if(b == null)
throw new IllegalArgumentException("behavior parameter cannot be null");
! methodToDefaultRetVal.put(method, new BehaviorInfo(b));
}
public void setDefaultReturnValue(String method, Object returnValue)
{
! setDefaultReturnValue(method, returnValue, new Class[] {});
}
! public void setDefaultReturnValue(String method, Object o, Class... argTypes) {
checkMethod(method, argTypes);
--- 519,541 ----
public void setDefaultBehavior(String method, Behavior b)
{
! setDefaultBehavior(method, b, new Class<?>[] {});
}
! public void setDefaultBehavior(String method, Behavior b, Class<?>... argTypes) {
checkMethod(method, argTypes);
if(b == null)
throw new IllegalArgumentException("behavior parameter cannot be null");
!
! BehaviorInfo action = createBehaviorInfo(method, b, argTypes);
!
! methodToDefaultRetVal.put(method, action);
}
public void setDefaultReturnValue(String method, Object returnValue)
{
! setDefaultReturnValue(method, returnValue, new Class<?>[] {});
}
! public void setDefaultReturnValue(String method, Object o, Class<?>... argTypes) {
checkMethod(method, argTypes);
***************
*** 545,560 ****
}
! public void addBehavior(String method, Behavior behavior, Class... argTypes) {
! if(behavior == null)
! throw new IllegalArgumentException("behavior parameter cannot be null");
! Method m = checkMethod(method, argTypes);
! BehaviorInfo action = new BehaviorInfo(behavior);
! addToActionList(action, method, argTypes);
!
//verify behavior has correct methods
! Class clazz = behavior.getClass();
try {
! Method behaviorMethod = clazz.getMethod(m.getName(), (Class[])m.getParameterTypes());
! action.setBehaviorMethod(behaviorMethod);
behaviorMethod.setAccessible(true);
} catch (SecurityException e) {
--- 548,561 ----
}
! private BehaviorInfo createBehaviorInfo(String method, Behavior behavior, Class<?>... argTypes) {
! BehaviorInfo action = null;
!
//verify behavior has correct methods
! Class<?> clazz = behavior.getClass();
!
! Method m = checkMethod(method, argTypes);
try {
! Method behaviorMethod = clazz.getMethod(m.getName(), (Class<?>[])m.getParameterTypes());
! action = new BehaviorInfo(behavior, behaviorMethod);
behaviorMethod.setAccessible(true);
} catch (SecurityException e) {
***************
*** 562,574 ****
"I can't reflect on it and call getClass on it's class object");
} catch (NoSuchMethodException e) {
! String methodSig = MessageHelper.getMethodSignature(m, "");
throw new IllegalArgumentException("You Behavior class is missing the method='"+methodSig);
! }
!
try {
if(!(behavior instanceof CloningBehavior))
! return;
! Method clonerMethod = clazz.getMethod(m.getName()+"Cloner", (Class[])m.getParameterTypes());
action.setClonerMethod(clonerMethod);
if(!Object[].class.isAssignableFrom(clonerMethod.getReturnType()))
--- 563,575 ----
"I can't reflect on it and call getClass on it's class object");
} catch (NoSuchMethodException e) {
! String methodSig = MessageHelper.getMethodSignature(null, m, "");
throw new IllegalArgumentException("You Behavior class is missing the method='"+methodSig);
! }
!
try {
if(!(behavior instanceof CloningBehavior))
! return action;
! Method clonerMethod = clazz.getMethod(m.getName()+"Cloner", (Class<?>[])m.getParameterTypes());
action.setClonerMethod(clonerMethod);
if(!Object[].class.isAssignableFrom(clonerMethod.getReturnType()))
***************
*** 579,585 ****
"I can't reflect on it and call getClass on it's class object");
} catch (NoSuchMethodException e) {
! String methodSig = MessageHelper.getMethodSignature(m, "Cloner");
throw new IllegalArgumentException("You Behavior class is missing the method='"+methodSig);
}
}
--- 580,596 ----
"I can't reflect on it and call getClass on it's class object");
} catch (NoSuchMethodException e) {
! String methodSig = MessageHelper.getMethodSignature("Object[]", m, "Cloner");
throw new IllegalArgumentException("You Behavior class is missing the method='"+methodSig);
}
+ return action;
+ }
+
+ public void addBehavior(String method, Behavior behavior, Class<?>... argTypes) {
+ if(behavior == null)
+ throw new IllegalArgumentException("behavior parameter cannot be null");
+
+ BehaviorInfo action = createBehaviorInfo(method, behavior, argTypes);
+
+ addToActionList(action, method, argTypes);
}
***************
*** 611,615 ****
}
! private void addToActionList(Action action, String method, Class... argTypes) {
List<Action> l = methodToReturnVal.get(method);
--- 622,626 ----
}
! private void addToActionList(Action action, String method, Class<?>... argTypes) {
List<Action> l = methodToReturnVal.get(method);
***************
*** 653,658 ****
}
! public Class[] getClasses() {
! return new Class[] {this.getClass()};
}
--- 664,669 ----
}
! public Class<?>[] getClasses() {
! return new Class<?>[] {this.getClass()};
}
***************
*** 667,671 ****
}
! private Method checkMethod(String method, Class[] argTypes) {
return MethodVerifier.getMethod(getClasses(), true, method, argTypes);
}
--- 678,682 ----
}
! private Method checkMethod(String method, Class<?>[] argTypes) {
return MethodVerifier.getMethod(getClasses(), true, method, argTypes);
}
Index: MethodVerifier.java
===================================================================
RCS file: /cvsroot/mocklib/mocklib3/input/javasrc/biz/xsoftware/impl/mock/MethodVerifier.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** MethodVerifier.java 15 Sep 2006 16:01:17 -0000 1.3
--- MethodVerifier.java 14 May 2007 18:31:26 -0000 1.4
***************
*** 15,54 ****
private MethodVerifier() {}
! private static boolean paramsMatch(Method method, Class[] argTypes) {
! Class<?>[] parameterTypes = method.getParameterTypes();
! if(parameterTypes.length != argTypes.length)
! return false;
!
! for(int i = 0; i < parameterTypes.length; i++) {
! if(!(parameterTypes[i].equals(argTypes[i])))
! return false;
! }
! return true;
! }
! /**
! * 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;
! for(Method m : classMethods) {
! if(m.getName().equals(method.getName()))
! matches++;
! }
!
! if(matches == 1)
! return true;
!
! return false;
! }
! static Method getMethod(Class[] classes, boolean isVerifyArgs, String method, Class ... argTypes) {
if(method == null)
throw new IllegalArgumentException("method parameter cannot be null");
--- 15,54 ----
private MethodVerifier() {}
! // private static boolean paramsMatch(Method method, Class<?>[] argTypes) {
! // Class<?>[] parameterTypes = method.getParameterTypes();
! // if(parameterTypes.length != argTypes.length)
! // return false;
! //
! // for(int i = 0; i < parameterTypes.length; i++) {
! // if(!(parameterTypes[i].equals(argTypes[i])))
! // return false;
! // }
! // return true;
! // }
! // /**
! // * 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;
! // for(Method m : classMethods) {
! // if(m.getName().equals(method.getName()))
! // matches++;
! // }
! //
! // if(matches == 1)
! // return true;
! //
! // return false;
! // }
! static Method getMethod(Class<?>[] classes, boolean isVerifyArgs, String method, Class<?> ... argTypes) {
if(method == null)
throw new IllegalArgumentException("method parameter cannot be null");
***************
*** 58,62 ****
return null;
else if(argTypes != null) {
! for(Class argType : argTypes) {
if(argType == null)
throw new IllegalArgumentException("No Class parameters can be null, yet one was null");
--- 58,62 ----
return null;
else if(argTypes != null) {
! for(Class<?> argType : argTypes) {
if(argType == null)
throw new IllegalArgumentException("No Class parameters can be null, yet one was null");
***************
*** 65,69 ****
List<Method> methods = new ArrayList<Method>();
! for(Class c : classes) {
if(log.isLoggable(Level.FINEST))
log.finest("adding methods for class="+c.getName());
--- 65,69 ----
List<Method> methods = new ArrayList<Method>();
! for(Class<?> c : classes) {
if(log.isLoggable(Level.FINEST))
log.finest("adding methods for class="+c.getName());
***************
*** 87,91 ****
String msg = "Too many methods match your method expected='"+method+"'. Methods found:\n";
for(Method m : matchingMethods) {
! msg += MessageHelper.getMethodSignature(m, "")+"\n";
}
msg += "You need to clarify which method you would like to add the return value to by " +
--- 87,91 ----
String msg = "Too many methods match your method expected='"+method+"'. Methods found:\n";
for(Method m : matchingMethods) {
! msg += MessageHelper.getMethodSignature(null, m, "")+"\n";
}
msg += "You need to clarify which method you would like to add the return value to by " +
***************
*** 100,104 ****
* @return
*/
! private static String getMethodSigString(String method, Class... argTypes)
{
String args = "";
--- 100,104 ----
* @return
*/
! private static String getMethodSigString(String method, Class<?> ... argTypes)
{
String args = "";
***************
*** 106,110 ****
int i = 0;
for(; i < argTypes.length-1; i++) {
! Class c = argTypes[i];
args += c.getName()+",";
}
--- 106,110 ----
int i = 0;
for(; i < argTypes.length-1; i++) {
! Class<?> c = argTypes[i];
args += c.getName()+",";
}
***************
*** 120,124 ****
* @return
*/
! private static String getClassNamesString(Class[] classes)
{
String classNames = "";
--- 120,124 ----
* @return
*/
! private static String getClassNamesString(Class<?>[] classes)
{
String classNames = "";
***************
*** 135,139 ****
* @return
*/
! private static List<Method> findMatchingMethods(List<Method> methods, String methodName, Class[] argTypes)
{
//find all methods with same name first
--- 135,139 ----
* @return
*/
! private static List<Method> findMatchingMethods(List<Method> methods, String methodName, Class<?>[] argTypes)
{
//find all methods with same name first
***************
*** 176,180 ****
* @return
*/
! private static boolean isArgTypesMatch(Class< ? >[] types, Class[] argTypes)
{
if(types.length != argTypes.length)
--- 176,180 ----
* @return
*/
! private static boolean isArgTypesMatch(Class< ? >[] types, Class<?>[] argTypes)
{
if(types.length != argTypes.length)
Index: MockObjectImpl.java
===================================================================
RCS file: /cvsroot/mocklib/mocklib3/input/javasrc/biz/xsoftware/impl/mock/MockObjectImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** MockObjectImpl.java 15 Sep 2006 21:22:56 -0000 1.2
--- MockObjectImpl.java 14 May 2007 18:31:28 -0000 1.3
***************
*** 19,28 ****
private static Set<Method> isMethodInSuper = new HashSet<Method>();
! private static Map<Type, Class> primitiveToClass = new HashMap<Type, Class>();
! private Class[] classes;
static {
//reflect and find all the methods of the superclass.
! Class c = MockObject.class;
Method[] m = c.getMethods();
for(int i = 0; i < m.length; i++) {
--- 19,28 ----
private static Set<Method> isMethodInSuper = new HashSet<Method>();
! private static Map<Type, Class<?>> primitiveToClass = new HashMap<Type, Class<?>>();
! private Class<?>[] classes;
static {
//reflect and find all the methods of the superclass.
! Class<?> c = MockObject.class;
Method[] m = c.getMethods();
for(int i = 0; i < m.length; i++) {
***************
*** 45,49 ****
}
! public MockObjectImpl(String id, Class[] interfaces) {
super(id);
this.classes = interfaces;
--- 45,49 ----
}
! public MockObjectImpl(String id, Class<?>[] interfaces) {
super(id);
this.classes = interfaces;
***************
*** 58,62 ****
Object o = methodCalledImpl(method.getName(), args);
! Class returnType = method.getReturnType();
if(returnType == null)
--- 58,62 ----
Object o = methodCalledImpl(method.getName(), args);
! Class<?> returnType = method.getReturnType();
if(returnType == null)
***************
*** 78,82 ****
} 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"
--- 78,82 ----
} 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"
***************
*** 102,106 ****
for(int ii = 0; ii < parameterTypes.length; ii++)
{
! Class arg = method.getParameterTypes()[ii];
methodArgs += arg.getName();
if(ii < parameterTypes.length -1)
--- 102,106 ----
for(int ii = 0; ii < parameterTypes.length; ii++)
{
! Class<?> arg = method.getParameterTypes()[ii];
methodArgs += arg.getName();
if(ii < parameterTypes.length -1)
***************
*** 184,188 ****
*/
@Override
! public Class[] getClasses() {
return classes;
}
--- 184,188 ----
*/
@Override
! public Class<?>[] getClasses() {
return classes;
}
Index: MessageHelper.java
===================================================================
RCS file: /cvsroot/mocklib/mocklib3/input/javasrc/biz/xsoftware/impl/mock/MessageHelper.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** MessageHelper.java 1 Oct 2006 03:18:44 -0000 1.3
--- MessageHelper.java 14 May 2007 18:31:21 -0000 1.4
***************
*** 13,23 ****
private MessageHelper() {}
! 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;
--- 13,27 ----
private MessageHelper() {}
! public static String getMethodSignature(String retVal, Method method, String postfix) {
! String methodSig = "public ";
! if(retVal == null)
! methodSig += method.getReturnType();
! else
! methodSig += retVal;
methodSig += " "+method.getName();
methodSig += postfix;
methodSig += "(";
boolean needChop = false;
! for(Class<?> c : method.getParameterTypes()) {
methodSig += c.getName()+", ";
needChop = true;
|