24
24
25
25
import com .google .gson .JsonObject ;
26
26
import com .scanoss .dto .ScanFileResult ;
27
+ import com .scanoss .dto .enums .MatchType ;
27
28
import com .scanoss .settings .Bom ;
28
29
import com .scanoss .settings .RemoveRule ;
29
30
import com .scanoss .settings .ReplaceRule ;
@@ -73,6 +74,16 @@ public void Setup() throws URISyntaxException, IOException {
73
74
74
75
}
75
76
77
+ private Boolean hasOnlyNonMatchingDetailsForPath (List <ScanFileResult > results , String path ) {
78
+ Optional <ScanFileResult > r = results .stream ().filter (result -> result .getFilePath ().matches (path )).findFirst ();
79
+
80
+ if (r .isEmpty ()) {
81
+ fail (String .format ("Should have found file %s" , path ));
82
+ }
83
+
84
+ return r .get ().getFileDetails ().stream ().noneMatch (c -> c .getMatchType () != MatchType .none );
85
+
86
+ }
76
87
77
88
/**
78
89
* TESTING REMOVE RULES
@@ -94,7 +105,7 @@ public void TestRemoveRuleWithPathAndPurl() {
94
105
List <ScanFileResult > results = scannerPostProcessor .process (sampleScanResults , bom );
95
106
96
107
// Verify
97
- assertEquals ( "Should have one result less after removal" , sampleScanResults . size () - 1 , results . size ( ));
108
+ assertTrue ( hasOnlyNonMatchingDetailsForPath ( results , "CMSsite/admin/js/npm.js" ));
98
109
log .info ("Finished {} -->" , methodName );
99
110
}
100
111
@@ -116,13 +127,7 @@ public void TestRemoveRuleWithPurlOnly() {
116
127
// Process results
117
128
List <ScanFileResult > results = scannerPostProcessor .process (sampleScanResults , bom );
118
129
119
- // Verify
120
- assertEquals ("Size should decrease by 1 after removal" ,
121
- sampleScanResults .size () - 1 ,
122
- results .size ());
123
-
124
- assertFalse ("Should remove file CMSsite/admin/js/npm.js" ,
125
- results .stream ().anyMatch (r -> r .getFilePath ().matches ("CMSsite/admin/js/npm.js" )));
130
+ assertTrue (hasOnlyNonMatchingDetailsForPath (results , "CMSsite/admin/js/npm.js" ));
126
131
127
132
log .info ("Finished {} -->" , methodName );
128
133
}
@@ -258,7 +263,7 @@ public void testRemoveRuleWithOverlappingLineRanges() {
258
263
List <ScanFileResult > results = scannerPostProcessor .process (sampleScanResults , bom );
259
264
260
265
// Verify - should remove because lines overlap
261
- assertEquals ( "Should have one result less after removal" , sampleScanResults . size () - 1 , results . size ( ));
266
+ assertTrue ( hasOnlyNonMatchingDetailsForPath ( results , "src/spdx.c" ));
262
267
263
268
log .info ("Finished {} -->" , methodName );
264
269
}
@@ -289,7 +294,7 @@ public void testMultipleRemoveRulesWithMixedLineRanges() {
289
294
// Process results
290
295
List <ScanFileResult > results = scannerPostProcessor .process (sampleScanResults , bom );
291
296
292
- assertEquals ( "Should have one result less after removal" , sampleScanResults . size () - 1 , results . size ( ));
297
+ assertTrue ( hasOnlyNonMatchingDetailsForPath ( results , "src/spdx.c" ));
293
298
294
299
log .info ("Finished {} -->" , methodName );
295
300
}
0 commit comments