1
1
package org.utbot.sarif
2
2
3
- import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
4
- import com.fasterxml.jackson.module.kotlin.readValue
5
3
import org.junit.Test
6
4
import org.mockito.Mockito
7
5
import org.utbot.framework.plugin.api.ExecutableId
@@ -19,7 +17,7 @@ class SarifReportTest {
19
17
testSets = listOf (),
20
18
generatedTestsCode = " " ,
21
19
sourceFindingEmpty
22
- ).createReport()
20
+ ).createReport().toJson()
23
21
24
22
assert (actualReport.isNotEmpty())
25
23
}
@@ -30,7 +28,7 @@ class SarifReportTest {
30
28
testSets = listOf (testSet),
31
29
generatedTestsCode = " " ,
32
30
sourceFindingEmpty
33
- ).createReport().toSarif()
31
+ ).createReport()
34
32
35
33
assert (sarif.runs.first().results.isEmpty())
36
34
}
@@ -60,7 +58,7 @@ class SarifReportTest {
60
58
testSets = testSets,
61
59
generatedTestsCode = " " ,
62
60
sourceFindingEmpty
63
- ).createReport().toSarif()
61
+ ).createReport()
64
62
65
63
assert (report.runs.first().results[0 ].message.text.contains(" NullPointerException" ))
66
64
assert (report.runs.first().results[1 ].message.text.contains(" ArrayIndexOutOfBoundsException" ))
@@ -77,7 +75,7 @@ class SarifReportTest {
77
75
Mockito .`when `(mockUtExecution.path.lastOrNull()?.stmt?.javaSourceStartLineNumber).thenReturn(1337 )
78
76
Mockito .`when `(mockUtExecution.testMethodName).thenReturn(" testMain_ThrowArithmeticException" )
79
77
80
- val report = sarifReportMain.createReport().toSarif()
78
+ val report = sarifReportMain.createReport()
81
79
82
80
val result = report.runs.first().results.first()
83
81
val location = result.locations.first().physicalLocation
@@ -105,7 +103,7 @@ class SarifReportTest {
105
103
)
106
104
)
107
105
108
- val report = sarifReportMain.createReport().toSarif()
106
+ val report = sarifReportMain.createReport()
109
107
110
108
val result = report.runs.first().results.first()
111
109
assert (result.message.text.contains(" 227" ))
@@ -128,7 +126,7 @@ class SarifReportTest {
128
126
)
129
127
Mockito .`when `(mockUtExecution.stateBefore.parameters).thenReturn(listOf ())
130
128
131
- val report = sarifReportMain.createReport().toSarif()
129
+ val report = sarifReportMain.createReport()
132
130
133
131
val result = report.runs.first().results.first().codeFlows.first().threadFlows.first().locations.map {
134
132
it.location.physicalLocation
@@ -153,7 +151,7 @@ class SarifReportTest {
153
151
Mockito .`when `(mockUtExecution.stateBefore.parameters).thenReturn(listOf ())
154
152
Mockito .`when `(mockUtExecution.testMethodName).thenReturn(" testMain_ThrowArithmeticException" )
155
153
156
- val report = sarifReportMain.createReport().toSarif()
154
+ val report = sarifReportMain.createReport()
157
155
158
156
val codeFlowPhysicalLocations = report.runs[0 ].results[0 ].codeFlows[0 ].threadFlows[0 ].locations.map {
159
157
it.location.physicalLocation
@@ -177,7 +175,7 @@ class SarifReportTest {
177
175
Mockito .`when `(mockUtExecution.stateBefore.parameters).thenReturn(listOf ())
178
176
Mockito .`when `(mockUtExecution.testMethodName).thenReturn(" testMain_ThrowArithmeticException" )
179
177
180
- val report = sarifReportPrivateMain.createReport().toSarif()
178
+ val report = sarifReportPrivateMain.createReport()
181
179
182
180
val codeFlowPhysicalLocations = report.runs[0 ].results[0 ].codeFlows[0 ].threadFlows[0 ].locations.map {
183
181
it.location.physicalLocation
@@ -203,7 +201,7 @@ class SarifReportTest {
203
201
testSets = testSets,
204
202
generatedTestsCode = " " ,
205
203
sourceFindingMain
206
- ).createReport().toSarif()
204
+ ).createReport()
207
205
208
206
assert (report.runs.first().results.size == 1 ) // no duplicates
209
207
}
@@ -228,7 +226,7 @@ class SarifReportTest {
228
226
testSets = testSets,
229
227
generatedTestsCode = " " ,
230
228
sourceFindingMain
231
- ).createReport().toSarif()
229
+ ).createReport()
232
230
233
231
assert (report.runs.first().results.size == 2 ) // no results have been removed
234
232
}
@@ -257,7 +255,7 @@ class SarifReportTest {
257
255
testSets = testSets,
258
256
generatedTestsCode = " " ,
259
257
sourceFindingMain
260
- ).createReport().toSarif()
258
+ ).createReport()
261
259
262
260
assert (report.runs.first().results.size == 2 ) // no results have been removed
263
261
}
@@ -291,7 +289,7 @@ class SarifReportTest {
291
289
testSets = testSets,
292
290
generatedTestsCode = " " ,
293
291
sourceFindingMain
294
- ).createReport().toSarif()
292
+ ).createReport()
295
293
296
294
assert (report.runs.first().results.size == 1 ) // no duplicates
297
295
assert (report.runs.first().results.first().totalCodeFlowLocations() == 1 ) // with a shorter stack trace
@@ -310,8 +308,6 @@ class SarifReportTest {
310
308
Mockito .`when `(mockExecutableId.classId.name).thenReturn(" Main" )
311
309
}
312
310
313
- private fun String.toSarif (): Sarif = jacksonObjectMapper().readValue(this )
314
-
315
311
// constants
316
312
317
313
private val sourceFindingEmpty = SourceFindingStrategyDefault (
0 commit comments