Skip to content

Commit e6a26cb

Browse files
authored
Other/ Increase code coverage in java Wrapper (AST-80967) (#395)
* test * put kics real time in comment * add test * add test * add badge and remove comment from kics * fix pom file * fix pr * fix pr * fix ci file * fix pom and ci * fix pom and ci * fix code coverage and remove job printed * run again * fix pr * add to exclude * fix pr
1 parent 9e56a54 commit e6a26cb

File tree

5 files changed

+53
-19
lines changed

5 files changed

+53
-19
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,10 @@ jobs:
6868
CX_TENANT: ${{ secrets.CX_TENANT }}
6969
CX_APIKEY: ${{ secrets.CX_APIKEY }}
7070

71-
- name: Print total coverage percentage
72-
run: |
73-
COVERED_LINES=$(xmllint --xpath "string(//report/counter[@type='LINE']/@covered)" target/site/jacoco/jacoco.xml)
74-
MISSED_LINES=$(xmllint --xpath "string(//report/counter[@type='LINE']/@missed)" target/site/jacoco/jacoco.xml)
75-
TOTAL_LINES=$((COVERED_LINES + MISSED_LINES))
76-
COVERAGE_PERCENTAGE=$(echo "scale=2; $COVERED_LINES / $TOTAL_LINES * 100" | bc)
77-
echo "Total coverage percentage: $COVERAGE_PERCENTAGE%"
71+
- name: Generate JaCoCo Badge
72+
uses: cicirello/jacoco-badge-generator@f33476a5a3fd5a4f77cb5eef2ebe728c1dd5b921 #v2.11.0
73+
with:
74+
jacoco-csv-file: target/site/jacoco/jacoco.csv
7875

7976
- name: Upload JaCoCo coverage report
8077
uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 #v4

pom.xml

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,28 @@
6565
<groupId>org.jacoco</groupId>
6666
<artifactId>jacoco-maven-plugin</artifactId>
6767
<version>0.8.8</version>
68+
<configuration>
69+
<excludes>
70+
<exclude>**/com/checkmarx/ast/results/**</exclude>
71+
<exclude>**/com/checkmarx/ast/kicsRealtimeResults/**</exclude>
72+
<exclude>**/com/checkmarx/ast/asca/**</exclude>
73+
<exclude>**/com/checkmarx/ast/learnMore/**</exclude>
74+
<exclude>**/com/checkmarx/ast/predicate/**</exclude>
75+
<exclude>**/com/checkmarx/ast/scan/**</exclude>
76+
<exclude>**/com/checkmarx/ast/codebashing/**</exclude>
77+
<exclude>**/com/checkmarx/ast/remediation/**</exclude>
78+
<exclude>**/com/checkmarx/ast/project/**</exclude>
79+
<exclude>**/com/checkmarx/ast/tenant/**</exclude>
80+
<exclude>**/com/checkmarx/ast/wrapper/CxConstants.class</exclude>
81+
<exclude>**/com/checkmarx/ast/wrapper/CxException.class</exclude>
82+
<exclude>**/com/checkmarx/ast/wrapper/CxConfig.class</exclude>
83+
<exclude>**/com/checkmarx/ast/wrapper/CxBaseObject.class</exclude>
84+
<exclude>**/com/checkmarx/ast/wrapper/CxConfig$*.class</exclude>
85+
86+
87+
<!-- Add other patterns as needed -->
88+
</excludes>
89+
</configuration>
6890
<executions>
6991
<execution>
7092
<goals>
@@ -77,15 +99,10 @@
7799
<goals>
78100
<goal>report</goal>
79101
</goals>
80-
<configuration>
81-
<includes>
82-
<include>**/src/main/java/**</include>
83-
<!-- Add other patterns as needed -->
84-
</includes>
85-
</configuration>
86102
</execution>
87103
</executions>
88104
</plugin>
105+
89106
<plugin>
90107
<groupId>com.github.spotbugs</groupId>
91108
<artifactId>spotbugs-maven-plugin</artifactId>

src/main/java/com/checkmarx/ast/wrapper/CxConfig.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,6 @@ List<String> toArguments() {
6363
return commands;
6464
}
6565

66-
public static final class InvalidCLIConfigException extends Exception {
67-
public InvalidCLIConfigException(String message) {
68-
super(message);
69-
}
70-
}
7166

7267
@SuppressWarnings("ALL")
7368
public static class CxConfigBuilder {

src/test/java/com/checkmarx/ast/AuthTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class AuthTest extends BaseTest {
1616
void testAuthValidate() throws CxException, IOException, InterruptedException {
1717
Assertions.assertNotNull(wrapper.authValidate());
1818
}
19-
19+
//
2020
@Test
2121
void testAuthFailure() {
2222
CxConfig cxConfig = getConfig();
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.checkmarx.ast;
2+
3+
import com.checkmarx.ast.results.ReportFormat;
4+
import org.junit.jupiter.api.Assertions;
5+
import org.junit.jupiter.api.Test;
6+
7+
import java.util.List;
8+
import java.util.UUID;
9+
10+
class BuildResultsArgumentsTest extends BaseTest {
11+
12+
@Test
13+
void testBuildResultsArguments_CreatesValidArguments() {
14+
UUID scanId = UUID.randomUUID();
15+
ReportFormat format = ReportFormat.json;
16+
17+
List<String> arguments = wrapper.buildResultsArguments(scanId, format);
18+
//
19+
20+
Assertions.assertNotNull(arguments, "Arguments list should not be null");
21+
Assertions.assertFalse(arguments.isEmpty(), "Arguments list should not be empty");
22+
Assertions.assertTrue(arguments.contains(scanId.toString()), "Arguments should contain scan ID");
23+
Assertions.assertTrue(arguments.contains(format.toString()), "Arguments should contain the report format");
24+
}
25+
}

0 commit comments

Comments
 (0)