|
1 |
| package com.agical.rmock.extension.junit; |
|
2 |
| |
|
3 |
| import java.lang.reflect.InvocationTargetException; |
|
4 |
| import java.lang.reflect.Method; |
|
5 |
| |
|
6 |
| import com.agical.rmock.core.strategy.TestStep; |
|
7 |
| import com.agical.rmock.core.strategy.impl.CompositeStep; |
|
8 |
| import com.agical.rmock.core.strategy.impl.MethodStep; |
|
9 |
| import com.agical.rmock.core.strategy.impl.ThreadedCompositeStep; |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| public class RMockThreadSupportingTestCase extends BasicJUnitStrategyTestCase { |
|
15 |
| |
|
16 |
10
| public RMockThreadSupportingTestCase(String testName) {
|
|
17 |
10
| super(testName);
|
|
18 |
| } |
|
19 |
| |
|
20 |
0
| public RMockThreadSupportingTestCase() {
|
|
21 |
0
| super();
|
|
22 |
| } |
|
23 |
| |
|
24 |
| |
|
25 |
| private class PriviledgedMethodStep extends MethodStep { |
|
26 |
13
| public PriviledgedMethodStep(Object target, String method) {
|
|
27 |
13
| super(target, method);
|
|
28 |
| } |
|
29 |
| |
|
30 |
11
| protected void invokeMethod(Object target, Method method) throws IllegalAccessException, InvocationTargetException {
|
|
31 |
11
| method.invoke(target, NO_ARGS);
|
|
32 |
| } |
|
33 |
| } |
|
34 |
| |
|
35 |
| private ThreadedCompositeStep threadedTestPreceedingSteps = new ThreadedCompositeStep(); |
|
36 |
| private ThreadedCompositeStep threadedTestConcurrentSteps = new ThreadedCompositeStep(); |
|
37 |
| |
|
38 |
7
| protected TestStep createTestStep(String test) {
|
|
39 |
7
| CompositeStep compositeStep = new CompositeStep();
|
|
40 |
7
| compositeStep.addStep( threadedTestPreceedingSteps );
|
|
41 |
7
| threadedTestConcurrentSteps.addStep( new MethodStep( this, test ) );
|
|
42 |
7
| compositeStep.addStep( threadedTestConcurrentSteps );
|
|
43 |
7
| return compositeStep;
|
|
44 |
| } |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
9
| public void addThreadedTestPreceedingStep(String methodToCall) {
|
|
52 |
9
| threadedTestPreceedingSteps.addStep( new PriviledgedMethodStep( this, methodToCall ) );
|
|
53 |
| } |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
4
| public void addThreadedTestConcurrentStep(String methodToCall) {
|
|
61 |
4
| threadedTestConcurrentSteps.addStep( new PriviledgedMethodStep( this, methodToCall ) );
|
|
62 |
| } |
|
63 |
| |
|
64 |
| |
|
65 |
| } |