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 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
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 | 602 | this(new LocalizedKeywords()); |
40 | 602 | } |
41 | |
|
42 | |
public ExamplesTableFactory(Keywords keywords) { |
43 | 602 | this(keywords, new LoadFromClasspath(), new ParameterConverters(), new TableTransformers()); |
44 | 602 | } |
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 | 986 | this(new LocalizedKeywords(), new LoadFromClasspath(), parameterConverters, new TableTransformers()); |
52 | 986 | } |
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 | 1591 | ParameterConverters parameterConverters, TableTransformers tableTranformers) { |
65 | 1591 | this.keywords = keywords; |
66 | 1591 | this.resourceLoader = resourceLoader; |
67 | 1591 | this.parameterConverters = parameterConverters; |
68 | 1591 | this.tableTransformers = tableTranformers; |
69 | 1591 | } |
70 | |
|
71 | |
public ExamplesTable createExamplesTable(String input) { |
72 | |
String tableAsString; |
73 | 154 | if (isBlank(input) || isTable(input)) { |
74 | 153 | tableAsString = input; |
75 | |
} else { |
76 | 1 | tableAsString = resourceLoader.loadResourceAsText(input); |
77 | |
} |
78 | 154 | return new ExamplesTable(tableAsString, keywords.examplesTableHeaderSeparator(), |
79 | |
keywords.examplesTableValueSeparator(), keywords.examplesTableIgnorableSeparator(), |
80 | |
parameterConverters, tableTransformers); |
81 | |
} |
82 | |
|
83 | |
protected boolean isTable(String input) { |
84 | 23 | return input.contains(keywords.examplesTableHeaderSeparator()); |
85 | |
} |
86 | |
|
87 | |
} |