@@ -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.
@@ -1258,9 +1262,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
1258
1262
currentMethodParameters[CgParameterKind .Argument (index)] = argument.parameter
1259
1263
}
1260
1264
1261
- val method = currentExecutable as MethodId
1262
- val containsFailureExecution = containsFailureExecution(testSet)
1263
-
1265
+ val method = currentExecutable!!
1264
1266
val expectedResultClassId = wrapTypeIfRequired(method.returnType)
1265
1267
1266
1268
if (expectedResultClassId != voidClassId) {
@@ -1278,6 +1280,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
1278
1280
currentMethodParameters[CgParameterKind .ExpectedResult ] = expectedResult.parameter
1279
1281
}
1280
1282
1283
+ val containsFailureExecution = containsFailureExecution(testSet)
1281
1284
if (containsFailureExecution) {
1282
1285
val classClassId = Class ::class .id
1283
1286
val expectedException = CgParameterDeclaration (
@@ -1343,7 +1346,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
1343
1346
arguments + = variableConstructor.getOrCreateVariable(paramModel, argumentName)
1344
1347
}
1345
1348
1346
- val method = currentExecutable as MethodId
1349
+ val method = currentExecutable!!
1347
1350
val needsReturnValue = method.returnType != voidClassId
1348
1351
val containsFailureExecution = containsFailureExecution(testSet)
1349
1352
execution.result
0 commit comments