Skip to content

Commit 4e57fc1

Browse files
authored
Miscellaneous code cleanup (#104)
1 parent 6671c87 commit 4e57fc1

File tree

9 files changed

+27
-33
lines changed

9 files changed

+27
-33
lines changed

src/main/java/com/github/terma/jenkins/githubprcoveragestatus/Configuration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public static final class ConfigurationDescriptor extends Descriptor<Configurati
9292
private static final int DEFAULT_YELLOW_THRESHOLD = 80;
9393
private static final int DEFAULT_GREEN_THRESHOLD = 90;
9494

95-
private final Map<String, Float> coverageByRepo = new ConcurrentHashMap<String, Float>();
95+
private final Map<String, Float> coverageByRepo = new ConcurrentHashMap<>();
9696

9797
private boolean disableSimpleCov;
9898
private String gitHubApiUrl;

src/main/java/com/github/terma/jenkins/githubprcoveragestatus/GetCoverageCallable.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ private List<Float> getFloats(File ws, String path, CoverageReportParser parser)
4444
FileSet fs = Util.createFileSet(ws, path);
4545
DirectoryScanner ds = fs.getDirectoryScanner();
4646
String[] files = ds.getIncludedFiles();
47-
List<Float> cov = new ArrayList<Float>();
47+
List<Float> cov = new ArrayList<>();
4848
for (String file : files) {
4949
cov.add(parser.get(new File(ds.getBasedir(), file).getAbsolutePath()));
5050
}
@@ -60,8 +60,8 @@ public float get(final FilePath workspace) throws IOException, InterruptedExcept
6060
}
6161

6262
@Override
63-
public Float invoke(final File ws, final VirtualChannel channel) throws IOException {
64-
final List<Float> cov = new ArrayList<Float>();
63+
public Float invoke(final File ws, final VirtualChannel channel) {
64+
final List<Float> cov = new ArrayList<>();
6565
cov.addAll(getFloats(ws, "**/cobertura.xml", new CoberturaParser()));
6666
cov.addAll(getFloats(ws, "**/cobertura-coverage.xml", new CoberturaParser()));
6767
cov.addAll(getFloats(ws, "**/jacoco.xml", new JacocoParser(jacocoCounterType)));

src/main/java/com/github/terma/jenkins/githubprcoveragestatus/XmlUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.io.ByteArrayInputStream;
3131
import java.io.IOException;
3232
import java.io.StringReader;
33+
import java.nio.charset.StandardCharsets;
3334

3435
public class XmlUtils {
3536

@@ -48,7 +49,7 @@ public InputSource resolveEntity(String publicId, String systemId)
4849
// }
4950
}
5051
});
51-
Document doc = builder.parse(new InputSource(new ByteArrayInputStream(xml.getBytes("utf-8"))));
52+
Document doc = builder.parse(new InputSource(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8))));
5253
XPathFactory xPathfactory = XPathFactory.newInstance();
5354
XPathExpression expr = xPathfactory.newXPath().compile(xpath);
5455
return (String) expr.evaluate(doc, XPathConstants.STRING);

src/test/java/com/github/terma/jenkins/githubprcoveragestatus/CloverParserTest.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,34 @@
2020
import org.junit.Assert;
2121
import org.junit.Test;
2222

