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

org.test4j.integration.spring.faker.StubFactoryBean Maven / Gradle / Ivy

package org.test4j.integration.spring.faker;

import org.springframework.beans.factory.config.AbstractFactoryBean;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.lang.NonNull;

import static org.springframework.beans.factory.support.BeanDefinitionBuilder.rootBeanDefinition;

/**
 * 将Stub实例注入到spring容器中
 *
 * @author darui.wu
 */
@SuppressWarnings({"rawtypes"})
public class StubFactoryBean extends AbstractFactoryBean {
    private final Object stub;

    public StubFactoryBean(Object stub) {
        this.stub = stub;
    }

    @Override
    public Class getObjectType() {
        return stub.getClass();
    }

    @NonNull
    @Override
    protected Object createInstance() {
        return stub;
    }

    public static BeanDefinition definition(Object target) {
        BeanDefinitionBuilder builder = rootBeanDefinition(StubFactoryBean.class);
        builder.addConstructorArgValue(target);
        builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
        return builder.getBeanDefinition();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy