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