1 3 package org.jmock.cglib; 4 5 import java.lang.reflect.Method ; 6 import net.sf.cglib.proxy.Enhancer; 7 import net.sf.cglib.proxy.MethodInterceptor; 8 import net.sf.cglib.proxy.MethodProxy; 9 import org.jmock.core.AbstractDynamicMock; 10 import org.jmock.core.Invocation; 11 import org.jmock.core.InvocationDispatcher; 12 import org.jmock.core.LIFOInvocationDispatcher; 13 14 15 public class CGLIBCoreMock 16 extends AbstractDynamicMock 17 implements MethodInterceptor 18 { 19 private Object proxy; 20 21 public CGLIBCoreMock( Class mockedType ) { 22 this(mockedType, 23 mockNameFromClass(mockedType), 24 new LIFOInvocationDispatcher()); 25 } 26 27 public CGLIBCoreMock( Class mockedType, String name ) { 28 this(mockedType, name, new LIFOInvocationDispatcher()); 29 } 30 31 public CGLIBCoreMock( Class mockedType, 32 String name, 33 InvocationDispatcher invocationDispatcher ) { 34 super(mockedType, name, invocationDispatcher); 35 this.proxy = Enhancer.create(mockedType, this); 36 } 37 38 public Object proxy() { 39 return this.proxy; 40 } 41 42 public Object intercept( Object thisProxy, Method method, Object [] args, 43 MethodProxy superProxy ) 44 throws Throwable { 45 Invocation invocation = new Invocation(proxy, method, args); 46 return mockInvocation(invocation); 47 } 48 } 49 | Popular Tags |