| 1 | |
package org.jbehave.core.steps; |
| 2 | |
|
| 3 | |
import java.util.ArrayList; |
| 4 | |
import java.util.LinkedHashMap; |
| 5 | |
import java.util.List; |
| 6 | |
import java.util.Map; |
| 7 | |
|
| 8 | |
import org.jbehave.core.configuration.Configuration; |
| 9 | |
|
| 10 | |
import static java.util.Arrays.asList; |
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
public class InstanceStepsFactory extends AbstractStepsFactory { |
| 16 | |
|
| 17 | 193 | private final Map<Class<?>,Object> stepsInstances = new LinkedHashMap<Class<?>, Object>(); |
| 18 | |
|
| 19 | |
public InstanceStepsFactory(Configuration configuration, Object... stepsInstances) { |
| 20 | 182 | this(configuration, asList(stepsInstances)); |
| 21 | 182 | } |
| 22 | |
|
| 23 | |
public InstanceStepsFactory(Configuration configuration, List<?> stepsInstances) { |
| 24 | 193 | super(configuration); |
| 25 | 193 | for (Object instance : stepsInstances) { |
| 26 | 191 | this.stepsInstances.put(instance.getClass(), instance); |
| 27 | 191 | } |
| 28 | 193 | } |
| 29 | |
|
| 30 | |
@Override |
| 31 | |
protected List<Class<?>> stepsTypes() { |
| 32 | 20 | return new ArrayList<Class<?>>(stepsInstances.keySet()); |
| 33 | |
} |
| 34 | |
|
| 35 | |
public Object createInstanceOfType(Class<?> type) { |
| 36 | 153 | Object instance = stepsInstances.get(type); |
| 37 | 153 | if ( instance == null ){ |
| 38 | 0 | throw new StepsInstanceNotFound(type, this); |
| 39 | |
} |
| 40 | 153 | return instance; |
| 41 | |
} |
| 42 | |
|
| 43 | |
} |