Package org.jbehave.core.steps

Source Code of org.jbehave.core.steps.ProvidedStepsFactory

package org.jbehave.core.steps;

import java.util.List;

import org.jbehave.core.steps.AbstractStepsFactory.StepsInstanceNotFound;

/**
* An {@link InjectableStepsFactory} that is provided with the
* {@link CandidateSteps} instances.
*/
public class ProvidedStepsFactory implements InjectableStepsFactory {

    private final List<CandidateSteps> candidateSteps;

    public ProvidedStepsFactory(List<CandidateSteps> candidateSteps) {
        this.candidateSteps = candidateSteps;
    }

    public List<CandidateSteps> createCandidateSteps() {
        return candidateSteps;
    }

    public Object createInstanceOfType(Class<?> type) {
        Object instance = null;
        for (CandidateSteps steps : candidateSteps) {
            try {
                if (type.equals(((Steps) steps).type())) {
                    instance = ((Steps) steps).instance();
                }
            } catch (RuntimeException e) {
                // creation failed on given factory, carry on
            }
        }
        if (instance == null) {
            throw new StepsInstanceNotFound(type, this);
        }
        return instance;
    }

}
TOP

Related Classes of org.jbehave.core.steps.ProvidedStepsFactory

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.