Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9249/input/javasrc/biz/xsoftware/mock2/impl
Modified Files:
Tag: branchForOffice
CalledMethodImpl.java MockObjectSuperImpl.java
Log Message:
pass
Index: CalledMethodImpl.java
===================================================================
RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl/CalledMethodImpl.java,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -C2 -d -r1.1.2.3 -r1.1.2.4
*** CalledMethodImpl.java 5 Feb 2006 10:29:22 -0000 1.1.2.3
--- CalledMethodImpl.java 6 Feb 2006 16:02:54 -0000 1.1.2.4
***************
*** 31,34 ****
--- 31,38 ----
public Object[] getParameters() {
// TODO Auto-generated method stub
+ if(parameters==null)
+ {
+ throw new IllegalStateException();
+ }
return parameters;
}
***************
*** 38,41 ****
--- 42,57 ----
return stackTrace;
}
+
+ public void setMethodName(String methodName) {
+ this.methodName = methodName;
+ }
+
+ public void setParameters(Object[] parameters) {
+ this.parameters = parameters;
+ }
+
+ public void setStackTrace(String stackTrace) {
+ this.stackTrace = stackTrace;
+ }
Index: MockObjectSuperImpl.java
===================================================================
RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock2/impl/MockObjectSuperImpl.java,v
retrieving revision 1.3.2.5
retrieving revision 1.3.2.6
diff -C2 -d -r1.3.2.5 -r1.3.2.6
*** MockObjectSuperImpl.java 5 Feb 2006 10:30:03 -0000 1.3.2.5
--- MockObjectSuperImpl.java 6 Feb 2006 16:02:54 -0000 1.3.2.6
***************
*** 14,164 ****
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.
*/
private List<CalledMethod> methodsCalled = new LinkedList<CalledMethod>();
/**
* List of the methods been called ,and store them
*/
! // private List<CalledMethod> calledMethodsStore=new LinkedList<CalledMethod>();
/**
* List of the methods that have been expected
*/
! private List<CalledMethod> methodsExpected=new LinkedList<CalledMethod>();
/**
* 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);
! }
! public CalledMethod expect(Object returnValue, String methodName,
! Class... vargs) {
! return expect(returnValue, methodName, DEFAULT_TIME_OUT, vargs);
! }
! public CalledMethod expect(String methodName, Throwable throwable,
! Class... vargs) {
! return expect(methodName, throwable, DEFAULT_TIME_OUT, vargs);
! }
! public CalledMethod expect(String methodName, Behavior behavior,
! Class... params) {
! return expect(methodName, behavior, DEFAULT_TIME_OUT, params);
! }
! 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);
! return methodsExpected.get(Index++);
! }
! public CalledMethod expect(Object returnValue, String methodName,
! long timeout, Class... vargs) {
! // TODO Auto-generated method stub
! return null;
! }
! public CalledMethod expect(String methodName, Throwable throwable,
! long timeout, Class... vargs) {
! // TODO Auto-generated method stub
! return null;
! }
! public CalledMethod expect(String methodName, Behavior behavior,
! long timeout, Class... params) {
! // TODO Auto-generated method stub
! return null;
! }
!
!
! public void verify(){
! for(int i=0;i<methodsExpected.size();i++){
! if(methodsExpected.get(i).getMethodName()==methodsCalled.get(i).getMethodName()){
!
! methodsExpected.add(i,methodsCalled.get(i));
! methodsExpected.remove(i+1);
! //continue;
! }
! }
! }
! 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) {
! // TODO Auto-generated method stub
! }
! public Object instance() {
! // TODO Auto-generated method stub
! return null;
! }
! synchronized protected Object methodCalledImpl(String methodName,
! Object[] parameters) {
! methodName = methodName.intern();
! String params = "";
! if (parameters == null) {
! params = "no params";
! } else {
! Object[] array = (Object[]) parameters;
! for (int i = 0; i < array.length - 1; i++) {
! params += array[i] + ", ";
! }
! params += array[array.length - 1];
! }
!
! String stackTrace="method Called="+methodName+"("+params+"on object"+this+")";
! CalledMethod calledMethod=new CalledMethodImpl(methodName,parameters,stackTrace);
! methodsCalled.add(calledMethod);
! //calledMethodsStore.add(calledMethod);
!
! //this.notifyAll();
! return getReturnValue(methodName);
! }
!
! private Object getReturnValue(String methodName){
!
! List l=(List)methodToReturnVal.get(methodName);
! if(l != null) {
! Object retVal = l.remove(0);
! if(l.size()<= 0)
! methodToReturnVal.remove(methodName);
! return retVal;
! }
! //next line returns null if setDefaultReturnValue not called by test case...
! return methodToDefaultRetVal.get(methodName);
!
!
! }
}
--- 14,182 ----
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.
*/
private List<CalledMethod> methodsCalled = new LinkedList<CalledMethod>();
+
/**
* List of the methods been called ,and store them
*/
! // private List<CalledMethod> calledMethodsStore=new
! // LinkedList<CalledMethod>();
/**
* List of the methods that have been expected
*/
! private List<CalledMethod> methodsExpected = new LinkedList<CalledMethod>();
!
/**
* 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);
! }
! public CalledMethod expect(Object returnValue, String methodName,
! Class... vargs) {
! return expect(returnValue, methodName, DEFAULT_TIME_OUT, vargs);
! }
! public CalledMethod expect(String methodName, Throwable throwable,
! Class... vargs) {
! return expect(methodName, throwable, DEFAULT_TIME_OUT, vargs);
! }
! public CalledMethod expect(String methodName, Behavior behavior,
! Class... params) {
! return expect(methodName, behavior, DEFAULT_TIME_OUT, params);
! }
! 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);
! return calledMethod;
! }
! public CalledMethod expect(Object returnValue, String methodName,
! long timeout, Class... vargs) {
! // TODO Auto-generated method stub
! return null;
! }
! public CalledMethod expect(String methodName, Throwable throwable,
! long timeout, Class... vargs) {
! // TODO Auto-generated method stub
! return null;
! }
! public CalledMethod expect(String methodName, Behavior behavior,
! long timeout, Class... params) {
! // TODO Auto-generated method stub
! 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());
! }
! }
! 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) {
! // TODO Auto-generated method stub
! }
! public Object instance() {
! // TODO Auto-generated method stub
! return null;
! }
! synchronized protected Object methodCalledImpl(String methodName,
! Object[] parameters) {
! methodName = methodName.intern();
! String params = "";
! if (parameters == null) {
! params = "no params";
! } else {
! Object[] array = (Object[]) parameters;
! for (int i = 0; i < array.length - 1; i++) {
! params += array[i] + ", ";
! }
! params += array[array.length - 1];
! }
!
! 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) {
!
! List l = (List) methodToReturnVal.get(methodName);
! if (l != null) {
! Object retVal = l.remove(0);
! if (l.size() <= 0)
! methodToReturnVal.remove(methodName);
! return retVal;
! }
! // next line returns null if setDefaultReturnValue not called by test
! // case...
! return methodToDefaultRetVal.get(methodName);
!
! }
}
|