asunit4 4.2.1.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. data/Gemfile +5 -0
  2. data/MIT-LICENSE.txt +22 -0
  3. data/README.textile +6 -0
  4. data/air/AIR2Runner.mxml +22 -0
  5. data/air/AIR2RunnerDescriptor.xml +38 -0
  6. data/asunit4.gemspec +20 -0
  7. data/asunit4.rb +16 -0
  8. data/bin/AsUnit-4.1.pre.swc +0 -0
  9. data/bin/AsUnitRunner.swf +0 -0
  10. data/build.xml +46 -0
  11. data/lib/Reflection.swc +0 -0
  12. data/rakefile.rb +169 -0
  13. data/script/generate +21 -0
  14. data/src/asunit/asserts/assertEquals.as +5 -0
  15. data/src/asunit/asserts/assertEqualsArrays.as +5 -0
  16. data/src/asunit/asserts/assertEqualsArraysIgnoringOrder.as +5 -0
  17. data/src/asunit/asserts/assertEqualsFloat.as +5 -0
  18. data/src/asunit/asserts/assertFalse.as +5 -0
  19. data/src/asunit/asserts/assertNotNull.as +5 -0
  20. data/src/asunit/asserts/assertNotSame.as +5 -0
  21. data/src/asunit/asserts/assertNull.as +5 -0
  22. data/src/asunit/asserts/assertSame.as +5 -0
  23. data/src/asunit/asserts/assertThrows.as +5 -0
  24. data/src/asunit/asserts/assertTrue.as +5 -0
  25. data/src/asunit/asserts/fail.as +5 -0
  26. data/src/asunit/core/AsUnitCore.as +177 -0
  27. data/src/asunit/core/FlashBuilderCore.as +22 -0
  28. data/src/asunit/core/FlashDevelopCore.as +21 -0
  29. data/src/asunit/core/TextCore.as +54 -0
  30. data/src/asunit/errors/AbstractError.as +10 -0
  31. data/src/asunit/errors/AssertionFailedError.as +10 -0
  32. data/src/asunit/errors/ClassNotFoundError.as +11 -0
  33. data/src/asunit/errors/InstanceNotFoundError.as +10 -0
  34. data/src/asunit/errors/UnimplementedFeatureError.as +10 -0
  35. data/src/asunit/errors/UsageError.as +11 -0
  36. data/src/asunit/events/TimeoutCommandEvent.as +27 -0
  37. data/src/asunit/framework/Assert.as +408 -0
  38. data/src/asunit/framework/Async.as +138 -0
  39. data/src/asunit/framework/CallbackBridge.as +175 -0
  40. data/src/asunit/framework/Command.as +6 -0
  41. data/src/asunit/framework/ErrorEvent.as +20 -0
  42. data/src/asunit/framework/IAsync.as +21 -0
  43. data/src/asunit/framework/IResult.as +36 -0
  44. data/src/asunit/framework/IRunListener.as +11 -0
  45. data/src/asunit/framework/IRunner.as +15 -0
  46. data/src/asunit/framework/IRunnerFactory.as +9 -0
  47. data/src/asunit/framework/ITestFailure.as +32 -0
  48. data/src/asunit/framework/ITestListener.as +15 -0
  49. data/src/asunit/framework/ITestResult.as +21 -0
  50. data/src/asunit/framework/ITestSuccess.as +22 -0
  51. data/src/asunit/framework/ITestWarning.as +14 -0
  52. data/src/asunit/framework/InjectionDelegate.as +96 -0
  53. data/src/asunit/framework/LegacyTestIterator.as +40 -0
  54. data/src/asunit/framework/MessageBridge.as +24 -0
  55. data/src/asunit/framework/Method.as +80 -0
  56. data/src/asunit/framework/Result.as +181 -0
  57. data/src/asunit/framework/RunnerFactory.as +179 -0
  58. data/src/asunit/framework/SuiteIterator.as +71 -0
  59. data/src/asunit/framework/TestCase.as +106 -0
  60. data/src/asunit/framework/TestFailure.as +65 -0
  61. data/src/asunit/framework/TestIterator.as +282 -0
  62. data/src/asunit/framework/TestObserver.as +12 -0
  63. data/src/asunit/framework/TestSuccess.as +38 -0
  64. data/src/asunit/framework/TestWarning.as +40 -0
  65. data/src/asunit/framework/TimeoutCommand.as +103 -0
  66. data/src/asunit/printers/FlashBuilderPrinter.as +134 -0
  67. data/src/asunit/printers/FlashDevelopPrinter.as +81 -0
  68. data/src/asunit/printers/TextPrinter.as +324 -0
  69. data/src/asunit/runners/LegacyRunner.as +13 -0
  70. data/src/asunit/runners/SuiteRunner.as +125 -0
  71. data/src/asunit/runners/TestRunner.as +403 -0
  72. data/src/asunit/util/ArrayIterator.as +30 -0
  73. data/src/asunit/util/Iterator.as +10 -0
  74. data/test/AllTests.as +73 -0
  75. data/test/AsUnitRunner.as +15 -0
  76. data/test/Flex3Runner.mxml +24 -0
  77. data/test/Flex4Runner.mxml +27 -0
  78. data/test/asunit/core/AsUnitCoreTest.as +97 -0
  79. data/test/asunit/framework/AssertEqualsArraysIgnoringOrderTest.as +88 -0
  80. data/test/asunit/framework/AssertEqualsArraysTest.as +102 -0
  81. data/test/asunit/framework/AssertTest.as +184 -0
  82. data/test/asunit/framework/AssertThrowsTest.as +42 -0
  83. data/test/asunit/framework/AsyncMethodTest.as +69 -0
  84. data/test/asunit/framework/AsyncTest.as +104 -0
  85. data/test/asunit/framework/CallbackBridgeTest.as +73 -0
  86. data/test/asunit/framework/InjectionDelegateTest.as +79 -0
  87. data/test/asunit/framework/MockData.xml +8 -0
  88. data/test/asunit/framework/NestedSuiteIteratorTest.as +59 -0
  89. data/test/asunit/framework/ProceedOnEventTest.as +109 -0
  90. data/test/asunit/framework/ResultTest.as +92 -0
  91. data/test/asunit/framework/RunnerFactoryTest.as +54 -0
  92. data/test/asunit/framework/SuiteIteratorTest.as +67 -0
  93. data/test/asunit/framework/TestCaseMock.as +24 -0
  94. data/test/asunit/framework/TestIteratorIgnoredMethodTest.as +62 -0
  95. data/test/asunit/framework/TestIteratorMethodByNameTest.as +50 -0
  96. data/test/asunit/framework/TestIteratorMultiMethodTest.as +186 -0
  97. data/test/asunit/framework/TestIteratorOrderedTestMethodTest.as +57 -0
  98. data/test/asunit/framework/TestIteratorSingleMethodTest.as +56 -0
  99. data/test/asunit/framework/VisualTestCaseTest.as +43 -0
  100. data/test/asunit/framework/assertAssertionFailed.as +19 -0
  101. data/test/asunit/printers/TextPrinterTest.as +122 -0
  102. data/test/asunit/runners/LegacyRunnerTest.as +40 -0
  103. data/test/asunit/runners/SuiteRunnerTest.as +40 -0
  104. data/test/asunit/runners/TestRunnerAsyncMethodTest.as +107 -0
  105. data/test/asunit/runners/TestRunnerErrorMethodTest.as +56 -0
  106. data/test/asunit/runners/TestRunnerExpectsErrorTest.as +98 -0
  107. data/test/asunit/runners/TestRunnerIgnoredMethodTest.as +42 -0
  108. data/test/asunit/runners/TestRunnerTest.as +171 -0
  109. data/test/asunit/support/AnnotatedSubClass.as +18 -0
  110. data/test/asunit/support/AnnotatedSuperClass.as +15 -0
  111. data/test/asunit/support/CustomParameters.as +13 -0
  112. data/test/asunit/support/CustomTestRunner.as +22 -0
  113. data/test/asunit/support/DoubleFailSuite.as +8 -0
  114. data/test/asunit/support/DoubleNestedSuite.as +14 -0
  115. data/test/asunit/support/ErrorInMethod.as +11 -0
  116. data/test/asunit/support/FailAssertEquals.as +29 -0
  117. data/test/asunit/support/FailAssertTrue.as +28 -0
  118. data/test/asunit/support/FakeObserver.as +42 -0
  119. data/test/asunit/support/FakeRunner.as +32 -0
  120. data/test/asunit/support/IgnoredMethod.as +26 -0
  121. data/test/asunit/support/InjectTimeoutOnAsync.as +14 -0
  122. data/test/asunit/support/InjectionFailure.as +18 -0
  123. data/test/asunit/support/InjectionVerification.as +69 -0
  124. data/test/asunit/support/LegacyTestCase.as +38 -0
  125. data/test/asunit/support/MultiMethod.as +77 -0
  126. data/test/asunit/support/OrderedTestMethod.as +36 -0
  127. data/test/asunit/support/RunWithButNoType.as +14 -0
  128. data/test/asunit/support/RunWithSuiteButNoType.as +11 -0
  129. data/test/asunit/support/SingleErrorSuite.as +7 -0
  130. data/test/asunit/support/SingleSuccessSuite.as +7 -0
  131. data/test/asunit/support/SucceedAssertTrue.as +31 -0
  132. data/test/asunit/support/SuiteOfTwoSuites.as +8 -0
  133. data/test/asunit/support/SuiteWithCustomRunner.as +12 -0
  134. data/test/asunit/support/SuiteWithOneCustomChildSuite.as +10 -0
  135. data/test/asunit/support/TestForFakeRunner.as +14 -0
  136. data/test/asunit/util/ArrayIteratorTest.as +65 -0
  137. data/vendor/as3reflection/README +7 -0
  138. data/vendor/as3reflection/p2/reflect/Reflection.as +417 -0
  139. data/vendor/as3reflection/p2/reflect/ReflectionAccessor.as +14 -0
  140. data/vendor/as3reflection/p2/reflect/ReflectionBase.as +52 -0
  141. data/vendor/as3reflection/p2/reflect/ReflectionMember.as +16 -0
  142. data/vendor/as3reflection/p2/reflect/ReflectionMetaData.as +69 -0
  143. data/vendor/as3reflection/p2/reflect/ReflectionMethod.as +36 -0
  144. data/vendor/as3reflection/p2/reflect/ReflectionMethodParameter.as +19 -0
  145. data/vendor/as3reflection/p2/reflect/ReflectionVariable.as +15 -0
  146. data/vendor/as3reflection/p2/reflect/findFirst.as +14 -0
  147. data/vendor/generators/suite/USAGE +0 -0
  148. data/vendor/generators/suite/suite_generator.rb +17 -0
  149. data/vendor/generators/suite/templates/TestSuite.as +17 -0
  150. metadata +216 -0
