01: package net.sf.mockcreator.exceptions;
02:
03: import java.util.Iterator;
04: import java.util.List;
05: import java.util.Map;
06:
07: public class MockException extends Error {
08: private List expectations;
09:
10: public MockException(String msg) {
11: super (msg);
12: }
13:
14: public MockException(String msg, Throwable th) {
15: super (msg, th);
16: }
17:
18: public MockException(String message, List expectations) {
19: super (message);
20: this .expectations = expectations;
21: }
22:
23: public List getExpectations() {
24: return expectations;
25: }
26:
27: public String getMessage() {
28: String msg = "\n" + super .getMessage();
29:
30: if (expectations != null && expectations.size() > 0) {
31: msg += "\nwhile expected:\n";
32: Iterator it = expectations.iterator();
33:
34: while (it.hasNext()) {
35: Object o = it.next();
36:
37: if (o instanceof Map) {
38: Map map = (Map) o;
39: msg += " block{\n";
40:
41: Iterator bi = map.keySet().iterator();
42: while (bi.hasNext()) {
43: msg += (" " + bi.next() + "\n");
44: }
45:
46: msg += " }\n";
47: } else {
48: msg += (" " + o + "\n");
49: }
50: }
51: }
52:
53: return msg;
54: }
55: }
|