FilteredCGLIBProxyRealMethod.java revision 674060f01e9090cd21b3c5656cc3204912ad17a6
1/*
2 * Copyright (c) 2007 Mockito contributors
3 * This program is made available under the terms of the MIT License.
4 */
5package org.mockito.internal.invocation.realmethod;
6
7import org.mockito.internal.creation.MockitoMethodProxy;
8import org.mockito.internal.exceptions.stacktrace.ConditionalStackTraceFilter;
9
10import java.io.Serializable;
11
12public class FilteredCGLIBProxyRealMethod implements RealMethod, HasCGLIBMethodProxy, Serializable {
13
14    private static final long serialVersionUID = 3596550785818938496L;
15    private final RealMethod realMethod;
16
17    public FilteredCGLIBProxyRealMethod(MockitoMethodProxy methodProxy) {
18        this(new CGLIBProxyRealMethod(methodProxy));
19    }
20
21    public FilteredCGLIBProxyRealMethod(RealMethod realMethod) {
22        this.realMethod = realMethod;
23    }
24
25    public Object invoke(Object target, Object[] arguments) throws Throwable {
26        try {
27            return realMethod.invoke(target, arguments);
28        } catch (Throwable t) {
29            new ConditionalStackTraceFilter().filter(t);
30            throw t;
31        }
32    }
33
34    public MockitoMethodProxy getMethodProxy() {
35        return ((HasCGLIBMethodProxy) realMethod).getMethodProxy();
36    }
37}