@@ -0,0 +1,138 @@
1
+ package asunit.framework {
2
+
3
+ import asunit.framework.ErrorEvent;
4
+
5
+ import asunit.events.TimeoutCommandEvent;
6
+
7
+ import flash.events.Event;
8
+ import flash.events.EventDispatcher;
9
+ import flash.events.IEventDispatcher;
10
+
11
+ public class Async extends EventDispatcher implements IAsync {
12
+
13
+ public static var DEFAULT_TIMEOUT:uint = 50;
14
+
15
+ private var _timeout:int = DEFAULT_TIMEOUT;
16
+ protected var pending:Array;
17
+
18
+ /**
19
+ * Asynchronous handler class.
20
+ *
21
+ * This class give you the ability to create Asynchronous event handlers
22
+ * and pause test execution until those handlers are triggered.
23
+ *
24
+ * To take advantage of Asynchronous features, add a member variable
25
+ * to your test like:
26
+ *
27
+ * [Inject]
28
+ * public var async:IAsync;
29
+ *
30
+ * This public property will be injected with an IAsync instance
31
+ * before each test method.
32
+ *
33
+ * Within your test methods, you can add Async callbacks with:
34
+ *
35
+ * [Test]
36
+ * public function verifySomething():void {
37
+ * async.add(handler);
38
+ * }
39
+ *
40
+ * In the previous example, test execution will be halted until the
41
+ * +handler+ method is called.
42
+ *
43
+ * It's worth noting that AsUnit does not store any state related
44
+ * to the playback of your test harness in global variables.
45
+ *
46
+ */
47
+ public function Async() {
48
+ pending = [];
49
+ }
50
+
51
+ public function get hasPending():Boolean {
52
+ return pending.length > 0;
53
+ }
54
+
55
+ public function set timeout(timeout:int):void {
56
+ _timeout = timeout;
57
+ }
58
+
59
+ public function get timeout():int {
60
+ return _timeout;
61
+ }
62
+
63
+ /**
64
+ * Returns a new async handler that should be used as the observer of some
65
+ * presumably asynchronous event.
66
+ *
67
+ * You can optionally pass a function closure that you would like to have
68
+ * executed when the provided handler is called. If this closure includes
69
+ * assertions, they will display in the test result.
70
+ *
71
+ * You can also override the default timeout (50ms) with a new value for
72
+ * this particular handler.
73
+ *
74
+ * This method may be called any number of times in a given [Test], [BeforeClass],
75
+ * or [Before] method.
76
+ *
77
+ * Test execution will be paused until all async handlers have returned
78
+ * or timed out.
79
+ *
80
+ * One way to use this method, is to simply send it to an event that you
81
+ * expect to have dispatched within a given time.
82
+ *
83
+ * instance.addEventListener(Event.COMPLETE, addAsync());
84
+ *
85
+ * In this example, you will receive a timeout error if the COMPLETE
86
+ * event is not dispatched within 50ms.
87
+ *
88
+ */
89
+ public function add(handler:Function=null, duration:int=-1):Function {
90
+ if (duration == -1) duration = timeout;
91
+ handler ||= function(...args):* {};
92
+ var command:TimeoutCommand = new TimeoutCommand(null, handler, duration);
93
+ addPending(command);
94
+ return command.getCallback();
95
+ }
96
+
97
+ public function proceedOnEvent(target:IEventDispatcher, eventName:String, timeout:int=500, timeoutHandler:Function=null):void {
98
+ var asyncHandler:Function = add(null, timeout);
99
+ target.addEventListener(eventName, asyncHandler, false, 0, true);
100
+ }
101
+
102
+ public function cancelPending():void {
103
+ for (var i:uint = pending.length; i--; ) {
104
+ var command:TimeoutCommand = TimeoutCommand(pending.pop());
105
+ command.cancel();
106
+ command.removeEventListener(TimeoutCommandEvent.CALLED, onTestResult);
107
+ command.removeEventListener(TimeoutCommandEvent.TIMED_OUT, onTestResult);
108
+ }
109
+ }
110
+
111
+ // Partially opened for testing purposes.
112
+ public function getPending():Array {
113
+ // Clone to prevent changing by reference.
114
+ return pending.slice();
115
+ }
116
+
117
+ protected function addPending(command:TimeoutCommand):void {
118
+ pending.push(command);
119
+ command.addEventListener(TimeoutCommandEvent.CALLED, onTestResult);
120
+ command.addEventListener(TimeoutCommandEvent.TIMED_OUT, onTestResult);
121
+ command.addEventListener(ErrorEvent.ERROR, onTestResult);
122
+ dispatchEvent(new TimeoutCommandEvent(TimeoutCommandEvent.ADDED, command));
123
+ }
124
+
125
+ protected function onTestResult(e:Event):void {
126
+ var command:TimeoutCommand = TimeoutCommand(e.currentTarget);
127
+ command.removeEventListener(TimeoutCommandEvent.CALLED, onTestResult);
128
+ command.removeEventListener(TimeoutCommandEvent.TIMED_OUT, onTestResult);
129
+ removePending(command);
130
+ dispatchEvent(e);
131
+ }
132
+
133
+ protected function removePending(command:TimeoutCommand):void {
134
+ pending.splice(pending.indexOf(command), 1);
135
+ }
136
+ }
137
+ }
138
+
@@ -0,0 +1,175 @@
1
+ package asunit.framework {
2
+
3
+ public class CallbackBridge implements IResult {
4
+
5
+ private var listeners:Array;
6
+
7
+ [Inject]
8
+ public var model:Result;
9
+
10
+ public function CallbackBridge() {
11
+ initialize();
12
+ }
13
+
14
+ protected function initialize():void
15
+ {
16
+ listeners = [];
17
+ model = new Result();
18
+ }
19
+
20
+ public function get length():int {
21
+ return listeners.length;
22
+ }
23
+
24
+ public function onRunStarted():void {
25
+ model.onRunStarted();
26
+ listeners.forEach(function(listener:IRunListener, index:int, items:Array):void {
27
+ listener.onRunStarted();
28
+ });
29
+ }
30
+
31
+ public function onRunCompleted(result:IResult):void {
32
+ model.onRunCompleted(result);
33
+ listeners.forEach(function(listener:IRunListener, index:int, items:Array):void {
34
+ listener.onRunCompleted(result);
35
+ });
36
+ }
37
+
38
+ public function onTestStarted(test:Object):void {
39
+ model.onTestStarted(test);
40
+ listeners.forEach(function(listener:IRunListener, index:int, items:Array):void {
41
+ listener.onTestStarted(test);
42
+ });
43
+ }
44
+
45
+ public function onTestCompleted(test:Object):void {
46
+ model.onTestCompleted(test);
47
+ listeners.forEach(function(listener:IRunListener, index:int, items:Array):void {
48
+ listener.onTestCompleted(test);
49
+ });
50
+ }
51
+
52
+ public function onTestFailure(failure:ITestFailure):void {
53
+ model.onTestFailure(failure);
54
+ listeners.forEach(function(listener:IRunListener, index:int, items:Array):void {
55
+ listener.onTestFailure(failure);
56
+ });
57
+ }
58
+
59
+ public function onTestSuccess(success:ITestSuccess):void {
60
+ model.onTestSuccess(success);
61
+ listeners.forEach(function(listener:IRunListener, index:int, items:Array):void {
62
+ listener.onTestSuccess(success);
63
+ });
64
+ }
65
+
66
+ public function onTestIgnored(method:Method):void {
67
+ model.onTestIgnored(method);
68
+ listeners.forEach(function(listener:IRunListener, index:int, items:Array):void {
69
+ listener.onTestIgnored(method);
70
+ });
71
+ }
72
+
73
+ public function onWarning(warning:ITestWarning):void {
74
+ model.onWarning(warning);
75
+ listeners.forEach(function(listener:IRunListener, index:int, items:Array):void {
76
+ listener.onWarning(warning);
77
+ });
78
+ }
79
+
80
+ //---------------------------------------
81
+ // IResult Implementation
82
+ //---------------------------------------
83
+
84
+ public function get errors():Array
85
+ {
86
+ return model.errors;
87
+ }
88
+
89
+ public function get errorCount():uint
90
+ {
91
+ return model.errorCount;
92
+ }
93
+
94
+ public function get failures():Array
95
+ {
96
+ return model.failures;
97
+ }
98
+
99
+ public function get failureCount():uint
100
+ {
101
+ return model.failureCount;
102
+ }
103
+
104
+ public function get successes():Array
105
+ {
106
+ return model.successes;
107
+ }
108
+
109
+ public function get successCount():uint
110
+ {
111
+ return model.successCount;
112
+ }
113
+
114
+ public function get warnings():Array
115
+ {
116
+ return model.warnings;
117
+ }
118
+
119
+ public function get ignoredTests():Array
120
+ {
121
+ return model.ignoredTests;
122
+ }
123
+
124
+ public function get ignoredTestCount():uint
125
+ {
126
+ return model.ignoredTestCount;
127
+ }
128
+
129
+ public function get runCount():uint
130
+ {
131
+ return model.runCount;
132
+ }
133
+
134
+ public function get failureEncountered():Boolean
135
+ {
136
+ return model.failureEncountered;
137
+ }
138
+
139
+ public function get wasSuccessful():Boolean
140
+ {
141
+ return model.wasSuccessful;
142
+ }
143
+
144
+ public function get runTime():Number
145
+ {
146
+ return model.runTime;
147
+ }
148
+
149
+ public function set runTime(value:Number):void
150
+ {
151
+ model.runTime = value;
152
+ }
153
+
154
+ public function addListener(listener:IRunListener):void
155
+ {
156
+ model.addListener(listener);
157
+ listeners.push(listener);
158
+ }
159
+
160
+ public function removeListener(listener:IRunListener):void
161
+ {
162
+ model.removeListener(listener);
163
+ }
164
+
165
+ public function addObserver(observer:TestObserver):void
166
+ {
167
+ model.addObserver(observer);
168
+ }
169
+
170
+ public function shouldRunTest(testClass:Class):Boolean
171
+ {
172
+ return model.shouldRunTest(testClass);
173
+ }
174
+ }
175
+ }
@@ -0,0 +1,6 @@
1
+ package asunit.framework {
2
+
3
+ public interface Command {
4
+ function execute():*;
5
+ }
6
+ }
@@ -0,0 +1,20 @@
1
+ package asunit.framework {
2
+
3
+ import flash.events.Event;
4
+
5
+ public class ErrorEvent extends Event {
6
+ public static const ERROR:String = 'error';
7
+ protected var _error:Error;
8
+
9
+ public function ErrorEvent(type:String, error:Error) {
10
+ super(type);
11
+ this._error = error;
12
+ }
13
+
14
+ override public function clone():Event {
15
+ return new ErrorEvent(type, _error);
16
+ }
17
+
18
+ public function get error():Error { return _error; }
19
+ }
20
+ }
@@ -0,0 +1,21 @@
1
+ package asunit.framework {
2
+
3
+ import flash.events.IEventDispatcher;
4
+
5
+ public interface IAsync extends IEventDispatcher {
6
+
7
+ function set timeout(timeout:int):void;
8
+ function get timeout():int;
9
+
10
+ function add(handler:Function=null, duration:int=-1):Function;
11
+
12
+ function cancelPending():void;
13
+
14
+ function get hasPending():Boolean;
15
+
16
+ function getPending():Array;
17
+
18
+ function proceedOnEvent(target:IEventDispatcher, eventName:String, timeout:int = 500, timeoutHandler:Function = null):void;
19
+ }
20
+ }
21
+
@@ -0,0 +1,36 @@
1
+ package asunit.framework {
2
+
3
+ import asunit.framework.ITestFailure;
4
+
5
+ public interface IResult extends MessageBridge, IRunListener, ITestListener {
6
+
7
+ function addListener(listener:IRunListener):void;
8
+ function removeListener(listener:IRunListener):void;
9
+
10
+ function addObserver(observer:TestObserver):void;
11
+ function shouldRunTest(testClass:Class):Boolean;
12
+
13
+ function get errors():Array;
14
+ function get errorCount():uint;
15
+
16
+ function get failures():Array;
17
+ function get failureCount():uint;
18
+
19
+ function get successes():Array;
20
+ function get successCount():uint;
21
+
22
+ function get warnings():Array;
23
+
24
+ function get ignoredTests():Array;
25
+ function get ignoredTestCount():uint;
26
+
27
+ function get runCount():uint;
28
+
29
+ function get failureEncountered():Boolean;
30
+ function get wasSuccessful():Boolean;
31
+
32
+ function get runTime():Number;
33
+ function set runTime(value:Number):void;
34
+ }
35
+ }
36
+
@@ -0,0 +1,11 @@
1
+ package asunit.framework {
2
+
3
+ import asunit.framework.ITestFailure;
4
+ import asunit.framework.IResult;
5
+
6
+ public interface IRunListener extends ITestListener {
7
+ function onRunStarted():void;
8
+ function onRunCompleted(result:IResult):void;
9
+ }
10
+ }
11
+
@@ -0,0 +1,15 @@
1
+ package asunit.framework {
2
+
3
+ import flash.events.IEventDispatcher;
4
+ import flash.display.DisplayObjectContainer;
5
+
6
+ public interface IRunner extends IEventDispatcher {
7
+
8
+ function run(testOrSuite:Class, testMethodName:String=null, visualContext:DisplayObjectContainer=null):void;
9
+ function shouldRunTest(testClass:Class):Boolean;
10
+
11
+ function set factory(factory:IRunnerFactory):void;
12
+ function get factory():IRunnerFactory;
13
+ }
14
+ }
15
+
@@ -0,0 +1,9 @@
1
+ package asunit.framework {
2
+
3
+
4
+ public interface IRunnerFactory {
5
+ function get injector():InjectionDelegate;
6
+ function set injector(value:InjectionDelegate):void;
7
+ function runnerFor(testOrSuite:Class):IRunner;
8
+ }
9
+ }
@@ -0,0 +1,32 @@
1
+ package asunit.framework
2
+ {
3
+
4
+ /**
5
+ *
6
+ */
7
+ public interface ITestFailure {
8
+
9
+ function get failedFeature():String;
10
+
11
+ function get failedMethod():String;
12
+
13
+ /**
14
+ * Gets the failed test case.
15
+ */
16
+ function get failedTest():Object;
17
+
18
+ /**
19
+ * Gets the thrown exception.
20
+ */
21
+ function get thrownException():Error;
22
+
23
+ function get exceptionMessage():String;
24
+
25
+ function get isFailure():Boolean;
26
+
27
+ /**
28
+ * Returns a short description of the failure.
29
+ */
30
+ function toString():String;
31
+ }
32
+ }
@@ -0,0 +1,15 @@
1
+ package asunit.framework {
2
+
3
+ import asunit.framework.ITestFailure;
4
+ import asunit.framework.TestObserver;
5
+
6
+ public interface ITestListener extends TestObserver {
7
+ function onTestStarted(test:Object):void;
8
+ function onTestCompleted(test:Object):void;
9
+ function onTestFailure(failure:ITestFailure):void;
10
+ function onTestSuccess(success:ITestSuccess):void;
11
+ function onTestIgnored(method:Method):void;
12
+ function onWarning(warning:ITestWarning):void;
13
+ }
14
+ }
15
+
@@ -0,0 +1,21 @@
1
+ package asunit.framework {
2
+
3
+ public interface ITestResult {
4
+
5
+ function addFailure(failure:ITestFailure):void;
6
+
7
+ function get errors():Array;
8
+ function get errorCount():uint;
9
+
10
+ function get failures():Array;
11
+ function get failureCount():uint;
12
+
13
+ function get runCount():uint;
14
+ function set runCount(value:uint):void;
15
+
16
+ function get wasSuccessful():Boolean;
17
+
18
+ function addListener(listener:ITestListener):void;
19
+ function removeListener(listener:ITestListener):void;
20
+ }
21
+ }
@@ -0,0 +1,22 @@
1
+ package asunit.framework {
2
+
3
+ /**
4
+ *
5
+ */
6
+ public interface ITestSuccess {
7
+
8
+ /**
9
+ * Gets the test case.
10
+ */
11
+ function get test():Object;
12
+
13
+ function get method():String;
14
+
15
+ function get feature():String;
16
+
17
+ /**
18
+ * Returns a short description of the failure.
19
+ */
20
+ function toString():String;
21
+ }
22
+ }
@@ -0,0 +1,14 @@
1
+ package asunit.framework {
2
+
3
+ public interface ITestWarning {
4
+
5
+ function set message(message:String):void;
6
+ function get message():String;
7
+
8
+ function set method(method:Method):void;
9
+ function get method():Method;
10
+
11
+ function toString():String;
12
+ }
13
+ }
14
+
@@ -0,0 +1,96 @@
1
+ package asunit.framework {
2
+
3
+ import p2.reflect.ReflectionMetaData;
4
+ import p2.reflect.Reflection;
5
+
6
+ import flash.utils.Dictionary;
7
+ import asunit.errors.UsageError;
8
+ import p2.reflect.ReflectionVariable;
9
+ import p2.reflect.ReflectionMember;
10
+ import flash.utils.getDefinitionByName;
11
+
12
+ public class InjectionDelegate {
13
+ //---------------------------------------
14
+ // CLASS CONSTANTS
15
+ //---------------------------------------
16
+
17
+ public static const THROW_ERROR_ON_MISSING_INJECTION_POINT:Boolean = true;
18
+ public static const INJECT_ANNOTATION:String = "Inject";
19
+
20
+ private var entities:Dictionary;
21
+
22
+ public function InjectionDelegate()
23
+ {
24
+ entities = new Dictionary();
25
+ }
26
+
27
+ /**
28
+ * @param addict * an entity with at least one [Inject] annotation
29
+ */
30
+ public function updateInjectionPoints(addict:*, throwErrorOnMissingInjection:Boolean=false):void {
31
+ var reflection:Reflection = Reflection.create(addict);
32
+ var members:Array = reflection.getMembersByMetaData(INJECT_ANNOTATION);
33
+ var addictName:String = reflection.name
34
+ if (throwErrorOnMissingInjection)
35
+ {
36
+ validateMembers(members, addictName);
37
+ }
38
+ var reflectionVariable:ReflectionVariable;
39
+ var injectionPointFound:Boolean;
40
+ members.forEach(function(member:ReflectionMember, index:int, items:Array):void {
41
+ reflectionVariable = member as ReflectionVariable;
42
+ if (reflectionVariable)
43
+ {
44
+ updateInjectionPoint(addict, reflectionVariable);
45
+ injectionPointFound = true;
46
+ }
47
+ });
48
+
49
+ if (!injectionPointFound && throwErrorOnMissingInjection)
50
+ {
51
+ throw new UsageError("InjectionDelegate expected at least one [Inject] annotation on a variable or accessor on" + addictName);
52
+ }
53
+
54
+ }
55
+
56
+ /**
57
+ * For each inject annotation we call this method
58
+ * @private
59
+ * @return
60
+ */
61
+ private function updateInjectionPoint(addict:*, member:ReflectionVariable):void {
62
+ //FIXME: This actually could be a getter. If someone has their head up their booty.
63
+ var instance:* = getInstanceFromTypeName(member.type);
64
+ addict[member.name] = instance;
65
+ }
66
+
67
+ private function getInstanceFromTypeName(name:String):* {
68
+ var clazz:Class = getDefinitionByName(name) as Class;
69
+ return getOrCacheInstanceFromClass(clazz);
70
+ }
71
+
72
+ private function getOrCacheInstanceFromClass(clazz:Class):* {
73
+ if (!entities[clazz])
74
+ {
75
+ //FIXME: This will choke if given a class with constructor arguments!
76
+ entities[clazz] = new clazz();
77
+ updateInjectionPoints(entities[clazz]);
78
+ }
79
+
80
+ return entities[clazz];
81
+ }
82
+
83
+ /**
84
+ * @private
85
+ */
86
+ private function validateMembers(members:Array, name:String):void
87
+ {
88
+ if (!members || members.length == 0)
89
+ {
90
+ throw new UsageError("InjectionDelegate expects at least one [Inject] annotation on " + name);
91
+ }
92
+
93
+ }
94
+
95
+ }
96
+ }
@@ -0,0 +1,40 @@
1
+ package asunit.framework {
2
+
3
+ import p2.reflect.Reflection;
4
+ import p2.reflect.ReflectionMethod;
5
+
6
+ public class LegacyTestIterator extends TestIterator {
7
+
8
+ public function LegacyTestIterator(test:Object, testMethodName:String = "") {
9
+ super(test, testMethodName);
10
+ }
11
+
12
+ override protected function getTestMethods(test:Object):Array {
13
+ var annotatedMethods:Array = super.getTestMethods(test);
14
+ var namedMethods:Array = getTestMethodsByName(test);
15
+ return annotatedMethods.concat(namedMethods);
16
+ }
17
+
18
+ protected function getTestMethodsByName(instance:Object):Array {
19
+ var methods:Array = [];
20
+ var reflection:Reflection = Reflection.create(instance);
21
+ reflection.methods.forEach(function(methodReflection:ReflectionMethod, index:int, list:Array):void {
22
+ if(methodNameBeginsWithTest(methodReflection) && methodDoesNotHaveTestAnnotation(methodReflection)) {
23
+ methods.push( new Method(instance, methodReflection) );
24
+ }
25
+ });
26
+
27
+ methods.sortOn('name');
28
+ return methods;
29
+ }
30
+
31
+ protected function methodNameBeginsWithTest(method:ReflectionMethod):Boolean {
32
+ return (method.name.match(/^test/) != null);
33
+ }
34
+
35
+ protected function methodDoesNotHaveTestAnnotation(method:ReflectionMethod):Boolean {
36
+ return (method.getMetaDataByName('Test') == null);
37
+ }
38
+ }
39
+ }
40
+