1
16
17 import org.as2lib.core.BasicClass;
18 import org.as2lib.data.holder.array.TypedArray;
19 import org.as2lib.data.holder.Iterator;
20 import org.as2lib.data.holder.array.ArrayIterator;
21 import org.as2lib.env.reflect.MethodInfo;
22 import org.as2lib.util.StopWatch;
23 import org.as2lib.util.StringUtil;
24 import org.as2lib.test.unit.ExecutionInfo;
25
26
31 class org.as2lib.test.unit.TestCaseMethodInfo extends BasicClass {
32
33
34 private var methodInfo:MethodInfo;
35
36
37 private var stopWatch:StopWatch;
38
39
40 private var infos:TypedArray;
41
42
43 private var executed:Boolean = false;
44
45
50 public function TestCaseMethodInfo(methodInfo:MethodInfo) {
51 this.methodInfo = methodInfo;
52
53 stopWatch = new StopWatch();
54 infos = new TypedArray(ExecutionInfo);
55 }
56
57
62 public function getStopWatch(Void):StopWatch {
63 return stopWatch;
64 }
65
66
71 public function hasErrors(Void):Boolean {
72 var i:Number = infos.length;
73 while (--i-(-1)) {
74 if(infos[i].isFailed()) {
75 return true;
76 }
77 }
78 return false;
79 }
80
81
86 public function getOperationTime(Void):Number {
87 return getStopWatch().getTimeInMilliSeconds();
88 }
89
90
95 public function getMethodInfo(Void):MethodInfo {
96 return this.methodInfo;
97 }
98
99
104 public function addInfo(info:ExecutionInfo):Void {
105 infos.push(info);
106 }
107
108
114 public function getInfos(Void):TypedArray {
115 return infos.concat();
116 }
117
118
123 public function getErrors(Void):TypedArray {
124 var result:TypedArray = new TypedArray(ExecutionInfo);
125 var i:Number = 0;
126 var l:Number = infos.length;
127 while (i<l) {
128 if(infos[i].isFailed()) {
129 result.push(infos[i]);
130 }
131 i-=(-1);
132 }
133 return result;
134 }
135
136
139 public function isExecuted(Void):Boolean {
140 return executed;
141 }
142
143
148 public function setExecuted(executed:Boolean):Void {
149 this.executed = executed;
150 }
151
152
157 public function toString():String {
158 var result:String = getMethodInfo().getName()+"() ["+getStopWatch().getTimeInMilliSeconds()+"ms]";
159 var errors:Array = getErrors();
160 if(errors.length > 1) {
161 result += " "+errors.length+" errors occured";
162 } else if(errors.length > 0) {
163 result += " 1 error occured";
164
165 }
166 var errorIterator:Iterator = new ArrayIterator(errors);
167 while(errorIterator.hasNext()) {
168 var error = errorIterator.next();
169 result += "\n"+StringUtil.addSpaceIndent(error.getMessage(), 2);
170 }
171 if(hasErrors()) {
172 result += "\n";
173 }
174 return result;
175 }
176
177
182 public function getName(Void):String {
183 return methodInfo.getFullName();
184 }
185 }