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

org.test4j.mock.Stubs Maven / Gradle / Ivy

package org.test4j.mock;

import org.test4j.mock.props.FakeProperties;
import org.test4j.mock.stub.Impostor;
import org.test4j.mock.stub.ProxyInvokable;

import java.lang.annotation.Annotation;

/**
 * 对类进行代理加强
 *
 * @author wudarui
 */
public class Stubs {
    private Stubs() {
    }

    /**
     * 创建stub对象, 并且调用定义好的Mock方法
     *
     * @param aClass
     * @param 
     * @return
     */
    public static  T fake(Class aClass) {
        return (T) Impostor.fake(aClass);
    }

    /**
     * 创建stub对象, 并且调用定义好的Mock方法
     *
     * @param aClass
     * @param args
     * @param 
     * @return
     */
    public static  T fake(Class aClass, Object... args) {
        return (T) Impostor.fake(aClass, args);
    }

    /**
     * @param invokable
     * @param baseType
     * @param interfaces
     * @param 
     * @return
     */
    public static  T proxy(ProxyInvokable invokable, Class baseType, Class... interfaces) {
        return Impostor.proxy(invokable, baseType, interfaces);
    }

    /**
     * 将对象空属性stub赋值
     *
     * @param target
     */
    public static  O nilFields(O target, Class... aClasses) {
        if (aClasses == null || aClasses.length == 0) {
            new FakeProperties(target).fakeNullProperties();
        } else {
            new FakeProperties(target).fakeNullByAnnotation(aClasses);
        }
        return target;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy