Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13102/input/javasrc/biz/xsoftware/mock2/impl
Modified Files:
MockObjectImpl.java MockObjectFactoryImpl.java
MockObjectSuperImpl.java
Log Message:
changed and cleaned some code
Index: MockObjectImpl.java
===================================================================
RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl/MockObjectImpl.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** MockObjectImpl.java 19 Feb 2006 19:20:52 -0000 1.3
--- MockObjectImpl.java 21 Mar 2006 09:25:32 -0000 1.4
***************
*** 38,60 ****
public MockObjectImpl(Class interfaceToMock, Object realObject) {
! // TODO Auto-generated constructor stub
}
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
! // TODO Auto-generated method stub
if(isMethodInSuper.contains(method)){
return callSuperMethod(proxy,method,args);
}
-
Object o=methodCalledImpl(method.getName(),args);
-
- if(o == null) {
- Class c = method.getReturnType();
- if(!Object.class.isAssignableFrom(c) && !"void".equals(c.getName())) {
- throw new RuntimeException("Must call addReturnValue " +
- "and specify a non-null value as method="+method.getName()+" returns a primitive value");
- }
- }
return o;
--- 38,51 ----
public MockObjectImpl(Class interfaceToMock, Object realObject) {
! // what is the situation when needed to provide a realObject
}
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
!
if(isMethodInSuper.contains(method)){
return callSuperMethod(proxy,method,args);
}
Object o=methodCalledImpl(method.getName(),args);
return o;
Index: MockObjectFactoryImpl.java
===================================================================
RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl/MockObjectFactoryImpl.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** MockObjectFactoryImpl.java 16 Feb 2006 15:37:34 -0000 1.3
--- MockObjectFactoryImpl.java 21 Mar 2006 09:25:32 -0000 1.4
***************
*** 23,27 ****
public MockObject createMockImpl(Class interfaceToMock, Object realObject) {
! // TODO: Implement me!
Class[] interfacePlusMock = new Class[1];
interfacePlusMock[0] = MockObject.class;
--- 23,27 ----
public MockObject createMockImpl(Class interfaceToMock, Object realObject) {
!
Class[] interfacePlusMock = new Class[1];
interfacePlusMock[0] = MockObject.class;
Index: MockObjectSuperImpl.java
===================================================================
RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl/MockObjectSuperImpl.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** MockObjectSuperImpl.java 20 Mar 2006 15:01:20 -0000 1.8
--- MockObjectSuperImpl.java 21 Mar 2006 09:25:32 -0000 1.9
***************
*** 11,25 ****
import biz.xsoftware.mock2.CalledMethod;
import biz.xsoftware.mock2.MockObject;
!
public abstract class MockObjectSuperImpl implements MockObject {
! // private static final Logger logger = Logger
! // .getLogger(MockObjectSuperImpl.class.getName());
private static final long DEFAULT_TIME_OUT = 10000;
- // private static int Index=0;
-
/**
* List of the current methods that have been called.
--- 11,27 ----
import biz.xsoftware.mock2.CalledMethod;
import biz.xsoftware.mock2.MockObject;
+ import biz.xsoftware.mock2.Messages;
! /**
! *
! * @author huajie.zeng
! *
! */
public abstract class MockObjectSuperImpl implements MockObject {
!
private static final long DEFAULT_TIME_OUT = 10000;
/**
* List of the current methods that have been called.
***************
*** 75,79 ****
public CalledMethod expect(String methodName, long timeout, Class... vargs) {
if (methodName == null)
! throw new IllegalArgumentException("methd name can not be null");
CalledMethod calledMethod = new CalledMethodImpl(methodName);
methodsExpected.add(calledMethod);
--- 77,81 ----
public CalledMethod expect(String methodName, long timeout, Class... vargs) {
if (methodName == null)
! throw new IllegalArgumentException(Messages.METHOD_NAME_CANT_BE_NULL);
CalledMethod calledMethod = new CalledMethodImpl(methodName);
methodsExpected.add(calledMethod);
***************
*** 84,88 ****
long timeout, Class... vargs) {
if (methodName == null)
! throw new IllegalArgumentException("method name can not be null");
CalledMethod calledMethod = new CalledMethodImpl(methodName);
methodsExpected.add(calledMethod);
--- 86,90 ----
long timeout, Class... vargs) {
if (methodName == null)
! throw new IllegalArgumentException(Messages.METHOD_NAME_CANT_BE_NULL);
CalledMethod calledMethod = new CalledMethodImpl(methodName);
methodsExpected.add(calledMethod);
***************
*** 94,98 ****
long timeout, Class... vargs) {
if (methodName == null)
! throw new IllegalArgumentException("method name can not be null");
CalledMethod calledMethod = new CalledMethodImpl(methodName);
methodsExpected.add(calledMethod);
--- 96,100 ----
long timeout, Class... vargs) {
if (methodName == null)
! throw new IllegalArgumentException(Messages.METHOD_NAME_CANT_BE_NULL);
CalledMethod calledMethod = new CalledMethodImpl(methodName);
methodsExpected.add(calledMethod);
***************
*** 104,108 ****
long timeout, Class... params){
if(methodName==null)
! throw new IllegalArgumentException("method name can not be null");
CalledMethod calledMethod=new CalledMethodImpl(methodName);
methodsExpected.add(calledMethod);
--- 106,110 ----
long timeout, Class... params){
if(methodName==null)
! throw new IllegalArgumentException(Messages.METHOD_NAME_CANT_BE_NULL);
CalledMethod calledMethod=new CalledMethodImpl(methodName);
methodsExpected.add(calledMethod);
***************
*** 115,122 ****
methodList.add(method);
} catch (SecurityException e) {
! // TODO Auto-generated catch block
! e.printStackTrace();
} catch (NoSuchMethodException e) {
! throw new IllegalArgumentException("method:"+methodName+"is not defined in your Behvior Implemetation");
}
--- 117,123 ----
methodList.add(method);
} catch (SecurityException e) {
! throw new IllegalArgumentException(Messages.METHOD_CAN_NOT_ACCESS);
} catch (NoSuchMethodException e) {
! throw new IllegalArgumentException(methodName+"is not defined in your Behvior Implemetation");
}
***************
*** 134,138 ****
this.wait(DEFAULT_TIME_OUT);
} catch (InterruptedException e) {
- // TODO Auto-generated catch block
e.getMessage();
}
--- 135,138 ----
***************
*** 151,174 ****
}
- public void addIgnoreMethod(String methodName, Class... vargs) {
- // TODO Auto-generated method stub
-
- }
-
- public void removeIgnoreMethod(String methodName, Class... vargs) {
- // TODO Auto-generated method stub
-
- }
-
- public void setDefaultReturnValue(Object returnValue, String methodName,
- Class... vargs) {
-
- }
-
- public Object instance() {
- // TODO Auto-generated method stub
- return null;
- }
-
protected Object methodCalledImpl(String methodName,
Object[] parameters) throws Throwable{
--- 151,154 ----
***************
*** 202,206 ****
Method m=methodList.get(i);
Behavior b=behaviorMap.get(calledMethod.getMethodName());
- // m.setAccessible(true);
Object retValue=m.invoke(b,calledMethod.getParameters());
retVal.put(methodName,retValue);
--- 182,185 ----
***************
*** 212,227 ****
private Object getReturnValue(String methodName) {
- if (retVal.size() == 0) {
- String returnValue = "No return value is set";
- // setDefaultReturnValue(returnValue, methodName);
-
- return returnValue;
- }
if (retVal.containsKey(methodName)) {
return retVal.get(methodName);
}
-
return null;
}
--- 191,218 ----
private Object getReturnValue(String methodName) {
if (retVal.containsKey(methodName)) {
return retVal.get(methodName);
}
return null;
+ }
+
+ public void addIgnoreMethod(String methodName, Class... vargs) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void removeIgnoreMethod(String methodName, Class... vargs) {
+ // TODO Auto-generated method stub
+
+ }
+ public void setDefaultReturnValue(Object returnValue, String methodName,
+ Class... vargs) {
+
+ }
+
+ public Object instance() {
+ // TODO Auto-generated method stub
+ return null;
}
|