From: Steve F. <sm...@us...> - 2003-04-16 22:48:02
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv3948/src/core/com/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment CallSequence.java CallBag.java Added Files: Tag: DynamicMockExperiment CallCollection.java Log Message: Factored out error reporting Index: CallSequence.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallSequence.java,v retrieving revision 1.4.2.5 retrieving revision 1.4.2.6 diff -u -r1.4.2.5 -r1.4.2.6 --- CallSequence.java 16 Apr 2003 22:14:46 -0000 1.4.2.5 +++ CallSequence.java 16 Apr 2003 22:47:58 -0000 1.4.2.6 @@ -8,52 +8,45 @@ import junit.framework.AssertionFailedError; -public class CallSequence implements Callable, CallableAddable { +public class CallSequence extends CallCollection implements Callable, CallableAddable { private ArrayList expectedCalls = new ArrayList(); int callIndex = 0; - public String getDescription() { - if (expectedCalls.isEmpty()) { - return "no methods"; - } else { - StringBuffer buf = new StringBuffer(); - - buf.append("in sequence:\n"); - - int j=0; - for (Iterator i = expectedCalls.iterator(); i.hasNext();) { - buf.append(((Callable)i.next()).getDescription()); - if (j++==(callIndex-1)) buf.append(" <<< NEXT EXPECTED CALL"); - buf.append("\n"); - } - - return buf.toString(); - } - } - - public CallSequence() { } public Object call(Mock mock, String methodName, Object[] args) throws Throwable { if (expectedCalls.size() == 0) throw new AssertionFailedError("no methods defined on mock, received: " + DynamicUtil.methodToString(methodName, args)); - if (callIndex == expectedCalls.size()) throw new AssertionFailedError("mock called too many times, recieved: " + DynamicUtil.methodToString(methodName, args)); + if (callIndex == expectedCalls.size()) throw new AssertionFailedError("mock called too many times, received: " + DynamicUtil.methodToString(methodName, args)); Callable nextCall = (Callable)expectedCalls.get(callIndex++); if (nextCall.matches(methodName, args)) return nextCall.call(mock, methodName, args); - StringBuffer buf = new StringBuffer(); - buf.append("Unexpected call to "); - buf.append(DynamicUtil.methodToString(methodName, args)); - buf.append("\n"); - buf.append("Expected "); - buf.append(getDescription()); - throw new AssertionFailedError(buf.toString()); + throw createUnexpectedCallError(methodName, args); } + public String getDescription() { + if (expectedCalls.isEmpty()) { + return "no methods"; + } else { + StringBuffer buf = new StringBuffer(); + + buf.append("in sequence:\n"); + + int j=0; + for (Iterator i = expectedCalls.iterator(); i.hasNext();) { + buf.append(((Callable)i.next()).getDescription()); + if (j++==(callIndex-1)) buf.append(" <<< Next Expected Call"); + buf.append("\n"); + } + + return buf.toString(); + } + } + public boolean matches(String methodName, Object[] args) { throw new AssertionFailedError("matches() operation not supported in CallSequence"); } Index: CallBag.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallBag.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- CallBag.java 16 Apr 2003 22:21:04 -0000 1.1.2.2 +++ CallBag.java 16 Apr 2003 22:47:58 -0000 1.1.2.3 @@ -7,13 +7,8 @@ import java.util.Iterator; import java.util.List; -import junit.framework.AssertionFailedError; - -/** - * @author dev - */ -public class CallBag implements Callable, CallableAddable { +public class CallBag extends CallCollection implements Callable, CallableAddable { private List expectedCalls = new ArrayList(); public CallBag() { @@ -29,16 +24,10 @@ } } - StringBuffer buf = new StringBuffer(); - buf.append("Unexpected call to "); - buf.append(DynamicUtil.methodToString(methodName, args)); - buf.append("\n"); - buf.append("Expected "); - buf.append(getDescription()); - throw new AssertionFailedError(buf.toString()); + throw createUnexpectedCallError(methodName, args); } - public String getDescription() { + public String getDescription() { if (expectedCalls.isEmpty()) { return "no methods"; } else { |