Skip to content

Commit 23bae4c

Browse files
Handle null SCA results in PredicateTest
Add guards in PredicateTest to skip scans with null results and to assume SCA result data exists before accessing it. These checks prevent NPEs and make the test resilient when scans or SCA payloads are missing, causing the test to be skipped instead of failing.
1 parent da96e45 commit 23bae4c

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/test/java/com/checkmarx/ast/predicate/PredicateTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,17 @@ void testGetStates() throws Exception {
6262
@Test
6363
void testScaTriage() throws Exception {
6464
// Automatically find a completed scan that has SCA results
65-
List<Scan> scans = wrapper.scanList("statuses=Completed");
65+
List<Scan> scans = wrapper.scanList("statuses=Completed&limit=50");
6666
Assumptions.assumeTrue(scans != null && scans.size() > 0, "No completed scans available");
6767

6868
Scan scaScan = null;
6969
Result scaResult = null;
7070

7171
for (Scan scan : scans) {
7272
Results results = wrapper.results(UUID.fromString(scan.getId()));
73+
if (results.getResults() == null) {
74+
continue;
75+
}
7376
scaResult = results.getResults().stream()
7477
.filter(res -> res.getType().equalsIgnoreCase("sca"))
7578
.findFirst()
@@ -81,6 +84,7 @@ void testScaTriage() throws Exception {
8184
}
8285

8386
Assumptions.assumeTrue(scaScan != null, "Skipping: no completed scan with SCA results found");
87+
Assumptions.assumeTrue(scaResult.getData() != null, "Skipping: SCA result has no data/vulnerabilities");
8488

8589
String packageIdentifier = scaResult.getData().getPackageIdentifier();
8690
int firstDash = packageIdentifier.indexOf('-');

0 commit comments

Comments
 (0)