Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitrii Motpan committed Oct 18, 2018
1 parent 7fce9e0 commit ec9e0b4
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ public float get(final String cloverFilePath) {
if (statements == 0) return 0;
else return coveredStatements / statements;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,6 @@ public float get(String coberturaFilePath) {
throw new RuntimeException(e);
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,14 @@
import hudson.tasks.Publisher;
import hudson.tasks.Recorder;
import jenkins.tasks.SimpleBuildStep;
import org.kohsuke.github.*;
import org.kohsuke.github.GHRepository;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;

import javax.annotation.Nonnull;
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
interface CoverageReportParser {

float get(String filePath);

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
<counter type="METHOD" missed="1" covered="2"/>
<counter type="CLASS" missed="0" covered="1"/>
*/

class JacocoParser implements CoverageReportParser {

private List<String> coverageTypes = new ArrayList<String>() {{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ public void extractCoverageFromJacocoReportWhenNoLinesOfCode() throws IOExceptio
Assert.assertEquals(0, new JacocoParser("LINE").get(filePath), 0.1);
}

@Test
public void extractInstructionCoverageFromJacocoReportWhenCoverageTypeNull() throws IOException {
String filePath = JacocoParserTest.class.getResource(
"/com/github/terma/jenkins/githubprcoveragestatus/JacocoParserTest/jacoco.xml").getFile();

Assert.assertEquals(0.22, new JacocoParser(null).get(filePath), 0.1);
}

@Test
public void extractInstructionCoverageFromJacocoReportWhenCoverageTypeUnknown() throws IOException {
String filePath = JacocoParserTest.class.getResource(
"/com/github/terma/jenkins/githubprcoveragestatus/JacocoParserTest/jacoco.xml").getFile();

Assert.assertEquals(0.22, new JacocoParser("random").get(filePath), 0.1);
}

@Test
public void throwExceptionWhenExtractCoverageFromJacocoAndNoLineTag() throws IOException {
String filePath = JacocoParserTest.class.getResource(
Expand Down

0 comments on commit ec9e0b4

Please sign in to comment.