1
16
17 import org.as2lib.test.unit.AbstractAssertInfo;
18 import org.as2lib.app.exec.Executable;
19 import org.as2lib.util.StringUtil;
20 import org.as2lib.env.reflect.ClassInfo;
21
22
27 class org.as2lib.test.unit.info.AssertNotThrowsInfo extends AbstractAssertInfo {
28
29
30 private var type;
31
32
33 private var toCall:Executable;
34
35
36 private var args:Array;
37
38
39 private var exception;
40
41
42 private var exceptionThrown:Boolean = false;
43
44
52 public function AssertNotThrowsInfo(message:String, type, toCall:Executable, args:Array) {
53 super(message);
54 this.type = type;
55 this.toCall = toCall;
56 this.args = args;
57 }
58
59
64 public function execute(Void):Boolean {
65 try {
66 toCall.execute.apply(Object(toCall), args);
67 } catch(e) {
68 exception = e;
69 exceptionThrown = true;
70 if(type != null) {
71 return (e instanceof type);
72 } else {
73 return true;
74 }
75 }
76 return false;
77 }
78
79
84 private function getFailureMessage(Void):String {
85 var result:String = "assertNotThrows failed";
86 if(hasMessage()) {
87 result += " with message: "+message;
88 }
89 result += "!\n";
90 if(typeof type == "function") {
91 result += " - Expected exception:\n "+ClassInfo.forClass(type).getFullName();
92 } else if(type == null) {
93 result += " - No exception expected.";
94 } else {
95 result += " - Expected exception:\n "+type;
96 }
97 if(exceptionThrown) {
98 result += "\n - Thrown exception:\n"+StringUtil.addSpaceIndent(exception.toString(), 6);
99 } else {
100 result += "\n - No exception thrown.";
101 }
102 return result;
103 }
104
105
110 private function getSuccessMessage(Void):String {
111 var result:String = "assertNotThrows executed. ";
112
113 if(typeof type == "function") {
114 result += ClassInfo.forClass(type).getFullName();
115 } else {
116 result += type;
117 }
118
119 result += "was not thrown by calling "+toCall.toString()+".";
120
121 return result;
122 }
123 }