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

jasmine.mock.framework.context.MockRuntimeProvider Maven / Gradle / Ivy

There is a newer version: 1.3.8
Show newest version
package jasmine.mock.framework.context;

import jasmine.framework.context.RuntimeProvider;
import jasmine.framework.common.util.CheckUtil;

import java.util.Map;

/**
 * @author mh.z
 */
public class MockRuntimeProvider implements RuntimeProvider {
    private RuntimeProvider runtimeProvider;
    private Map objects;

    public MockRuntimeProvider(RuntimeProvider runtimeProvider,
                               Map objects) {
        this.runtimeProvider = runtimeProvider;
        this.objects = objects;
    }

    @Override
    public  T getByType(Class type) {
        CheckUtil.notNull(type, "type null");

        return getByName(type.getName());
    }

    @Override
    public  T getByType(Class type, boolean required) {
        CheckUtil.notNull(type, "type null");

        return getByName(type.getName(), required);
    }

    @Override
    public  T getByName(String name) {
        return getByName(name, true);
    }

    @Override
    public  T getByName(String name, boolean required) {
        Object object = objects.get(name);

        if (object == null) {
            if (runtimeProvider != null) {
                object = runtimeProvider.getByName(name, required);
            }
        }

        return (T) object;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy