Coverage Report - org.tap4j.producer.TapProducerImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
TapProducerImpl
87%
29/33
N/A
2.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.producer;
 25  
 
 26  
 import java.io.File;
 27  
 import java.io.IOException;
 28  
 import java.io.Writer;
 29  
 
 30  
 import org.apache.commons.io.FileUtils;
 31  
 import org.tap4j.model.TestSet;
 32  
 import org.tap4j.representer.Representer;
 33  
 import org.tap4j.representer.RepresenterException;
 34  
 import org.tap4j.representer.Tap13Representer;
 35  
 
 36  
 /**
 37  
  * @author Bruno P. Kinoshita - http://www.kinoshita.eti.br
 38  
  * @since 1.0
 39  
  */
 40  
 public class TapProducerImpl 
 41  
 implements TapProducer 
 42  
 {
 43  
 
 44  
         protected Representer representer;
 45  
         
 46  
         public TapProducerImpl()
 47  
         {
 48  4
                 super();
 49  4
                 representer = new Tap13Representer();
 50  4
         }
 51  
         
 52  
         public TapProducerImpl(Representer representer)
 53  10
         {
 54  10
                 this.representer = representer;
 55  10
         }
 56  
         
 57  
         /* (non-Javadoc)
 58  
          * @see org.tap4j.producer.TapProducer#dump(org.tap4j.model.TestSet)
 59  
          */
 60  
         public String dump(TestSet testSet) 
 61  
         throws TapProducerException 
 62  
         {
 63  151
                 String dumpData = null;
 64  
                 
 65  
                 try
 66  
                 {
 67  151
                         dumpData = this.representer.representData(testSet);
 68  
                 } 
 69  1
                 catch ( RepresenterException re )
 70  
                 {
 71  1
                         throw new TapProducerException( "Failed to produce test set dump: " + re.getMessage(), re );
 72  150
                 }
 73  
                 
 74  150
                 return dumpData;
 75  
         }
 76  
 
 77  
         /* (non-Javadoc)
 78  
          * @see org.tap4j.producer.TapProducer#dump(org.tap4j.model.TestSet, java.io.Writer)
 79  
          */
 80  
         public void dump(TestSet testSet, Writer writer)
 81  
         throws TapProducerException 
 82  
         {
 83  3
                 String tapStream = null;
 84  
                 
 85  
                 try
 86  
                 {
 87  3
                         tapStream = this.dump(testSet);
 88  
                 } 
 89  0
                 catch ( RepresenterException re )
 90  
                 {
 91  0
                         throw new TapProducerException( "Failed to dump Test Set to writer: " + re.getMessage(), re );
 92  3
                 }
 93  
                 
 94  
                 try 
 95  
                 {
 96  3
                         writer.append(tapStream);
 97  
                 } 
 98  1
                 catch (IOException e) 
 99  
                 {
 100  1
                         throw new TapProducerException("Failed to dump TAP Stream: " + e.getMessage(), e);
 101  1
                 }
 102  1
         }
 103  
 
 104  
         /* (non-Javadoc)
 105  
          * @see org.tap4j.producer.TapProducer#dump(org.tap4j.model.TestSet, java.io.File)
 106  
          */
 107  
         public void dump(TestSet testSet, File output)
 108  
         throws TapProducerException 
 109  
         {
 110  147
                 String tapStream = null;
 111  
                 
 112  
                 try
 113  
                 {
 114  147
                         tapStream = this.dump(testSet);
 115  
                 } 
 116  0
                 catch ( RepresenterException re )
 117  
                 {
 118  0
                         throw new TapProducerException( "Failed to dump Test Set to output file '"+output+"': " + re.getMessage(), re );
 119  146
                 }
 120  
                 
 121  
                 try 
 122  
                 {
 123  146
                         FileUtils.writeStringToFile(output, tapStream);
 124  
                 }
 125  1
                 catch (IOException e) 
 126  
                 {
 127  1
                         throw new TapProducerException("Failed to dump TAP Stream: " + e.getMessage(), e);
 128  145
                 }
 129  145
         }
 130  
 
 131  
         /* (non-Javadoc)
 132  
          * @see org.tap4j.producer.TapProducer#getRepresenter()
 133  
          */
 134  
         public Representer getRepresenter()
 135  
         {
 136  2
                 return this.representer;
 137  
         }
 138  
         
 139  
 }