All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.oneeyedmen.okeydoke.internal.Fred Maven / Gradle / Ivy

There is a newer version: 2.0.3
Show newest version
package com.oneeyedmen.okeydoke.internal;

import org.jmock.api.Invocation;
import org.jmock.api.Invokable;
import org.jmock.lib.legacy.ClassImposteriser;

import java.lang.reflect.InvocationHandler;

public class Fred {

    private static final org.jmock.api.Imposteriser IMPOSTERISER = loadImposteriser();

    private static org.jmock.api.Imposteriser loadImposteriser() {
        try {
            return ClassImposteriser.INSTANCE;
        } catch (Throwable t) {
            throw new ExceptionInInitializerError("You need JMock and JMock-Legacy in your classpath to do this");
        }
    }

    public static  T newProxyInstance(Class type, final InvocationHandler handler)
    {
        Invokable invokable = new Invokable() {
            @Override
            public Object invoke(Invocation invocation) throws Throwable {
                return handler.invoke(null, invocation.getInvokedMethod(), invocation.getParametersAsArray());
            }
        };
        return IMPOSTERISER.imposterise(invokable, type);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy