##### Coverage Report - org.jbehave.core.steps.weld.WeldStepsFactory

Classes in this File | Line Coverage | Branch Coverage | Complexity
WeldStepsFactory |
90% | 9/10
66% | 4/6
| 2.6666666666666665;2.667

1 |  |
     /**
2 |  |
      *
3 |  |
      */
4 |  |
     package org.jbehave.core.steps.weld;
5 |  |
6 |  |
     import java.util.ArrayList;
7 |  |
     import java.util.List;
8 |  |
9 |  |
     import javax.enterprise.inject.Any;
10 |  |
     import javax.enterprise.inject.Instance;
11 |  |
     import javax.inject.Inject;
12 |  |
     import javax.inject.Singleton;
13 |  |
14 |  |
     import org.jbehave.core.annotations.weld.WeldConfiguration;
15 |  |
     import org.jbehave.core.annotations.weld.WeldStep;
16 |  |
     import org.jbehave.core.configuration.Configuration;
17 |  |
     import org.jbehave.core.steps.AbstractStepsFactory;
18 |  |
     import org.jbehave.core.steps.InjectableStepsFactory;
19 |  |
20 |  |
     /**
21 |  |
      * An {@link InjectableStepsFactory} that uses a Weld {@link Inject} for the
22 |  |
      * composition and instantiation of all components that contain JBehave
23 |  |
      * annotated methods.
24 |  |
      *
25 |  |
      * @author Aaron Walker
26 |  |
      */
27 |  |
     @Singleton
28 |  |
     public class WeldStepsFactory extends AbstractStepsFactory {
29 |  |
30 |  |
         @Inject
31 |  |
         @Any
32 |  |
         @WeldStep
33 |  |
         private Instance<Object> instances;
34 |  |
35 |  |
         @Inject
36 |  |
         public WeldStepsFactory(@WeldConfiguration Configuration configuration) {
37 | 8 |
             super(configuration);
38 | 8 |
         }
39 |  |
40 |  |
         @Override
41 |  |
         protected List<Class<?>> stepsTypes() {
42 | 3 |
             List<Class<?>> types = new ArrayList<Class<?>>();
43 | 3 |
             for (Object o : instances) {
44 | 3 |
                 types.add(o.getClass());
45 |  |
             }
46 | 3 |
             return types;
47 |  |
         }
48 |  |
49 |  |
         public Object createInstanceOfType(Class<?> type) {
50 | 3 |
             for (Object o : instances) {
51 | 3 |
                 if ( type.equals(o.getClass())){
52 | 3 |
                     return o;
53 |  |
                 }
54 |  |
             }
55 | 0 |
             throw new StepsInstanceNotFound(type, this);
56 |  |
         }
57 |  |
58 |  |
     }