Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30703/input/javasrc/biz/xsoftware/mock2/impl
Modified Files:
Tag: branchForOffice
MockObjectSuperImpl.java
Log Message:
implement exception handling. i am not so sure this implementation is the best one
Index: MockObjectSuperImpl.java
===================================================================
RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl/MockObjectSuperImpl.java,v
retrieving revision 1.3.2.8
retrieving revision 1.3.2.9
diff -C2 -d -r1.3.2.8 -r1.3.2.9
*** MockObjectSuperImpl.java 18 Feb 2006 08:09:16 -0000 1.3.2.8
--- MockObjectSuperImpl.java 22 Feb 2006 14:20:29 -0000 1.3.2.9
***************
*** 1,4 ****
--- 1,5 ----
package biz.xsoftware.mock2.impl;
+ import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedList;
***************
*** 12,17 ****
public abstract class MockObjectSuperImpl implements MockObject {
! // private static final Logger logger = Logger
! // .getLogger(MockObjectSuperImpl.class.getName());
private static final long DEFAULT_TIME_OUT = 10000;
--- 13,18 ----
public abstract class MockObjectSuperImpl implements MockObject {
! // private static final Logger logger = Logger
! // .getLogger(MockObjectSuperImpl.class.getName());
private static final long DEFAULT_TIME_OUT = 10000;
***************
*** 27,31 ****
* List of the methods been called ,and store them
*/
! Map retVal=new HashMap();
/**
* List of the methods that have been expected
--- 28,33 ----
* List of the methods been called ,and store them
*/
! private Map<String, Object> retVal = new HashMap<String, Object>();
!
/**
* List of the methods that have been expected
***************
*** 34,47 ****
/**
! * A map of queues, containing objects to return when methods are called
*/
! // private Map<String, List<Object>> methodToReturnVal = new HashMap<String, List<Object>>();
/**
! * A map of default return values, which are used to return if the queue for
! * the method is empty.
*/
! // private Map<String, Object> methodToDefaultRetVal = new HashMap<String, Object>();
!
public CalledMethod expect(String methodName, Class... vargs) {
return expect(methodName, DEFAULT_TIME_OUT, vargs);
--- 36,48 ----
/**
! * A map of methods which will throw exception
*/
! private Map<String, Throwable> methodWithException = new HashMap<String, Throwable>();
/**
! * a with the ignore method
*/
! // private Map<String, Object> methodToDefaultRetVal = new HashMap<String, Object>();
!
public CalledMethod expect(String methodName, Class... vargs) {
return expect(methodName, DEFAULT_TIME_OUT, vargs);
***************
*** 75,83 ****
public CalledMethod expect(Object returnValue, String methodName,
long timeout, Class... vargs) {
! if(methodName==null)
throw new IllegalArgumentException("method name can not be null");
! CalledMethod calledMethod=new CalledMethodImpl(methodName);
methodsExpected.add(calledMethod);
! retVal.put(methodName,returnValue);
return calledMethod;
}
--- 76,84 ----
public CalledMethod expect(Object returnValue, String methodName,
long timeout, Class... vargs) {
! if (methodName == null)
throw new IllegalArgumentException("method name can not be null");
! CalledMethod calledMethod = new CalledMethodImpl(methodName);
methodsExpected.add(calledMethod);
! retVal.put(methodName, returnValue);
return calledMethod;
}
***************
*** 85,90 ****
public CalledMethod expect(String methodName, Throwable throwable,
long timeout, Class... vargs) {
! // TODO Auto-generated method stub
! return null;
}
--- 86,95 ----
public CalledMethod expect(String methodName, Throwable throwable,
long timeout, Class... vargs) {
! if (methodName == null)
! throw new IllegalArgumentException("method name can not be null");
! CalledMethod calledMethod = new CalledMethodImpl(methodName);
! methodsExpected.add(calledMethod);
! methodWithException.put(methodName, throwable);
! return calledMethod;
}
***************
*** 94,118 ****
return null;
}
!
!
! public void verify() {
if (methodsCalled.size() == 0) {
! synchronized(this){
! try {
! this.wait(DEFAULT_TIME_OUT);
! } catch (InterruptedException e) {
! // TODO Auto-generated catch block
! e.printStackTrace();
! }
}
}
!
while (methodsCalled.size() != 0) {
CalledMethod calledMethod = methodsCalled.remove(0);
CalledMethodImpl m = (CalledMethodImpl) methodsExpected.remove(0);
m.setParameters(calledMethod.getParameters());
m.setStackTrace(calledMethod.getStackTrace());
!
}
--- 99,126 ----
return null;
}
!
! public void verify() throws Exception{
if (methodsCalled.size() == 0) {
! synchronized (this) {
!
! this.wait(DEFAULT_TIME_OUT);
!
}
}
!
while (methodsCalled.size() != 0) {
CalledMethod calledMethod = methodsCalled.remove(0);
CalledMethodImpl m = (CalledMethodImpl) methodsExpected.remove(0);
+
m.setParameters(calledMethod.getParameters());
m.setStackTrace(calledMethod.getStackTrace());
!
! if(methodWithException.containsKey(m.getMethodName())){
! Throwable t=methodWithException.get(m.getMethodName());
! throw (Exception)t;
! }
!
!
}
***************
*** 131,135 ****
public void setDefaultReturnValue(Object returnValue, String methodName,
Class... vargs) {
-
}
--- 139,142 ----
***************
*** 157,182 ****
String stackTrace = "method Called=" + methodName + "(" + params
+ "on object" + this + ")";
! // if(methodsExpected.size()!=0){
CalledMethod calledMethod = new CalledMethodImpl(methodName,
parameters, stackTrace);
!
methodsCalled.add(calledMethod);
- // }
-
return getReturnValue(methodName);
}
private Object getReturnValue(String methodName) {
! if(retVal.size()==0){
! String returnValue="No return value is set";
! setDefaultReturnValue(returnValue,methodName);
}
! if(retVal.containsKey(methodName)){
return retVal.get(methodName);
}
!
! return null;
!
}
--- 164,186 ----
String stackTrace = "method Called=" + methodName + "(" + params
+ "on object" + this + ")";
!
CalledMethod calledMethod = new CalledMethodImpl(methodName,
parameters, stackTrace);
!
methodsCalled.add(calledMethod);
return getReturnValue(methodName);
}
private Object getReturnValue(String methodName) {
! if (retVal.size() == 0) {
! String returnValue = "No return value is set";
! setDefaultReturnValue(returnValue, methodName);
}
! if (retVal.containsKey(methodName)) {
return retVal.get(methodName);
}
!
! return null;
}
|