Clover coverage report - Maven Clover report
Coverage timestamp: Sun Mar 18 2007 17:42:32 CET
file stats: LOC: 98   Methods: 2
NCLOC: 61   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ObjectInterceptionInvocationHandler.java 100% 100% 100% 100%
coverage
 1    package com.agical.rmock.extension.cglib;
 2   
 3    import java.lang.reflect.Method;
 4    import java.util.HashSet;
 5    import java.util.Set;
 6   
 7    import net.sf.cglib.proxy.MethodInterceptor;
 8    import net.sf.cglib.proxy.MethodProxy;
 9   
 10    import com.agical.rmock.core.MethodHandle;
 11    import com.agical.rmock.core.ProxyFactory;
 12    import com.agical.rmock.core.expectation.ExpectationsState;
 13    import com.agical.rmock.core.expectation.InvocationListener;
 14    import com.agical.rmock.core.util.ForwardingMethodHandle;
 15    import com.agical.rmock.core.util.impl.MockMethodSignatureIdentity;
 16   
 17    /**
 18    * <em>(c) Agical AB 2005</em>
 19    * @author brolund
 20    *
 21   
 22    */
 23    public class ObjectInterceptionInvocationHandler extends BaseInvocationHandler
 24    implements MethodInterceptor {
 25   
 26    private final com.agical.rmock.core.InvocationHandler invocationHandler;
 27    private final String id;
 28    private final Class clazz;
 29    private final ProxyFactory proxyFactory;
 30    private Object proxy;
 31    private final ExpectationsState expectationsState;
 32    private Set invocations = new HashSet();
 33    private final InvocationListener invocationListener;
 34    private final ObjectReferenceRetriever objectReferenceFromStacktrace;
 35   
 36  69 public ObjectInterceptionInvocationHandler( com.agical.rmock.core.InvocationHandler invocationHandler,
 37    String id,
 38    Class clazz,
 39    ProxyFactory proxyFactory,
 40    ExpectationsState expectationsState,
 41    InvocationListener invocationListener,
 42    ObjectReferenceRetriever objectReferenceFromStacktrace) {
 43  69 this.invocationHandler = invocationHandler;
 44  69 this.id = id;
 45  69 this.clazz = clazz;
 46  69 this.proxyFactory = proxyFactory;
 47  69 this.expectationsState = expectationsState;
 48  69 this.invocationListener = invocationListener;
 49  69 this.objectReferenceFromStacktrace = objectReferenceFromStacktrace;
 50    }
 51   
 52  765 public Object intercept(Object proxy, Method method, Object[] parameters, MethodProxy methodProxy) throws Throwable {
 53   
 54  765 String methodName = method.getName();
 55  765 Class[] parameterTypes = method.getParameterTypes();
 56  765 MethodHandle methodHandle = new ForwardingMethodHandle(proxy, methodProxy, id, methodName, parameterTypes , method.getReturnType());
 57   
 58   
 59    // if (methodName.equals("toString") && parameterTypes.length == 0) {
 60    // return id;
 61    // }
 62    //
 63    // if (methodName.equals("equals") && parameterTypes.length == 1 && parameterTypes[0].equals(Object.class)) {
 64    // return (this.proxy == parameters[0]) ? Boolean.TRUE : Boolean.FALSE;
 65    // }
 66    //
 67    // if (methodName.equals("hashCode") && parameterTypes.length == 0) {
 68    // return new Integer(0);
 69    // }
 70   
 71    // Short-circuit for finalize method
 72  765 if (methodName.equals("finalize") && parameters.length == 0) {
 73  1 return methodHandle.invoke(parameters);
 74    }
 75   
 76  764 MockMethodSignatureIdentity setEntry = new MockMethodSignatureIdentity( id, methodName, parameterTypes );
 77   
 78  764 sendInvocationListenerEvent(proxy, parameters, method, invocationListener, objectReferenceFromStacktrace, expectationsState);
 79   
 80   
 81   
 82    // If this is verification and the method signature has not been setup, short-circuit the
 83    // invocation
 84  764 if( expectationsState.isInVerifyState() && !invocations.contains( setEntry ) ) {
 85  616 if ( methodProxy != null) {
 86  601 return methodHandle.invoke( parameters );
 87    }
 88    else {
 89  15 return null;
 90    }
 91    }
 92    else {
 93  148 invocations.add( setEntry );
 94  148 return invocationHandler.invocation( id, proxy.getClass(), methodName, parameters, methodHandle );
 95    }
 96    }
 97    }
 98