Clover Coverage Report - EasyMock 3.0
Coverage timestamp: sam. mai 8 2010 14:37:27 CEST
13   72   3   4,33
0   31   0,23   3
3     1  
1    
 
  CglibTest       Line # 34 13 0% 3 0 100% 1.0
 
  (3)
 
1    /**
2    * Copyright 2001-2010 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10    * Unless required by applicable law or agreed to in writing, software
11    * distributed under the License is distributed on an "AS IS" BASIS,
12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    * See the License for the specific language governing permissions and
14    * limitations under the License.
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    * This test case is used to make sure that the way cglib is used is providing
30    * the expected behavior
31    *
32    * @author Henri Tremblay
33    */
 
34    public class CglibTest extends TestCase {
35   
36    /**
37    * Check that an interceptor is used by only one instance of a class
38    *
39    * @throws Exception
40    */
 
41  2 toggle @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   
 
50  4 toggle private Factory createMock() throws Exception {
51  4 final MethodInterceptor interceptor = new MethodInterceptor() {
 
52  4 toggle 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    }