1
16
17 import org.as2lib.core.BasicClass;
18 import org.as2lib.env.except.IllegalStateException;
19 import org.as2lib.env.except.IllegalArgumentException;
20 import org.as2lib.test.mock.MockControlState;
21 import org.as2lib.test.mock.MethodBehavior;
22 import org.as2lib.test.mock.Behavior;
23 import org.as2lib.test.mock.MethodCallRange;
24 import org.as2lib.test.mock.MethodCall;
25 import org.as2lib.test.mock.MethodResponse;
26 import org.as2lib.test.mock.ArgumentsMatcher;
27
28
33 class org.as2lib.test.mock.support.ReplayState extends BasicClass implements MockControlState {
34
35
36 private var behavior:Behavior;
37
38
46 public function ReplayState(behavior:Behavior) {
47 if (!behavior) throw new IllegalArgumentException("Behavior is not allowed to be null or undefined.", this, arguments);
48 this.behavior = behavior;
49 }
50
51
56 public function getBehavior(Void):Behavior {
57 return behavior;
58 }
59
60
67 public function invokeMethod(methodCall:MethodCall) {
68 var methodBehavior:MethodBehavior = behavior.getMethodBehavior(methodCall);
69 if (methodBehavior) {
70 methodBehavior.addActualMethodCall(methodCall);
71 return methodBehavior.response();
72 } else {
73 methodBehavior = behavior.createMethodBehavior(null);
74 if (methodCall.getMethodName() && methodCall.getMethodName() != "") {
75 behavior.addMethodBehavior(methodCall.getMethodName(), methodBehavior);
76 } else {
77 behavior.addMethodBehavior("[unknown]", methodBehavior);
78 }
79 methodBehavior.addActualMethodCall(methodCall);
80 return methodBehavior.response();
81 }
82 }
83
84
87 public function verify(Void):Void {
88 behavior.verify();
89 }
90
91
94 public function setMethodResponse(methodResponse:MethodResponse, methodCallRange:MethodCallRange):Void {
95 throw new IllegalStateException("Method must not be called in replay state.", this, arguments);
96 }
97
98
101 public function setArgumentsMatcher(argumentsMatcher:ArgumentsMatcher):Void {
102 throw new IllegalStateException("Method must not be called in replay state.", this, arguments);
103 }
104
105 }