Clover Coverage Report - EasyMock 3.0
Coverage timestamp: sam. mai 8 2010 14:37:27 CEST
../../../img/srcFileCovDistChart10.png 0% of files have more coverage
13   69   7   3,25
4   36   0,54   4
4     1,75  
1    
4,5% of code in this file is excluded from these metrics.
 
  ClassExtensionHelper       Line # 30 13 4,5% 7 0 100% 1.0
 
  (678)
 
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.internal;
18   
19    import java.lang.reflect.Proxy;
20   
21    import net.sf.cglib.proxy.Enhancer;
22    import net.sf.cglib.proxy.Factory;
23   
24    import org.easymock.ConstructorArgs;
25    import org.easymock.internal.ClassProxyFactory.MockMethodInterceptor;
26   
27    /**
28    * @author Henri Tremblay
29    */
 
30    public final class ClassExtensionHelper {
31   
32    private static final ThreadLocal<ConstructorArgs> currentConstructorArgs = new ThreadLocal<ConstructorArgs>();
33   
34    // ///CLOVER:OFF
 
35    toggle private ClassExtensionHelper() {
36    }
37   
38    // ///CLOVER:ON
39   
 
40  112 toggle public static void setCurrentConstructorArgs(final ConstructorArgs args) {
41  112 currentConstructorArgs.set(args);
42    }
43   
 
44  316 toggle public static ConstructorArgs getCurrentConstructorArgs() {
45  316 return currentConstructorArgs.get();
46    }
47   
 
48  386 toggle public static MockMethodInterceptor getInterceptor(final Object mock) {
49  386 final Factory factory = (Factory) mock;
50  386 return (MockMethodInterceptor) factory.getCallback(0);
51    }
52   
 
53  1286 toggle public static MocksControl getControl(final Object mock) {
54  1286 ObjectMethodsFilter handler;
55   
56  1286 try {
57  1286 if (Enhancer.isEnhanced(mock.getClass())) {
58  262 handler = (ObjectMethodsFilter) getInterceptor(mock).getHandler();
59  1024 } else if (Proxy.isProxyClass(mock.getClass())) {
60  1022 handler = (ObjectMethodsFilter) Proxy.getInvocationHandler(mock);
61    } else {
62  2 throw new IllegalArgumentException("Not a mock: " + mock.getClass().getName());
63    }
64  1280 return handler.getDelegate().getControl();
65    } catch (final ClassCastException e) {
66  4 throw new IllegalArgumentException("Not a mock: " + mock.getClass().getName());
67    }
68    }
69    }