| 1 | |
package org.jbehave.core.steps; |
| 2 | |
|
| 3 | |
import java.util.ArrayList; |
| 4 | |
import java.util.HashMap; |
| 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 | 178 | private final Map<Class<?>,Object> stepsInstances = new HashMap<Class<?>, Object>(); |
| 18 | |
|
| 19 | |
public InstanceStepsFactory(Configuration configuration, Object... stepsInstances) { |
| 20 | 168 | this(configuration, asList(stepsInstances)); |
| 21 | 168 | } |
| 22 | |
|
| 23 | |
public InstanceStepsFactory(Configuration configuration, List<Object> stepsInstances) { |
| 24 | 178 | super(configuration); |
| 25 | 178 | for (Object instance : stepsInstances) { |
| 26 | 175 | this.stepsInstances.put(instance.getClass(), instance); |
| 27 | |
} |
| 28 | 178 | } |
| 29 | |
|
| 30 | |
@Override |
| 31 | |
protected List<Class<?>> stepsTypes() { |
| 32 | 15 | return new ArrayList<Class<?>>(stepsInstances.keySet()); |
| 33 | |
} |
| 34 | |
|
| 35 | |
public Object createInstanceOfType(Class<?> type) { |
| 36 | 144 | Object instance = stepsInstances.get(type); |
| 37 | 144 | if ( instance == null ){ |
| 38 | 0 | throw new StepsInstanceNotFound(type, this); |
| 39 | |
} |
| 40 | 144 | return instance; |
| 41 | |
} |
| 42 | |
|
| 43 | |
} |