##### Coverage Report - org.jbehave.core.model.ExamplesTableFactory

Classes in this File | Line Coverage | Branch Coverage | Complexity
ExamplesTableFactory |
91% | 21/23
100% | 4/4
| 1.2222222222222223;1.222

1 |  |
     package org.jbehave.core.model;
2 |  |
3 |  |
     import org.jbehave.core.configuration.Configuration;
4 |  |
     import org.jbehave.core.configuration.Keywords;
5 |  |
     import org.jbehave.core.i18n.LocalizedKeywords;
6 |  |
     import org.jbehave.core.io.LoadFromClasspath;
7 |  |
     import org.jbehave.core.io.ResourceLoader;
8 |  |
     import org.jbehave.core.steps.ParameterConverters;
9 |  |
10 |  |
     import static org.apache.commons.lang.StringUtils.isBlank;
11 |  |
12 |  |
     /**
13 |  |
      * Factory that creates instances of ExamplesTable from different type of
14 |  |
      * inputs:
15 |  |
      * <ul>
16 |  |
      * <li>table text input, i.e. any input that contains a
17 |  |
      * {@link Keywords#examplesTableHeaderSeparator()}</li>
18 |  |
      * <li>resource path input, the table as text is loaded via the
19 |  |
      * {@link ResourceLoader} (defaulting to {@link LoadFromClasspath}).</li>
20 |  |
      * </ul>
21 |  |
      * Factory also supports optional specification of {@link ParameterConverters}
22 |  |
      * to allow the ExamplesTable to convert row values.
23 |  |
      * <p>
24 |  |
      * <b>NOTE</b>: Users needing parameter conversion in the ExamplesTable, i.e.
25 |  |
      * invoking {@link ExamplesTable#getRowAsParameters(int)}, will need to use a
26 |  |
      * factory constructor providing explicitly the ParameterConverters instance
27 |  |
      * configured in the
28 |  |
      * {@link Configuration#useParameterConverters(ParameterConverters)}.
29 |  |
      * </p>
30 |  |
      */
31 |  |
     public class ExamplesTableFactory {
32 |  |
33 |  |
         private final Keywords keywords;
34 |  |
         private final ResourceLoader resourceLoader;
35 |  |
         private final ParameterConverters parameterConverters;
36 |  |
         private final TableTransformers tableTransformers;
37 |  |
38 |  |
         public ExamplesTableFactory() {
39 | 698 |
             this(new LocalizedKeywords());
40 | 698 |
         }
41 |  |
42 |  |
         public ExamplesTableFactory(Keywords keywords) {
43 | 698 |
             this(keywords, new LoadFromClasspath(), new ParameterConverters(), new TableTransformers());
44 | 698 |
         }
45 |  |
46 |  |
         public ExamplesTableFactory(ResourceLoader resourceLoader) {
47 | 1 |
             this(new LocalizedKeywords(), resourceLoader, new ParameterConverters(), new TableTransformers());
48 | 1 |
         }
49 |  |
50 |  |
         public ExamplesTableFactory(ParameterConverters parameterConverters) {
51 | 1131 |
             this(new LocalizedKeywords(), new LoadFromClasspath(), parameterConverters, new TableTransformers());
52 | 1131 |
         }
53 |  |
54 |  |
         public ExamplesTableFactory(TableTransformers tableTransformers) {
55 | 2 |
             this(new LocalizedKeywords(), new LoadFromClasspath(), new ParameterConverters(), tableTransformers);
56 | 2 |
         }
57 |  |
58 |  |
         public ExamplesTableFactory(Keywords keywords, ResourceLoader resourceLoader,
59 |  |
                 ParameterConverters parameterConverters) {
60 | 0 |
             this(keywords, resourceLoader, parameterConverters, new TableTransformers());
61 | 0 |
         }
62 |  |
63 |  |
         public ExamplesTableFactory(Keywords keywords, ResourceLoader resourceLoader,
64 | 1832 |
                 ParameterConverters parameterConverters, TableTransformers tableTranformers) {
65 | 1832 |
             this.keywords = keywords;
66 | 1832 |
             this.resourceLoader = resourceLoader;
67 | 1832 |
             this.parameterConverters = parameterConverters;
68 | 1832 |
             this.tableTransformers = tableTranformers;
69 | 1832 |
         }
70 |  |
71 |  |
         public ExamplesTable createExamplesTable(String input) {
72 |  |
             String tableAsString;
73 | 142 |
             if (isBlank(input) || isTable(input)) {
74 | 141 |
                 tableAsString = input;
75 |  |
             } else {
76 | 1 |
                 tableAsString = resourceLoader.loadResourceAsText(input);
77 |  |
             }
78 | 142 |
             return new ExamplesTable(tableAsString, keywords.examplesTableHeaderSeparator(),
79 |  |
                     keywords.examplesTableValueSeparator(), keywords.examplesTableIgnorableSeparator(),
80 |  |
                     parameterConverters, tableTransformers);
81 |  |
         }
82 |  |
83 |  |
         protected boolean isTable(String input) {
84 | 18 |
             return input.contains(keywords.examplesTableHeaderSeparator());
85 |  |
         }
86 |  |
87 |  |
     }