Coverage Report - org.jbehave.core.model.ExamplesTableFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
ExamplesTableFactory
86%
13/15
100%
4/4
1.333
 
 1  
 package org.jbehave.core.model;
 2  
 
 3  
 import org.jbehave.core.configuration.Keywords;
 4  
 import org.jbehave.core.i18n.LocalizedKeywords;
 5  
 import org.jbehave.core.io.LoadFromURL;
 6  
 import org.jbehave.core.io.ResourceLoader;
 7  
 
 8  
 import static org.apache.commons.lang.StringUtils.isBlank;
 9  
 
 10  
 
 11  
 /**
 12  
  * Factory that creates instances of ExamplesTable from different type of inputs:
 13  
  * <ul>
 14  
  * <li>table text input, i.e. any input that contains a {@link Keywords#examplesTableHeaderSeparator()}</li>
 15  
  * <li>resource path input, the table as text is loaded via the {@link ResourceLoader}.</li>
 16  
  * </ul>
 17  
  */
 18  
 public class ExamplesTableFactory {
 19  
 
 20  
     private final Keywords keywords;
 21  
     private final ResourceLoader resourceLoader;
 22  
 
 23  
     public ExamplesTableFactory() {
 24  698
         this(new LocalizedKeywords());
 25  698
     }
 26  
 
 27  
     public ExamplesTableFactory(Keywords keywords) {
 28  698
         this(keywords, new LoadFromURL());
 29  698
     }
 30  
     
 31  
     public ExamplesTableFactory(ResourceLoader resourceLoader) {
 32  0
         this(new LocalizedKeywords(), resourceLoader);
 33  0
     }
 34  
 
 35  699
     public ExamplesTableFactory(Keywords keywords, ResourceLoader resourceLoader) {
 36  699
         this.keywords = keywords;
 37  699
         this.resourceLoader = resourceLoader;
 38  699
     }
 39  
 
 40  
     public ExamplesTable createExamplesTable(String input) {
 41  
         String tableAsString;
 42  124
         if ( isBlank(input) || isTable(input)) {
 43  123
             tableAsString = input;
 44  
         } else {
 45  1
             tableAsString = resourceLoader.loadResourceAsText(input);
 46  
         }
 47  124
         return new ExamplesTable(tableAsString, keywords.examplesTableHeaderSeparator(),
 48  
                 keywords.examplesTableValueSeparator(), keywords.examplesTableIgnorableSeparator());
 49  
     }
 50  
 
 51  
     protected boolean isTable(String input) {
 52  6
         return input.contains(keywords.examplesTableHeaderSeparator());
 53  
     }
 54  
 
 55  
 }