|
1 |
| package com.agical.rmock.extension.junit; |
|
2 |
| |
|
3 |
| import junit.framework.TestCase; |
|
4 |
| |
|
5 |
| import com.agical.rmock.core.Assert; |
|
6 |
| import com.agical.rmock.core.Verifiable; |
|
7 |
| import com.agical.rmock.core.configuration.ConfiguratorImpl; |
|
8 |
| import com.agical.rmock.core.event.TestCaseListener; |
|
9 |
| import com.agical.rmock.core.exception.RMockAssertionFailedException; |
|
10 |
| import com.agical.rmock.core.exception.RMockExpectationException; |
|
11 |
| import com.agical.rmock.core.exception.RMockInternalError; |
|
12 |
| import com.agical.rmock.core.exception.StrategyTerminatingException; |
|
13 |
| import com.agical.rmock.core.expectation.Engine; |
|
14 |
| import com.agical.rmock.core.hub.Hub; |
|
15 |
| import com.agical.rmock.core.match.Expression; |
|
16 |
| import com.agical.rmock.core.match.constraint.ConstraintFactory; |
|
17 |
| import com.agical.rmock.core.strategy.StrategyRunner; |
|
18 |
| import com.agical.rmock.core.strategy.TestStep; |
|
19 |
| import com.agical.rmock.core.util.PrimitiveToObject; |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| public abstract class AbstractStrategyTestCase extends TestCase { |
|
50 |
| private TestFinder testFinder; |
|
51 |
| private TestCaseListener testCaseListener; |
|
52 |
| private StrategyRunner strategyRunner; |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| protected ConstraintFactory is = new ConstraintFactory(); |
|
59 |
| private Assert asserter; |
|
60 |
| private final Hub hub; |
|
61 |
| private Verifiable verifiable; |
|
62 |
| |
|
63 |
| |
|
64 |
1378
| public void setStrategyRunner(StrategyRunner strategyRunner) {
|
|
65 |
1378
| this.strategyRunner = strategyRunner;
|
|
66 |
| } |
|
67 |
| |
|
68 |
0
| public StrategyRunner getStrategyRunner() {
|
|
69 |
0
| return strategyRunner;
|
|
70 |
| } |
|
71 |
| |
|
72 |
| |
|
73 |
11
| public AbstractStrategyTestCase(String name) {
|
|
74 |
11
| this(name, ConfiguratorImpl.getInstance().getHub());
|
|
75 |
| } |
|
76 |
| |
|
77 |
| |
|
78 |
| |
|
79 |
| |
|
80 |
| |
|
81 |
| |
|
82 |
| |
|
83 |
1137
| public AbstractStrategyTestCase(String name, Hub hub) {
|
|
84 |
1137
| super(name);
|
|
85 |
1137
| this.hub = hub;
|
|
86 |
| } |
|
87 |
| |
|
88 |
| |
|
89 |
| |
|
90 |
| |
|
91 |
| |
|
92 |
| |
|
93 |
| protected abstract TestStep createStrategy(String test); |
|
94 |
| |
|
95 |
| |
|
96 |
| |
|
97 |
| |
|
98 |
557
| public void runBare() throws Throwable {
|
|
99 |
| |
|
100 |
557
| Hub hub = getHub();
|
|
101 |
557
| hub.beginScope();
|
|
102 |
557
| Engine engine = new Engine();
|
|
103 |
557
| hub.connect(engine);
|
|
104 |
557
| hub.connect(this);
|
|
105 |
557
| testCaseListener.beforeTestCase(this, getName());
|
|
106 |
557
| try {
|
|
107 |
557
| TestStep step = createStrategy(getName());
|
|
108 |
557
| if (step == null) {
|
|
109 |
1
| throw new RMockInternalError("The createStrategy(String) returned null!");
|
|
110 |
| } |
|
111 |
556
| try {
|
|
112 |
556
| strategyRunner.runStrategy(step);
|
|
113 |
| } catch( StrategyTerminatingException exception ) { |
|
114 |
| |
|
115 |
| } |
|
116 |
554
| verifiable.endVerify();
|
|
117 |
| } |
|
118 |
| catch( RMockExpectationException exception ) { |
|
119 |
0
| throw new ExtendedAssertionFailedError(exception);
|
|
120 |
| } |
|
121 |
| finally { |
|
122 |
557
| try {
|
|
123 |
557
| testCaseListener.afterTestCase();
|
|
124 |
| } |
|
125 |
| catch(Exception e) { |
|
126 |
0
| e.printStackTrace();
|
|
127 |
| } |
|
128 |
557
| hub.disconnect(engine);
|
|
129 |
557
| hub.endScope();
|
|
130 |
| } |
|
131 |
| } |
|
132 |
| |
|
133 |
3264
| public Hub getHub() {
|
|
134 |
3264
| return hub;
|
|
135 |
| } |
|
136 |
| |
|
137 |
| |
|
138 |
| |
|
139 |
| |
|
140 |
| |
|
141 |
| |
|
142 |
| |
|
143 |
564
| public void assertThat(Object actual, Expression expression) {
|
|
144 |
564
| try {
|
|
145 |
564
| asserter.assertThat(actual, expression);
|
|
146 |
| } |
|
147 |
| catch(RMockAssertionFailedException exception) { |
|
148 |
1
| throw new ExtendedAssertionFailedError(exception);
|
|
149 |
| } |
|
150 |
| |
|
151 |
| } |
|
152 |
| |
|
153 |
| |
|
154 |
| |
|
155 |
| |
|
156 |
162
| public void assertThat(boolean result, Expression constraint) {
|
|
157 |
162
| assertThat(PrimitiveToObject.convert(result), constraint);
|
|
158 |
| } |
|
159 |
| |
|
160 |
| |
|
161 |
| |
|
162 |
| |
|
163 |
3
| public void assertThat(byte result, Expression constraint) {
|
|
164 |
3
| assertThat(PrimitiveToObject.convert(result), constraint);
|
|
165 |
| |
|
166 |
| } |
|
167 |
| |
|
168 |
| |
|
169 |
| |
|
170 |
| |
|
171 |
3
| public void assertThat(char result, Expression constraint) {
|
|
172 |
3
| assertThat(PrimitiveToObject.convert(result), constraint);
|
|
173 |
| } |
|
174 |
| |
|
175 |
| |
|
176 |
| |
|
177 |
| |
|
178 |
3
| public void assertThat(short result, Expression constraint) {
|
|
179 |
3
| assertThat(PrimitiveToObject.convert(result), constraint);
|
|
180 |
| } |
|
181 |
| |
|
182 |
| |
|
183 |
| |
|
184 |
| |
|
185 |
54
| public void assertThat(int result, Expression constraint) {
|
|
186 |
54
| assertThat(PrimitiveToObject.convert(result), constraint);
|
|
187 |
| } |
|
188 |
| |
|
189 |
| |
|
190 |
| |
|
191 |
| |
|
192 |
3
| public void assertThat(long result, Expression constraint) {
|
|
193 |
3
| assertThat(PrimitiveToObject.convert(result), constraint);
|
|
194 |
| |
|
195 |
| } |
|
196 |
| |
|
197 |
| |
|
198 |
| |
|
199 |
| |
|
200 |
3
| public void assertThat(float result, Expression constraint) {
|
|
201 |
3
| assertThat(PrimitiveToObject.convert(result), constraint);
|
|
202 |
| } |
|
203 |
| |
|
204 |
| |
|
205 |
| |
|
206 |
| |
|
207 |
3
| public void assertThat(double result, Expression constraint) {
|
|
208 |
3
| assertThat(PrimitiveToObject.convert(result), constraint);
|
|
209 |
| } |
|
210 |
| |
|
211 |
| |
|
212 |
1397
| public void setAsserter(Assert asserter) {
|
|
213 |
1397
| this.asserter = asserter;
|
|
214 |
| } |
|
215 |
| |
|
216 |
2210
| public void setTestCaseListener(TestCaseListener testCaseListener) {
|
|
217 |
2210
| this.testCaseListener = testCaseListener;
|
|
218 |
| } |
|
219 |
| |
|
220 |
2212
| public void setVerifiable(Verifiable verifiable) {
|
|
221 |
2212
| this.verifiable = verifiable;
|
|
222 |
| } |
|
223 |
| |
|
224 |
417
| protected Verifiable getVerifiable() {
|
|
225 |
417
| return verifiable;
|
|
226 |
| } |
|
227 |
| } |