@@ -107,6 +107,7 @@ import org.utbot.framework.plugin.api.UtEnumConstantModel
107107import org.utbot.framework.plugin.api.UtExecution
108108import org.utbot.framework.plugin.api.UtExecutionFailure
109109import org.utbot.framework.plugin.api.UtExecutionSuccess
110+ import org.utbot.framework.plugin.api.UtExplicitlyThrownException
110111import org.utbot.framework.plugin.api.UtMethod
111112import org.utbot.framework.plugin.api.UtModel
112113import org.utbot.framework.plugin.api.UtNewInstanceInstrumentation
@@ -292,7 +293,8 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
292293 // we cannot generate any assertions for constructor testing
293294 // but we need to generate a constructor call
294295 val constructorCall = currentExecutable as ConstructorId
295- currentExecution!! .result
296+ val currentExecution = currentExecution!!
297+ currentExecution.result
296298 .onSuccess {
297299 methodType = SUCCESSFUL
298300
@@ -308,15 +310,16 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
308310 }
309311 }
310312 .onFailure { exception ->
311- processExecutionFailure(exception)
313+ processExecutionFailure(currentExecution, exception)
312314 }
313315 }
314316 is BuiltinMethodId -> error(" Unexpected BuiltinMethodId $currentExecutable while generating result assertions" )
315317 is MethodId -> {
316318 emptyLineIfNeeded()
317319 val method = currentExecutable as MethodId
320+ val currentExecution = currentExecution!!
318321 // build assertions
319- currentExecution!! .result
322+ currentExecution.result
320323 .onSuccess { result ->
321324 methodType = SUCCESSFUL
322325
@@ -330,13 +333,13 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
330333 }
331334 }
332335 .onFailure { exception ->
333- processExecutionFailure(exception)
336+ processExecutionFailure(currentExecution, exception)
334337 }
335338 }
336339 }
337340 }
338341
339- private fun processExecutionFailure (exception : Throwable ) {
342+ private fun processExecutionFailure (execution : UtExecution , exception : Throwable ) {
340343 val methodInvocationBlock = {
341344 with (currentExecutable) {
342345 when (this ) {
@@ -346,7 +349,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
346349 }
347350 }
348351
349- if (shouldTestPassWithExpectedException( exception)) {
352+ if (shouldTestPassWithException(execution, exception)) {
350353 testFrameworkManager.expectException(exception::class .id) {
351354 methodInvocationBlock()
352355 }
@@ -373,11 +376,13 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
373376 methodInvocationBlock()
374377 }
375378
376- private fun shouldTestPassWithExpectedException ( exception : Throwable ): Boolean {
379+ private fun shouldTestPassWithException ( execution : UtExecution , exception : Throwable ): Boolean {
377380 // tests with timeout or crash should be processed differently
378381 if (exception is TimeoutException || exception is ConcreteExecutionFailureException ) return false
379382
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
381386 }
382387
383388 private fun writeWarningAboutTimeoutExceeding () {
0 commit comments