Coverage Report - org.jbehave.core.model.ExamplesTableFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
ExamplesTableFactory
100%
21/21
100%
4/4
1.25
 
 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
 25  
  * in the ExamplesTable, i.e. invoking {@link ExamplesTable#getRowAsParameters(int)}, will need
 26  
  * to use a factory constructor providing explicitly the ParameterConverters instance
 27  
  * configured in the {@link Configuration#useParameterConverters(ParameterConverters)}.  
 28  
  * </p>
 29  
  */
 30  
 public class ExamplesTableFactory {
 31  
 
 32  
     private final Keywords keywords;
 33  
     private final ResourceLoader resourceLoader;
 34  
     private final ParameterConverters parameterConverters;
 35  
     private final TableTransformers tableTransformers;
 36  
 
 37  
     public ExamplesTableFactory() {
 38  670
         this(new LocalizedKeywords());
 39  670
     }
 40  
 
 41  
     public ExamplesTableFactory(Keywords keywords) {
 42  670
         this(keywords, new LoadFromClasspath(), new ParameterConverters(), new TableTransformers());
 43  670
     }
 44  
 
 45  
     public ExamplesTableFactory(ResourceLoader resourceLoader) {
 46  1
         this(new LocalizedKeywords(), resourceLoader, new ParameterConverters(), new TableTransformers());
 47  1
     }
 48  
 
 49  
     public ExamplesTableFactory(ParameterConverters parameterConverters) {
 50  1091
         this(new LocalizedKeywords(), new LoadFromClasspath(), parameterConverters, new TableTransformers());
 51  1091
     }
 52  
 
 53  
     public ExamplesTableFactory(TableTransformers tableTransformers) {
 54  2
         this(new LocalizedKeywords(), new LoadFromClasspath(), new ParameterConverters(), tableTransformers);
 55  2
     }
 56  
 
 57  
     public ExamplesTableFactory(Keywords keywords, ResourceLoader resourceLoader,
 58  1764
             ParameterConverters parameterConverters, TableTransformers tableTranformers) {
 59  1764
         this.keywords = keywords;
 60  1764
         this.resourceLoader = resourceLoader;
 61  1764
         this.parameterConverters = parameterConverters;
 62  1764
         this.tableTransformers = tableTranformers;
 63  1764
     }
 64  
 
 65  
     public ExamplesTable createExamplesTable(String input) {
 66  
         String tableAsString;
 67  139
         if (isBlank(input) || isTable(input)) {
 68  138
             tableAsString = input;
 69  
         } else {
 70  1
             tableAsString = resourceLoader.loadResourceAsText(input);
 71  
         }
 72  139
         return new ExamplesTable(tableAsString, keywords.examplesTableHeaderSeparator(),
 73  
                 keywords.examplesTableValueSeparator(), keywords.examplesTableIgnorableSeparator(), parameterConverters, tableTransformers);
 74  
     }
 75  
 
 76  
     protected boolean isTable(String input) {
 77  17
         return input.contains(keywords.examplesTableHeaderSeparator());
 78  
     }
 79  
 
 80  
 }