Coverage Report - org.tap4j.consumer.TapConsumerImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
TapConsumerImpl
100%
19/19
N/A
1.667
 
 1  
 /*
 2  
  * The MIT License
 3  
  *
 4  
  * Copyright (c) <2010> <tap4j>
 5  
  * 
 6  
  * Permission is hereby granted, free of charge, to any person obtaining a copy
 7  
  * of this software and associated documentation files (the "Software"), to deal
 8  
  * in the Software without restriction, including without limitation the rights
 9  
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 10  
  * copies of the Software, and to permit persons to whom the Software is
 11  
  * furnished to do so, subject to the following conditions:
 12  
  * 
 13  
  * The above copyright notice and this permission notice shall be included in
 14  
  * all copies or substantial portions of the Software.
 15  
  * 
 16  
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 17  
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 18  
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 19  
  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 20  
  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 21  
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 22  
  * THE SOFTWARE.
 23  
  */
 24  
 package org.tap4j.consumer;
 25  
 
 26  
 import java.io.File;
 27  
 
 28  
 import org.tap4j.model.TestSet;
 29  
 import org.tap4j.parser.Parser;
 30  
 import org.tap4j.parser.ParserException;
 31  
 import org.tap4j.parser.Tap13Parser;
 32  
 
 33  
 /**
 34  
  * Implementation of a TAP Consumer. It can use different TAP parsers. The 
 35  
  * parser can change the behaviour of the consumer, as the latter delegates 
 36  
  * the parsing and TAP model loading to the former.
 37  
  * 
 38  
  * @since 1.0
 39  
  */
 40  
 public class TapConsumerImpl implements TapConsumer {
 41  
     
 42  
     /**
 43  
      * TAP parser.
 44  
      */
 45  
     private final Parser parser;
 46  
     
 47  
     /**
 48  
      * TAP Test Set.
 49  
      */
 50  
     private TestSet testSet;
 51  
     
 52  
     /**
 53  
      * Default constructor.
 54  
      */
 55  23
     public TapConsumerImpl() {
 56  23
         parser = new Tap13Parser();
 57  23
         testSet = new TestSet();
 58  23
     }
 59  
     
 60  
     /**
 61  
      * Constructor with a parser.
 62  
      * @param parser a parser
 63  
      */
 64  16
     public TapConsumerImpl(Parser parser) {
 65  16
         this.parser = parser;
 66  16
     }
 67  
     
 68  
     /*
 69  
      * (non-Javadoc)
 70  
      * @see org.tap4j.consumer.TapConsumer#getTestSet()
 71  
      */
 72  
     public TestSet getTestSet() {
 73  3
         return this.testSet;
 74  
     }
 75  
     
 76  
     /*
 77  
      * (non-Javadoc)
 78  
      * @see org.tap4j.consumer.TapConsumer#load(java.io.File)
 79  
      */
 80  
     public TestSet load(File file) {
 81  
         try {
 82  33
             this.testSet = this.parser.parseFile(file);
 83  10
         } catch (ParserException e) {
 84  10
             throw new TapConsumerException("Failed to parse file " + file +
 85  
                                            ": " + e.getMessage(), e);
 86  23
         }
 87  23
         return this.testSet;
 88  
     }
 89  
     
 90  
     /*
 91  
      * (non-Javadoc)
 92  
      * @see org.tap4j.consumer.TapConsumer#load(java.lang.String)
 93  
      */
 94  
     public TestSet load(String tapStream) {
 95  
         try {
 96  6
             this.testSet = this.parser.parseTapStream(tapStream);
 97  1
         } catch (ParserException e) {
 98  1
             throw new TapConsumerException("Failed to parse TAP Stream " +
 99  
                                            tapStream + ": " + e.getMessage(), e);
 100  5
         }
 101  5
         return this.testSet;
 102  
     }
 103  
     
 104  
     /*
 105  
      * (non-Javadoc)
 106  
      * @see org.tap4j.consumer.TapConsumer#getParser()
 107  
      */
 108  
     public Parser getParser() {
 109  2
         return this.parser;
 110  
     }
 111  
 
 112  
 }