001/* 002 * SonarQube 003 * Copyright (C) 2009-2016 SonarSource SA 004 * mailto:contact AT sonarsource DOT com 005 * 006 * This program is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 3 of the License, or (at your option) any later version. 010 * 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public License 017 * along with this program; if not, write to the Free Software Foundation, 018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 019 */ 020package org.sonar.api.batch.sensor.coverage; 021 022import org.sonar.api.batch.fs.InputFile; 023 024/** 025 * This builder is used to define code coverage by tests of a given type (UT/IT/Overall) on files. 026 * 027 * Example: 028 * 029 * <pre> 030 * sensorContext.newCoverage().onFile(file) 031 .ofType(UNIT) 032 .lineHits(1, 2) 033 .lineHits(2, 5) 034 .lineHits(3, 0) 035 . ... 036 .conditions(3, 4, 2) 037 .conditions(12, 2, 2) 038 . ... 039 .save(); 040 * 041 * </pre> 042 * @since 5.2 043 */ 044public interface NewCoverage { 045 046 /** 047 * The covered file. 048 */ 049 NewCoverage onFile(InputFile inputFile); 050 051 NewCoverage ofType(CoverageType type); 052 053 /** 054 * Call this method as many time as needed to report coverage hits per line. This method should only be called for executable lines. 055 * @param line Line number (starts at 1). 056 * @param hits Number of time the line was hit. 057 */ 058 NewCoverage lineHits(int line, int hits); 059 060 /** 061 * Call this method as many time as needed to report coverage of conditions. 062 * @param line Line number (starts at 1). 063 * @param conditions Number of conditions on this line (should be greater than 1). 064 * @param coveredConditions Number of covered conditions. 065 */ 066 NewCoverage conditions(int line, int conditions, int coveredConditions); 067 068 /** 069 * Call this method only once when your are done with defining coverage of the file. 070 */ 071 void save(); 072}