|
1 |
| package com.agical.rmock.core.expectation.modification.impl; |
|
2 |
| |
|
3 |
| import com.agical.rmock.core.Action; |
|
4 |
| import com.agical.rmock.core.action.ForwardingAction; |
|
5 |
| import com.agical.rmock.core.action.ReturnAction; |
|
6 |
| import com.agical.rmock.core.action.ThrowsAction; |
|
7 |
| import com.agical.rmock.core.exception.IllegalModificationSystemException; |
|
8 |
| import com.agical.rmock.core.expectation.modification.ActionModifier; |
|
9 |
| import com.agical.rmock.core.expectation.modification.ArgumentsModifier; |
|
10 |
| import com.agical.rmock.core.expectation.modification.ExpectationModifier; |
|
11 |
| import com.agical.rmock.core.expectation.modification.LastExpectationProvider; |
|
12 |
| import com.agical.rmock.core.expectation.modification.ModifiableExpectation; |
|
13 |
| import com.agical.rmock.core.match.Expression; |
|
14 |
| import com.agical.rmock.core.match.Multiplicity; |
|
15 |
| import com.agical.rmock.core.util.PrimitiveToObject; |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| public class ExpectationModifierImpl implements ExpectationModifier { |
|
24 |
| private LastExpectationProvider lastExpectationProvider = LastExpectationProvider.NULL; |
|
25 |
| |
|
26 |
| |
|
27 |
1372
| public void setLastExpectationProvider(
|
|
28 |
| LastExpectationProvider lastExpectationProvider) { |
|
29 |
1372
| this.lastExpectationProvider = lastExpectationProvider;
|
|
30 |
| } |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
88
| public ArgumentsModifier multiplicity(Multiplicity multiplicity) {
|
|
36 |
88
| lastExpectationProvider.getLastExpectation().setMultiplicity(multiplicity);
|
|
37 |
88
| return this;
|
|
38 |
| } |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
67
| public ActionModifier args(Expression arg1) {
|
|
44 |
67
| return this.args(new Expression[]{arg1});
|
|
45 |
| } |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
18
| public ActionModifier args(Expression arg1, Expression arg2) {
|
|
51 |
18
| return this.args(new Expression[]{arg1, arg2});
|
|
52 |
| } |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
2
| public ActionModifier args(Expression arg1, Expression arg2, Expression arg3) {
|
|
58 |
2
| return this.args(new Expression[]{arg1, arg2, arg3});
|
|
59 |
| } |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
| |
|
64 |
19
| public ActionModifier args(Expression arg1, Expression arg2, Expression arg3,
|
|
65 |
| Expression arg4) { |
|
66 |
19
| return this.args(new Expression[]{arg1, arg2, arg3, arg4});
|
|
67 |
| } |
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
| |
|
72 |
7
| public ActionModifier args(Expression arg1, Expression arg2, Expression arg3,
|
|
73 |
| Expression arg4, Expression arg5) { |
|
74 |
7
| return this.args(new Expression[]{arg1, arg2, arg3, arg4, arg5});
|
|
75 |
| } |
|
76 |
| |
|
77 |
| |
|
78 |
| |
|
79 |
| |
|
80 |
1
| public ActionModifier args(Expression arg1, Expression arg2, Expression arg3,
|
|
81 |
| Expression arg4, Expression arg5, Expression arg6) { |
|
82 |
1
| return this.args(new Expression[]{arg1, arg2, arg3, arg4, arg5, arg6});
|
|
83 |
| } |
|
84 |
| |
|
85 |
| |
|
86 |
| |
|
87 |
| |
|
88 |
116
| public ActionModifier args(Expression[] newArgs) {
|
|
89 |
116
| Expression[] oldArgs = lastExpectationProvider.getLastExpectation().getArguments();
|
|
90 |
116
| if (oldArgs.length < newArgs.length) {
|
|
91 |
1
| throw new IllegalModificationSystemException("Too many expected arguments received, the method takes "+
|
|
92 |
| oldArgs.length+ " argument(s), received "+newArgs.length+"!"); |
|
93 |
| } |
|
94 |
115
| for (int i = 0; i < newArgs.length; i++) {
|
|
95 |
236
| if (newArgs[i] != null) {
|
|
96 |
211
| oldArgs[i]=newArgs[i];
|
|
97 |
| } |
|
98 |
| } |
|
99 |
115
| return this;
|
|
100 |
| } |
|
101 |
| |
|
102 |
| |
|
103 |
| |
|
104 |
| |
|
105 |
290
| public void returnValue(Object o) {
|
|
106 |
290
| perform(new ReturnAction(o));
|
|
107 |
| } |
|
108 |
| |
|
109 |
| |
|
110 |
| |
|
111 |
| |
|
112 |
127
| public void returnValue(boolean result) {
|
|
113 |
127
| returnValue(PrimitiveToObject.convert(result));
|
|
114 |
| } |
|
115 |
| |
|
116 |
| |
|
117 |
| |
|
118 |
| |
|
119 |
1
| public void returnValue(byte result) {
|
|
120 |
1
| returnValue(PrimitiveToObject.convert(result));
|
|
121 |
| |
|
122 |
| } |
|
123 |
| |
|
124 |
| |
|
125 |
| |
|
126 |
| |
|
127 |
1
| public void returnValue(char result) {
|
|
128 |
1
| returnValue(PrimitiveToObject.convert(result));
|
|
129 |
| } |
|
130 |
| |
|
131 |
| |
|
132 |
| |
|
133 |
| |
|
134 |
1
| public void returnValue(short result) {
|
|
135 |
1
| returnValue(PrimitiveToObject.convert(result));
|
|
136 |
| } |
|
137 |
| |
|
138 |
| |
|
139 |
| |
|
140 |
| |
|
141 |
42
| public void returnValue(int result) {
|
|
142 |
42
| returnValue(PrimitiveToObject.convert(result));
|
|
143 |
| } |
|
144 |
| |
|
145 |
| |
|
146 |
| |
|
147 |
| |
|
148 |
1
| public void returnValue(long result) {
|
|
149 |
1
| returnValue(PrimitiveToObject.convert(result));
|
|
150 |
| |
|
151 |
| } |
|
152 |
| |
|
153 |
| |
|
154 |
| |
|
155 |
| |
|
156 |
1
| public void returnValue(float result) {
|
|
157 |
1
| returnValue(PrimitiveToObject.convert(result));
|
|
158 |
| } |
|
159 |
| |
|
160 |
| |
|
161 |
| |
|
162 |
| |
|
163 |
1
| public void returnValue(double result) {
|
|
164 |
1
| returnValue(PrimitiveToObject.convert(result));
|
|
165 |
| } |
|
166 |
| |
|
167 |
| |
|
168 |
| |
|
169 |
| |
|
170 |
12
| public void throwException(Throwable throwable) {
|
|
171 |
12
| perform( new ThrowsAction( throwable ) );
|
|
172 |
| } |
|
173 |
| |
|
174 |
326
| public void perform(Action action) {
|
|
175 |
326
| ModifiableExpectation lastExpectation = lastExpectationProvider.getLastExpectation();
|
|
176 |
326
| lastExpectation.setAction(action);
|
|
177 |
| |
|
178 |
| } |
|
179 |
| |
|
180 |
11
| public void forward() {
|
|
181 |
11
| perform(new ForwardingAction());
|
|
182 |
| } |
|
183 |
| |
|
184 |
| } |