23-
import java.io.IOException;
24-
2523
public class CloverParserTest {
2624

2725
@Test
28-
public void extractCoverageFromCloverReport() throws IOException {
26+
public void extractCoverageFromCloverReport() {
2927
String filePath = CloverParserTest.class.getResource(
3028
"/com/github/terma/jenkins/githubprcoveragestatus/CloverParserTest/clover.xml").getFile();
3129

3230
Assert.assertEquals(0.5, new CloverParser().get(filePath), 0.1);
3331
}
3432

3533
@Test
36-
public void extractZeroCoverageIfNoCoveredStatements() throws IOException {
34+
public void extractZeroCoverageIfNoCoveredStatements() {
3735
String filePath = CloverParserTest.class.getResource(
3836
"/com/github/terma/jenkins/githubprcoveragestatus/CloverParserTest/clover-zero-statements-coverage.xml").getFile();
3937

4038
Assert.assertEquals(0, new CloverParser().get(filePath), 0.1);
4139
}
4240

4341
@Test(expected = IllegalArgumentException.class)
44-
public void throwExceptionIfReportDoesntHaveStatementsAttribute() throws IOException {
42+
public void throwExceptionIfReportDoesntHaveStatementsAttribute() {
4543
String filePath = CloverParserTest.class.getResource(
4644
"/com/github/terma/jenkins/githubprcoveragestatus/CloverParserTest/clover-invalid-no-statements.xml").getFile();
4745

4846
Assert.assertEquals(0, new CloverParser().get(filePath), 0.1);
4947
}
5048

5149
@Test
52-
public void extractZeroCoverageIfZeroStatements() throws IOException {
50+
public void extractZeroCoverageIfZeroStatements() {
5351
String filePath = CloverParserTest.class.getResource(
5452
"/com/github/terma/jenkins/githubprcoveragestatus/CloverParserTest/clover-zero-statements.xml").getFile();
5553

src/test/java/com/github/terma/jenkins/githubprcoveragestatus/CoberturaParserTest.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,59 +20,57 @@
2020
import org.junit.Assert;
2121
import org.junit.Test;
2222

23-
import java.io.IOException;
24-
2523
public class CoberturaParserTest {
2624

2725
@Test
28-
public void extractCoverageFromCoberturaReportAsLineRatePlusBranchRateDivByTwo() throws IOException {
26+
public void extractCoverageFromCoberturaReportAsLineRatePlusBranchRateDivByTwo() {
2927
String filePath = CoberturaParserTest.class.getResource(
3028
"/com/github/terma/jenkins/githubprcoveragestatus/CoberturaParserTest/cobertura.xml").getFile();
3129

3230
Assert.assertEquals(0.94, new CoberturaParser().get(filePath), 0.1);
3331
}
3432

3533
@Test
36-
public void extractCoverageFromCoberturaReportWithSingleQuotes() throws IOException {
34+
public void extractCoverageFromCoberturaReportWithSingleQuotes() {
3735
String filePath = CoberturaParserTest.class.getResource(
3836
"/com/github/terma/jenkins/githubprcoveragestatus/CoberturaParserTest/cobertura-with-single-quotes.xml").getFile();
3937

4038
Assert.assertEquals(0.94, new CoberturaParser().get(filePath), 0.1);
4139
}
4240

4341
@Test
44-
public void extractZeroCoverageIfNoZeroLineRateAndBranchRate() throws IOException {
42+
public void extractZeroCoverageIfNoZeroLineRateAndBranchRate() {
4543
String filePath = CoberturaParserTest.class.getResource(
4644
"/com/github/terma/jenkins/githubprcoveragestatus/CoberturaParserTest/cobertura-zero-coverage.xml").getFile();
4745

4846
Assert.assertEquals(0, new CoberturaParser().get(filePath), 0.1);
4947
}
5048

5149
@Test
52-
public void extractCoverageIfBranchRateIsZeroAndHasOnlyLineRate() throws IOException {
50+
public void extractCoverageIfBranchRateIsZeroAndHasOnlyLineRate() {
5351
String filePath = CoberturaParserTest.class.getResource(
5452
"/com/github/terma/jenkins/githubprcoveragestatus/CoberturaParserTest/cobertura-zero-branch-rate.xml").getFile();
5553

5654
Assert.assertEquals(0.5, new CoberturaParser().get(filePath), 0.1);
5755
}
5856

5957
@Test
60-
public void extractCoverageIfLineRateIsZeroAndHasBranchRate() throws IOException {
58+
public void extractCoverageIfLineRateIsZeroAndHasBranchRate() {
6159
String filePath = CoberturaParserTest.class.getResource(
6260
"/com/github/terma/jenkins/githubprcoveragestatus/CoberturaParserTest/cobertura-zero-line-rate.xml").getFile();
6361

6462
Assert.assertEquals(1, new CoberturaParser().get(filePath), 0.1);
6563
}
6664

6765
@Test(expected = IllegalArgumentException.class)
68-
public void throwExceptionIfNoLineRate() throws IOException {
66+
public void throwExceptionIfNoLineRate() {
6967
String filePath = CoberturaParserTest.class.getResource(
7068
"/com/github/terma/jenkins/githubprcoveragestatus/CoberturaParserTest/cobertura-no-line-rate.xml").getFile();
7169
new CoberturaParser().get(filePath);
7270
}
7371

7472
@Test(expected = IllegalArgumentException.class)
75-
public void throwExceptionIfNoBranchRate() throws IOException {
73+
public void throwExceptionIfNoBranchRate() {
7674
String filePath = CoberturaParserTest.class.getResource(
7775
"/com/github/terma/jenkins/githubprcoveragestatus/CoberturaParserTest/cobertura-no-branch-rate.xml").getFile();
7876
new CoberturaParser().get(filePath);

src/test/java/com/github/terma/jenkins/githubprcoveragestatus/CompareCoverageActionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class CompareCoverageActionTest {
5656
private CompareCoverageAction coverageAction = new CompareCoverageAction();
5757

5858
@Before
59-
public void initMocks() throws IOException, InterruptedException {
59+
public void initMocks() throws IOException {
6060
ServiceRegistry.setMasterCoverageRepository(masterCoverageRepository);
6161
ServiceRegistry.setCoverageRepository(coverageRepository);
6262
ServiceRegistry.setSettingsRepository(settingsRepository);

src/test/java/com/github/terma/jenkins/githubprcoveragestatus/JacocoParserTest.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,44 +20,42 @@
2020
import org.junit.Assert;
2121
import org.junit.Test;
2222

23-
import java.io.IOException;
24-
2523
public class JacocoParserTest {
2624

2725
@Test
28-
public void extractCoverageFromJacocoReport() throws IOException {
26+
public void extractCoverageFromJacocoReport() {
2927
String filePath = JacocoParserTest.class.getResource(
3028
"/com/github/terma/jenkins/githubprcoveragestatus/JacocoParserTest/jacoco.xml").getFile();
3129

3230
Assert.assertEquals(0.22, new JacocoParser("LINE").get(filePath), 0.1);
3331
}
3432

3533
@Test
36-
public void extractCoverageFromJacocoReportWhenNoLinesOfCode() throws IOException {
34+
public void extractCoverageFromJacocoReportWhenNoLinesOfCode() {
3735
String filePath = JacocoParserTest.class.getResource(
3836
"/com/github/terma/jenkins/githubprcoveragestatus/JacocoParserTest/jacoco-no-code.xml").getFile();
3937

4038
Assert.assertEquals(0, new JacocoParser("LINE").get(filePath), 0.1);
4139
}
4240

4341
@Test
44-
public void extractInstructionCoverageFromJacocoReportWhenCoverageTypeNull() throws IOException {
42+
public void extractInstructionCoverageFromJacocoReportWhenCoverageTypeNull() {
4543
String filePath = JacocoParserTest.class.getResource(
4644
"/com/github/terma/jenkins/githubprcoveragestatus/JacocoParserTest/jacoco.xml").getFile();
4745

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

5149
@Test
52-
public void extractInstructionCoverageFromJacocoReportWhenCoverageTypeUnknown() throws IOException {
50+
public void extractInstructionCoverageFromJacocoReportWhenCoverageTypeUnknown() {
5351
String filePath = JacocoParserTest.class.getResource(
5452
"/com/github/terma/jenkins/githubprcoveragestatus/JacocoParserTest/jacoco.xml").getFile();
5553

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

5957
@Test
60-
public void throwExceptionWhenExtractCoverageFromJacocoAndNoLineTag() throws IOException {
58+
public void throwExceptionWhenExtractCoverageFromJacocoAndNoLineTag() {
6159
String filePath = JacocoParserTest.class.getResource(
6260
"/com/github/terma/jenkins/githubprcoveragestatus/JacocoParserTest/jacoco-no-line-tag.xml").getFile();
6361

@@ -80,7 +78,7 @@ public void throwExceptionWhenExtractCoverageFromJacocoAndNoLineTag() throws IOE
8078
}
8179

8280
@Test
83-
public void throwExceptionWhenExtractCoverageFromJacocoAndMissedNotNumber() throws IOException {
81+
public void throwExceptionWhenExtractCoverageFromJacocoAndMissedNotNumber() {
8482
String filePath = JacocoParserTest.class.getResource(
8583
"/com/github/terma/jenkins/githubprcoveragestatus/JacocoParserTest/jacoco-missed-not-number.xml").getFile();
8684

@@ -104,7 +102,7 @@ public void throwExceptionWhenExtractCoverageFromJacocoAndMissedNotNumber() thro
104102
}
105103

106104
@Test
107-
public void throwExceptionWhenExtractCoverageFromJacocoAndCoveredNotNumber() throws IOException {
105+
public void throwExceptionWhenExtractCoverageFromJacocoAndCoveredNotNumber() {
108106
String filePath = JacocoParserTest.class.getResource(
109107
"/com/github/terma/jenkins/githubprcoveragestatus/JacocoParserTest/jacoco-covered-not-number.xml").getFile();
110108

@@ -128,7 +126,7 @@ public void throwExceptionWhenExtractCoverageFromJacocoAndCoveredNotNumber() thr
128126
}
129127

130128
@Test
131-
public void throwExceptionWhenExtractCoverageFromJacocoAndNoFile() throws IOException {
129+
public void throwExceptionWhenExtractCoverageFromJacocoAndNoFile() {
132130
try {
133131
new JacocoParser("LINE").get("/jacoco-no-file.xml");
134132
Assert.fail("Where is my exception?");

src/test/java/com/github/terma/jenkins/githubprcoveragestatus/SimpleCovParserTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.github.terma.jenkins.githubprcoveragestatus;
22

33
import junit.framework.TestCase;
4-
import org.junit.Assert;
54
import org.junit.Test;
65

76
import static org.hamcrest.CoreMatchers.equalTo;

src/test/java/com/github/terma/jenkins/githubprcoveragestatus/SonarMasterCoverageRepositoryTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class SonarMasterCoverageRepositoryTest {
2828
private ByteArrayOutputStream buildLogOutputStream;
2929

3030
@After
31-
public void afterTest() throws Exception {
31+
public void afterTest() {
3232
System.out.println(buildLogOutputStream.toString());
3333
wireMockRule.resetMappings();
3434
}

0 commit comments

Comments
 (0)