|
From: Steve F. <sm...@us...> - 2003-11-23 21:12:08
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic
In directory sc8-pr-cvs1:/tmp/cvs-serv20697/src/core/com/mockobjects/dynamic
Modified Files:
CoreMock.java InvocationMocker.java
Log Message:
Improved error reporting and toString()
Index: CoreMock.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CoreMock.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- CoreMock.java 18 Nov 2003 23:12:51 -0000 1.15
+++ CoreMock.java 23 Nov 2003 21:12:05 -0000 1.16
@@ -5,7 +5,6 @@
import junit.framework.AssertionFailedError;
-
public class CoreMock implements DynamicMock {
private InvocationDispatcher invocationDispatcher;
private Object proxy;
@@ -15,6 +14,7 @@
this.proxy = Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { mockedClass }, this);
this.name = name;
this.invocationDispatcher = invocationDispatcher;
+ add(new InvocationMocker("toString", C.args(), new ReturnStub(name)));
}
public Object proxy() {
Index: InvocationMocker.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/InvocationMocker.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- InvocationMocker.java 18 Nov 2003 23:12:51 -0000 1.9
+++ InvocationMocker.java 23 Nov 2003 21:12:05 -0000 1.10
@@ -7,6 +7,8 @@
import java.util.Iterator;
import java.util.List;
+import junit.framework.AssertionFailedError;
+
import com.mockobjects.dynamic.matchers.MethodNameMatcher;
public class InvocationMocker implements Invokable {
@@ -52,9 +54,15 @@
}
public void verify() {
- Iterator i = matchers.iterator();
- while( i.hasNext() ) {
- ((InvocationMatcher)i.next()).verify();
+ try {
+ Iterator i = matchers.iterator();
+ while (i.hasNext()) {
+ ((InvocationMatcher) i.next()).verify();
+ }
+ } catch (AssertionFailedError error) {
+ AssertionFailedError newError = new AssertionFailedError(error.getMessage() + " " + toString());
+ newError.fillInStackTrace();
+ throw newError;
}
}
@@ -68,11 +76,16 @@
}
public StringBuffer writeTo(StringBuffer buffer) {
+ buffer.append("(");
Iterator it = matchers.iterator();
while (it.hasNext()) {
((InvocationMatcher)it.next()).writeTo(buffer).append(", ");
}
stub.writeTo(buffer);
return buffer.append("\n");
+ }
+
+ public String toString() {
+ return writeTo(new StringBuffer()).toString();
}
}
|