@@ -44,6 +44,9 @@ class SarifReportTest {
44
44
)
45
45
Mockito .`when `(mockUtExecutionAIOBE.stateBefore.parameters).thenReturn(listOf ())
46
46
47
+ defaultMockCoverage(mockUtExecutionNPE)
48
+ defaultMockCoverage(mockUtExecutionAIOBE)
49
+
47
50
val testSets = listOf (
48
51
UtMethodTestSet (mockExecutableId, listOf (mockUtExecutionNPE)),
49
52
UtMethodTestSet (mockExecutableId, listOf (mockUtExecutionAIOBE))
@@ -68,12 +71,13 @@ class SarifReportTest {
68
71
)
69
72
Mockito .`when `(mockUtExecution.stateBefore.parameters).thenReturn(listOf ())
70
73
Mockito .`when `(mockUtExecution.coverage?.coveredInstructions?.lastOrNull()?.lineNumber).thenReturn(1337 )
74
+ Mockito .`when `(mockUtExecution.coverage?.coveredInstructions?.lastOrNull()?.className).thenReturn(" Main" )
71
75
Mockito .`when `(mockUtExecution.testMethodName).thenReturn(" testMain_ThrowArithmeticException" )
72
76
73
77
val report = sarifReportMain.createReport()
74
78
75
79
val result = report.runs.first().results.first()
76
- val location = result.locations.first().physicalLocation
80
+ val location = result.locations.filterIsInstance< SarifPhysicalLocationWrapper >(). first().physicalLocation
77
81
val relatedLocation = result.relatedLocations.first().physicalLocation
78
82
79
83
assert (location.artifactLocation.uri.contains(" Main.java" ))
@@ -98,6 +102,8 @@ class SarifReportTest {
98
102
)
99
103
)
100
104
105
+ defaultMockCoverage(mockUtExecution)
106
+
101
107
val report = sarifReportMain.createReport()
102
108
103
109
val result = report.runs.first().results.first()
@@ -121,6 +127,8 @@ class SarifReportTest {
121
127
)
122
128
Mockito .`when `(mockUtExecution.stateBefore.parameters).thenReturn(listOf ())
123
129
130
+ defaultMockCoverage(mockUtExecution)
131
+
124
132
val report = sarifReportMain.createReport()
125
133
126
134
val result = report.runs.first().results.first().codeFlows.first().threadFlows.first().locations.map {
@@ -140,6 +148,8 @@ class SarifReportTest {
140
148
Mockito .`when `(uncheckedException.stackTrace).thenReturn(arrayOf())
141
149
Mockito .`when `(mockUtExecution.result).thenReturn(UtSandboxFailure (uncheckedException))
142
150
151
+ defaultMockCoverage(mockUtExecution)
152
+
143
153
val report = sarifReportMain.createReport()
144
154
val result = report.runs.first().results.first()
145
155
assert (result.message.text.contains(" AccessControlException" ))
@@ -159,6 +169,8 @@ class SarifReportTest {
159
169
Mockito .`when `(mockUtExecution.stateBefore.parameters).thenReturn(listOf ())
160
170
Mockito .`when `(mockUtExecution.testMethodName).thenReturn(" testMain_ThrowArithmeticException" )
161
171
172
+ defaultMockCoverage(mockUtExecution)
173
+
162
174
val report = sarifReportMain.createReport()
163
175
164
176
val codeFlowPhysicalLocations = report.runs[0 ].results[0 ].codeFlows[0 ].threadFlows[0 ].locations.map {
@@ -183,6 +195,8 @@ class SarifReportTest {
183
195
Mockito .`when `(mockUtExecution.stateBefore.parameters).thenReturn(listOf ())
184
196
Mockito .`when `(mockUtExecution.testMethodName).thenReturn(" testMain_ThrowArithmeticException" )
185
197
198
+ defaultMockCoverage(mockUtExecution)
199
+
186
200
val report = sarifReportPrivateMain.createReport()
187
201
188
202
val codeFlowPhysicalLocations = report.runs[0 ].results[0 ].codeFlows[0 ].threadFlows[0 ].locations.map {
@@ -200,6 +214,8 @@ class SarifReportTest {
200
214
val mockUtExecution = Mockito .mock(UtExecution ::class .java, Mockito .RETURNS_DEEP_STUBS )
201
215
Mockito .`when `(mockUtExecution.result).thenReturn(UtImplicitlyThrownException (NullPointerException (), false ))
202
216
217
+ defaultMockCoverage(mockUtExecution)
218
+
203
219
val testSets = listOf (
204
220
UtMethodTestSet (mockExecutableId, listOf (mockUtExecution)),
205
221
UtMethodTestSet (mockExecutableId, listOf (mockUtExecution)) // duplicate
@@ -225,6 +241,9 @@ class SarifReportTest {
225
241
Mockito .`when `(mockUtExecution1.result).thenReturn(UtImplicitlyThrownException (NullPointerException (), false ))
226
242
Mockito .`when `(mockUtExecution2.result).thenReturn(UtImplicitlyThrownException (ArithmeticException (), false ))
227
243
244
+ defaultMockCoverage(mockUtExecution1)
245
+ defaultMockCoverage(mockUtExecution2)
246
+
228
247
val testSets = listOf (
229
248
UtMethodTestSet (mockExecutableId, listOf (mockUtExecution1)),
230
249
UtMethodTestSet (mockExecutableId, listOf (mockUtExecution2)) // not a duplicate
@@ -252,7 +271,9 @@ class SarifReportTest {
252
271
253
272
// different locations
254
273
Mockito .`when `(mockUtExecution1.coverage?.coveredInstructions?.lastOrNull()?.lineNumber).thenReturn(11 )
274
+ Mockito .`when `(mockUtExecution1.coverage?.coveredInstructions?.lastOrNull()?.className).thenReturn(" Main" )
255
275
Mockito .`when `(mockUtExecution2.coverage?.coveredInstructions?.lastOrNull()?.lineNumber).thenReturn(22 )
276
+ Mockito .`when `(mockUtExecution2.coverage?.coveredInstructions?.lastOrNull()?.className).thenReturn(" Main" )
256
277
257
278
val testSets = listOf (
258
279
UtMethodTestSet (mockExecutableId, listOf (mockUtExecution1)),
@@ -288,6 +309,9 @@ class SarifReportTest {
288
309
Mockito .`when `(mockNPE1.stackTrace).thenReturn(arrayOf(stackTraceElement1))
289
310
Mockito .`when `(mockNPE2.stackTrace).thenReturn(arrayOf(stackTraceElement1, stackTraceElement2))
290
311
312
+ defaultMockCoverage(mockUtExecution1)
313
+ defaultMockCoverage(mockUtExecution2)
314
+
291
315
val testSets = listOf (
292
316
UtMethodTestSet (mockExecutableId, listOf (mockUtExecution1)),
293
317
UtMethodTestSet (mockExecutableId, listOf (mockUtExecution2)) // duplicate with a longer stack trace
@@ -316,6 +340,11 @@ class SarifReportTest {
316
340
Mockito .`when `(mockExecutableId.classId.name).thenReturn(" Main" )
317
341
}
318
342
343
+ private fun defaultMockCoverage (mockExecution : UtExecution ) {
344
+ Mockito .`when `(mockExecution.coverage?.coveredInstructions?.lastOrNull()?.lineNumber).thenReturn(1 )
345
+ Mockito .`when `(mockExecution.coverage?.coveredInstructions?.lastOrNull()?.className).thenReturn(" Main" )
346
+ }
347
+
319
348
// constants
320
349
321
350
private val sourceFindingEmpty = SourceFindingStrategyDefault (
0 commit comments