1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.easymock.tests; |
18 |
|
|
19 |
|
import java.lang.reflect.Method; |
20 |
|
import java.util.ArrayList; |
21 |
|
|
22 |
|
import junit.framework.TestCase; |
23 |
|
import net.sf.cglib.proxy.*; |
24 |
|
|
25 |
|
import org.easymock.internal.ClassInstantiatorFactory; |
26 |
|
import org.junit.Test; |
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
@author |
33 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 3 |
Complexity Density: 0,23 |
|
34 |
|
public class CglibTest extends TestCase { |
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
@throws |
40 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
1
PASS
|
|
41 |
2
|
@Test... |
42 |
|
public void test() throws Exception { |
43 |
|
|
44 |
2
|
final Factory f1 = createMock(); |
45 |
2
|
final Factory f2 = createMock(); |
46 |
|
|
47 |
2
|
assertNotSame(f1.getCallback(0), f2.getCallback(0)); |
48 |
|
} |
49 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0,11 |
|
50 |
4
|
private Factory createMock() throws Exception {... |
51 |
4
|
final MethodInterceptor interceptor = new MethodInterceptor() { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
52 |
4
|
public Object intercept(final Object obj, final Method method, final Object[] args,... |
53 |
|
final MethodProxy proxy) throws Throwable { |
54 |
4
|
return proxy.invokeSuper(obj, args); |
55 |
|
} |
56 |
|
}; |
57 |
|
|
58 |
4
|
final Enhancer enhancer = new Enhancer(); |
59 |
4
|
enhancer.setSuperclass(ArrayList.class); |
60 |
4
|
enhancer.setCallbackType(MethodInterceptor.class); |
61 |
|
|
62 |
4
|
final Class<?> mockClass = enhancer.createClass(); |
63 |
|
|
64 |
4
|
Enhancer.registerCallbacks(mockClass, new Callback[] { interceptor }); |
65 |
|
|
66 |
4
|
final Factory f = (Factory) ClassInstantiatorFactory.getInstantiator().newInstance(mockClass); |
67 |
|
|
68 |
4
|
f.getCallback(0); |
69 |
|
|
70 |
4
|
return f; |
71 |
|
} |
72 |
|
} |