@@ -284,30 +284,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
284
284
*/
285
285
private fun generateResultAssertions () {
286
286
when (currentExecutable) {
287
- is ConstructorId -> {
288
- // we cannot generate any assertions for constructor testing
289
- // but we need to generate a constructor call
290
- val constructorCall = currentExecutable as ConstructorId
291
- val currentExecution = currentExecution!!
292
- currentExecution.result
293
- .onSuccess {
294
- methodType = SUCCESSFUL
295
-
296
- // TODO engine returns UtCompositeModel sometimes (concrete execution?)
297
-
298
- // TODO support inner classes constructors testing JIRA:1461
299
- require(! constructorCall.classId.isInner) {
300
- " Inner class ${constructorCall.classId} constructor testing is not supported yet"
301
- }
302
-
303
- actual = newVar(constructorCall.classId, " actual" ) {
304
- constructorCall(* methodArguments.toTypedArray())
305
- }
306
- }
307
- .onFailure { exception ->
308
- processExecutionFailure(currentExecution, exception)
309
- }
310
- }
287
+ is ConstructorId -> generateConstructorCall(currentExecutable!! , currentExecution!! )
311
288
is BuiltinMethodId -> error(" Unexpected BuiltinMethodId $currentExecutable while generating result assertions" )
312
289
is MethodId -> {
313
290
emptyLineIfNeeded()
@@ -434,24 +411,30 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
434
411
*/
435
412
private fun generateAssertionsForParameterizedTest () {
436
413
emptyLineIfNeeded()
437
- val method = currentExecutable as MethodId
438
- currentExecution!! .result
439
- .onSuccess { result ->
440
- if (result.isUnit()) {
441
- + thisInstance[method](* methodArguments.toTypedArray())
442
- } else {
443
- // "generic" expected variable is represented with a wrapper if
444
- // actual result is primitive to support cases with exceptions.
445
- resultModel = if (result is UtPrimitiveModel ) assemble(result) else result
446
414
447
- val expectedVariable = currentMethodParameters[CgParameterKind .ExpectedResult ]!!
448
- val expectedExpression = CgNotNullAssertion (expectedVariable)
415
+ when (currentExecutable) {
416
+ is ConstructorId -> generateConstructorCall(currentExecutable!! , currentExecution!! )
417
+ is MethodId -> {
418
+ val method = currentExecutable as MethodId
419
+ currentExecution!! .result
420
+ .onSuccess { result ->
421
+ if (result.isUnit()) {
422
+ + thisInstance[method](* methodArguments.toTypedArray())
423
+ } else {
424
+ // "generic" expected variable is represented with a wrapper if
425
+ // actual result is primitive to support cases with exceptions.
426
+ resultModel = if (result is UtPrimitiveModel ) assemble(result) else result
449
427
450
- assertEquality(expectedExpression, actual)
451
- println ()
452
- }
428
+ val expectedVariable = currentMethodParameters[CgParameterKind .ExpectedResult ]!!
429
+ val expectedExpression = CgNotNullAssertion (expectedVariable)
430
+
431
+ assertEquality(expectedExpression, actual)
432
+ println ()
433
+ }
434
+ }
435
+ .onFailure { thisInstance[method](* methodArguments.toTypedArray()).intercepted() }
453
436
}
454
- .onFailure { thisInstance[method]( * methodArguments.toTypedArray()).intercepted() }
437
+ }
455
438
}
456
439
457
440
/* *
@@ -1024,6 +1007,27 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
1024
1007
generateDeepEqualsOrNullAssertion(expected.expression, actual)
1025
1008
}
1026
1009
1010
+ private fun generateConstructorCall (currentExecutableId : ExecutableId , currentExecution : UtExecution ) {
1011
+ // we cannot generate any assertions for constructor testing
1012
+ // but we need to generate a constructor call
1013
+ val constructorCall = currentExecutableId as ConstructorId
1014
+ currentExecution.result
1015
+ .onSuccess {
1016
+ methodType = SUCCESSFUL
1017
+
1018
+ require(! constructorCall.classId.isInner) {
1019
+ " Inner class ${constructorCall.classId} constructor testing is not supported yet"
1020
+ }
1021
+
1022
+ actual = newVar(constructorCall.classId, " actual" ) {
1023
+ constructorCall(* methodArguments.toTypedArray())
1024
+ }
1025
+ }
1026
+ .onFailure { exception ->
1027
+ processExecutionFailure(currentExecution, exception)
1028
+ }
1029
+ }
1030
+
1027
1031
/* *
1028
1032
* We can't use standard deepEquals method in parametrized tests
1029
1033
* because nullable objects require different asserts.
@@ -1264,9 +1268,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
1264
1268
currentMethodParameters[CgParameterKind .Argument (index)] = argument.parameter
1265
1269
}
1266
1270
1267
- val method = currentExecutable as MethodId
1268
- val containsFailureExecution = containsFailureExecution(testSet)
1269
-
1271
+ val method = currentExecutable!!
1270
1272
val expectedResultClassId = wrapTypeIfRequired(method.returnType)
1271
1273
1272
1274
if (expectedResultClassId != voidClassId) {
@@ -1284,6 +1286,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
1284
1286
currentMethodParameters[CgParameterKind .ExpectedResult ] = expectedResult.parameter
1285
1287
}
1286
1288
1289
+ val containsFailureExecution = containsFailureExecution(testSet)
1287
1290
if (containsFailureExecution) {
1288
1291
val classClassId = Class ::class .id
1289
1292
val expectedException = CgParameterDeclaration (
@@ -1349,7 +1352,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
1349
1352
arguments + = variableConstructor.getOrCreateVariable(paramModel, argumentName)
1350
1353
}
1351
1354
1352
- val method = currentExecutable as MethodId
1355
+ val method = currentExecutable!!
1353
1356
val needsReturnValue = method.returnType != voidClassId
1354
1357
val containsFailureExecution = containsFailureExecution(testSet)
1355
1358
execution.result
0 commit comments