Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6177/input/javasrc/biz/xsoftware/mock2/impl
Modified Files:
MockObjectSuperImpl.java
Log Message:
changed implementation from branch and merged the second one to HEAD
Index: MockObjectSuperImpl.java
===================================================================
RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl/MockObjectSuperImpl.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** MockObjectSuperImpl.java 19 Feb 2006 19:20:52 -0000 1.6
--- MockObjectSuperImpl.java 23 Feb 2006 11:36:32 -0000 1.7
***************
*** 1,4 ****
--- 1,5 ----
package biz.xsoftware.mock2.impl;
+
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
*/
! private 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,125 ----
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.getMessage();
}
+
}
}
!
while (methodsCalled.size() != 0) {
CalledMethod calledMethod = methodsCalled.remove(0);
CalledMethodImpl m = (CalledMethodImpl) methodsExpected.remove(0);
+
m.setParameters(calledMethod.getParameters());
! m.setStackTrace(calledMethod.getStackTrace());
!
}
***************
*** 131,135 ****
public void setDefaultReturnValue(Object returnValue, String methodName,
Class... vargs) {
-
}
--- 138,141 ----
***************
*** 140,145 ****
}
! protected synchronized Object methodCalledImpl(String methodName,
! Object[] parameters) {
methodName = methodName.intern();
--- 146,151 ----
}
! protected Object methodCalledImpl(String methodName,
! Object[] parameters) throws Throwable{
methodName = methodName.intern();
***************
*** 157,167 ****
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);
--- 163,176 ----
String stackTrace = "method Called=" + methodName + "(" + params
+ "on object" + this + ")";
!
CalledMethod calledMethod = new CalledMethodImpl(methodName,
parameters, stackTrace);
methodsCalled.add(calledMethod);
!
! if(methodWithException.containsKey(calledMethod.getMethodName())){
! Throwable t=methodWithException.get(calledMethod.getMethodName());
! throw t;
! }
!
return getReturnValue(methodName);
***************
*** 169,182 ****
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;
!
}
--- 178,190 ----
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;
}
|