View Javadoc

1   package org.codehaus.mojo.dashboard.report.plugin.beans;
2   
3   /*
4    * Copyright 2006 David Vicente
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  
20  
21  import java.util.Date;
22  
23  /**
24   * 
25   * @author <a href="dvicente72@gmail.com">David Vicente</a>
26   * 
27   */
28  public class CoberturaReportBean extends AbstractReportBean
29  {
30      /**
31       * 
32       */
33      private int nbClasses;
34      /**
35       * 
36       */
37      private double lineCoverRate;
38      /**
39       * 
40       */
41      private double branchCoverRate;
42      /**
43       * 
44       */
45      private int numberOfCoveredBranches;
46      /**
47       * 
48       */
49      private int numberOfCoveredLines;
50      /**
51       * 
52       */
53      private int numberOfValidBranches;
54      /**
55       * 
56       */
57      private int numberOfValidLines;
58      /**
59       * Default constructor
60       *
61       */
62      public CoberturaReportBean()
63      {
64      }
65      /**
66       * 
67       * @param dateGeneration
68       */
69      public CoberturaReportBean( Date dateGeneration )
70      {
71          super( dateGeneration );
72      }
73      /**
74       * 
75       * @return
76       */
77      public int getNbClasses()
78      {
79          return nbClasses;
80      }
81      /**
82       * 
83       * @param nbClasses
84       */
85      public void setNbClasses( int nbClasses )
86      {
87          this.nbClasses = nbClasses;
88      }
89      /**
90       * 
91       * @return
92       */
93      public double getLineCoverRate()
94      {
95          return lineCoverRate;
96      }
97      /**
98       * 
99       * @param lineCoverRate
100      */
101     public void setLineCoverRate( double lineCoverRate )
102     {
103         this.lineCoverRate = lineCoverRate;
104     }
105     /**
106      * 
107      * @return
108      */
109     public double getBranchCoverRate()
110     {
111         return branchCoverRate;
112     }
113     /**
114      * 
115      * @param branchCoverRate
116      */
117     public void setBranchCoverRate( double branchCoverRate )
118     {
119         this.branchCoverRate = branchCoverRate;
120     }
121     /**
122      * 
123      * @return
124      */
125     public int getNumberOfCoveredBranches()
126     {
127         return numberOfCoveredBranches;
128     }
129     /**
130      * 
131      * @param numberOfCoveredBranches
132      */
133     public void setNumberOfCoveredBranches( int numberOfCoveredBranches )
134     {
135         this.numberOfCoveredBranches = numberOfCoveredBranches;
136     }
137     /**
138      * 
139      * @return
140      */
141     public int getNumberOfCoveredLines()
142     {
143         return numberOfCoveredLines;
144     }
145     /**
146      * 
147      * @param numberOfCoveredLines
148      */
149     public void setNumberOfCoveredLines( int numberOfCoveredLines )
150     {
151         this.numberOfCoveredLines = numberOfCoveredLines;
152     }
153     /**
154      * 
155      * @return
156      */
157     public int getNumberOfValidBranches()
158     {
159         return numberOfValidBranches;
160     }
161     /**
162      * 
163      * @param numberOfValidBranches
164      */
165     public void setNumberOfValidBranches( int numberOfValidBranches )
166     {
167         this.numberOfValidBranches = numberOfValidBranches;
168     }
169     /**
170      * 
171      * @return
172      */
173     public int getNumberOfValidLines()
174     {
175         return numberOfValidLines;
176     }
177     /**
178      * 
179      * @param numberOfValidLines
180      */
181     public void setNumberOfValidLines( int numberOfValidLines )
182     {
183         this.numberOfValidLines = numberOfValidLines;
184     }
185     /**
186      * 
187      * @param dashboardReport
188      */
189     public void merge( IDashBoardReportBean dashboardReport )
190     {
191         if ( dashboardReport != null && dashboardReport instanceof CoberturaReportBean )
192         {
193             this.nbClasses = this.nbClasses + ( (CoberturaReportBean) dashboardReport ).getNbClasses();
194             this.numberOfCoveredBranches =
195                 this.numberOfCoveredBranches + ( (CoberturaReportBean) dashboardReport ).getNumberOfCoveredBranches();
196             this.numberOfCoveredLines =
197                 this.numberOfCoveredLines + ( (CoberturaReportBean) dashboardReport ).getNumberOfCoveredLines();
198             this.numberOfValidBranches =
199                 this.numberOfValidBranches + ( (CoberturaReportBean) dashboardReport ).getNumberOfValidBranches();
200             this.numberOfValidLines =
201                 this.numberOfValidLines + ( (CoberturaReportBean) dashboardReport ).getNumberOfValidLines();
202             if ( numberOfValidBranches == 0 )
203             {
204                 // no branches, therefore 100% branch coverage.
205                 branchCoverRate = 1d;
206             }
207             else
208             {
209                 branchCoverRate = (double) numberOfCoveredBranches / numberOfValidBranches;
210             }
211             //MOJO-662 correction
212             if ( numberOfValidLines == 0 )
213             {
214                 // no branches, therefore 100% branch coverage.
215                 lineCoverRate = 1d;
216             }
217             else
218             {
219                 lineCoverRate = (double) numberOfCoveredLines / numberOfValidLines;
220             }
221         }
222     }
223 }