Clover coverage report - Maven Clover report
Coverage timestamp: Sun Mar 18 2007 17:42:32 CET
file stats: LOC: 94   Methods: 3
NCLOC: 55   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
InterfaceInvocationHandler.java 100% 100% 100% 100%
coverage
 1    package com.agical.rmock.extension.cglib;
 2   
 3    import java.lang.reflect.Method;
 4   
 5    import com.agical.rmock.core.InvocationHandler;
 6    import com.agical.rmock.core.MethodHandle;
 7    import com.agical.rmock.core.ProxyFactory;
 8    import com.agical.rmock.core.expectation.ExpectationsState;
 9    import com.agical.rmock.core.expectation.InvocationListener;
 10    import com.agical.rmock.core.util.InterfaceMethodHandle;
 11   
 12    /**
 13    * <em>(c) Agical AB 2005</em>
 14    * @author brolund
 15    *
 16   
 17    */
 18    class InterfaceInvocationHandler extends BaseInvocationHandler
 19    implements net.sf.cglib.proxy.InvocationHandler {
 20    /**
 21    *
 22    */
 23    private final InvocationHandler invocationHandler;
 24    private final String id;
 25    private final Class clazz;
 26    private final ProxyFactory proxyFactory;
 27    private Object proxy;
 28    private final InvocationListener invocationListener;
 29    private final ObjectReferenceRetriever objectReferenceRetriever;
 30    private final ExpectationsState expectationsState;
 31   
 32    /**
 33    * This class intercepts the calls to methods such as toString, hashCode and equals.
 34    * @param invocationHandler The invocation handler to pass invocations to
 35    * @param id The id of the mock
 36    * @param clazz The type to pass calls to
 37    * @param proxyFactory The ProxyFactory beeing forwarded to
 38    * @param invocationListener The invocationListener to pass invocations to
 39    */
 40  713 public InterfaceInvocationHandler(InvocationHandler invocationHandler,
 41    String id,
 42    Class clazz,
 43    ProxyFactory proxyFactory,
 44    InvocationListener invocationListener,
 45    ObjectReferenceRetriever objectReferenceRetriever,
 46    ExpectationsState expectationsState) {
 47  713 this.invocationHandler = invocationHandler;
 48  713 this.id = id;
 49  713 this.clazz = clazz;
 50  713 this.proxyFactory = proxyFactory;
 51  713 this.invocationListener = invocationListener;
 52  713 this.objectReferenceRetriever = objectReferenceRetriever;
 53  713 this.expectationsState = expectationsState;
 54    }
 55   
 56    /**
 57    * @see net.sf.cglib.proxy.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
 58    */
 59  1904 public Object invoke(Object target, Method method, Object[] arguments) throws Throwable {
 60  1904 String methodName = method.getName();
 61  1904 Class[] parameterTypes = method.getParameterTypes();
 62   
 63   
 64  1904 if (methodName.equals("toString") && parameterTypes.length == 0) {
 65  2 return id;
 66    }
 67   
 68  1902 if (methodName.equals("equals") && parameterTypes.length == 1 && parameterTypes[0].equals(Object.class)) {
 69  147 return (this.proxy == arguments[0]) ? Boolean.TRUE : Boolean.FALSE;
 70    }
 71   
 72  1755 if (methodName.equals("hashCode") && parameterTypes.length == 0) {
 73  235 return new Integer(0);
 74    }
 75   
 76    // Short-circuit for finalize method
 77  1520 if (methodName.equals("finalize") && arguments.length == 0) {
 78  34 return null;
 79    }
 80   
 81  1486 sendInvocationListenerEvent(target, arguments, method, invocationListener, objectReferenceRetriever, expectationsState);
 82   
 83  1486 MethodHandle methodHandle = new InterfaceMethodHandle(id, method.getName(), parameterTypes, method.getReturnType(), proxyFactory);
 84   
 85  1486 return invocationHandler.invocation(id, clazz, methodName, arguments, methodHandle);
 86    }
 87   
 88    /**
 89    * @param proxy The proxy to set.
 90    */
 91  712 public void setProxy(Object proxy) {
 92  712 this.proxy = proxy;
 93    }
 94    }