@@ -107,6 +107,7 @@ import org.utbot.framework.plugin.api.UtEnumConstantModel
107
107
import org.utbot.framework.plugin.api.UtExecution
108
108
import org.utbot.framework.plugin.api.UtExecutionFailure
109
109
import org.utbot.framework.plugin.api.UtExecutionSuccess
110
+ import org.utbot.framework.plugin.api.UtExplicitlyThrownException
110
111
import org.utbot.framework.plugin.api.UtMethod
111
112
import org.utbot.framework.plugin.api.UtModel
112
113
import org.utbot.framework.plugin.api.UtNewInstanceInstrumentation
@@ -292,7 +293,8 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
292
293
// we cannot generate any assertions for constructor testing
293
294
// but we need to generate a constructor call
294
295
val constructorCall = currentExecutable as ConstructorId
295
- currentExecution!! .result
296
+ val currentExecution = currentExecution!!
297
+ currentExecution.result
296
298
.onSuccess {
297
299
methodType = SUCCESSFUL
298
300
@@ -308,15 +310,16 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
308
310
}
309
311
}
310
312
.onFailure { exception ->
311
- processExecutionFailure(exception)
313
+ processExecutionFailure(currentExecution, exception)
312
314
}
313
315
}
314
316
is BuiltinMethodId -> error(" Unexpected BuiltinMethodId $currentExecutable while generating result assertions" )
315
317
is MethodId -> {
316
318
emptyLineIfNeeded()
317
319
val method = currentExecutable as MethodId
320
+ val currentExecution = currentExecution!!
318
321
// build assertions
319
- currentExecution!! .result
322
+ currentExecution.result
320
323
.onSuccess { result ->
321
324
methodType = SUCCESSFUL
322
325
@@ -330,13 +333,13 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
330
333
}
331
334
}
332
335
.onFailure { exception ->
333
- processExecutionFailure(exception)
336
+ processExecutionFailure(currentExecution, exception)
334
337
}
335
338
}
336
339
}
337
340
}
338
341
339
- private fun processExecutionFailure (exception : Throwable ) {
342
+ private fun processExecutionFailure (execution : UtExecution , exception : Throwable ) {
340
343
val methodInvocationBlock = {
341
344
with (currentExecutable) {
342
345
when (this ) {
@@ -346,7 +349,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
346
349
}
347
350
}
348
351
349
- if (shouldTestPassWithExpectedException( exception)) {
352
+ if (shouldTestPassWithException(execution, exception)) {
350
353
testFrameworkManager.expectException(exception::class .id) {
351
354
methodInvocationBlock()
352
355
}
@@ -373,11 +376,13 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
373
376
methodInvocationBlock()
374
377
}
375
378
376
- private fun shouldTestPassWithExpectedException ( exception : Throwable ): Boolean {
379
+ private fun shouldTestPassWithException ( execution : UtExecution , exception : Throwable ): Boolean {
377
380
// tests with timeout or crash should be processed differently
378
381
if (exception is TimeoutException || exception is ConcreteExecutionFailureException ) return false
379
382
380
- return runtimeExceptionTestsBehaviour == PASS || exception !is RuntimeException
383
+ val exceptionRequiresAssert = exception !is RuntimeException || runtimeExceptionTestsBehaviour == PASS
384
+ val exceptionIsExplicit = execution.result is UtExplicitlyThrownException
385
+ return exceptionRequiresAssert || exceptionIsExplicit
381
386
}
382
387
383
388
private fun writeWarningAboutTimeoutExceeding () {
0 commit comments