@@ -284,30 +284,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
284284 */
285285 private fun generateResultAssertions () {
286286 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!! )
311288 is BuiltinMethodId -> error(" Unexpected BuiltinMethodId $currentExecutable while generating result assertions" )
312289 is MethodId -> {
313290 emptyLineIfNeeded()
@@ -434,24 +411,30 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
434411 */
435412 private fun generateAssertionsForParameterizedTest () {
436413 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
446414
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
449427
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() }
453436 }
454- .onFailure { thisInstance[method]( * methodArguments.toTypedArray()).intercepted() }
437+ }
455438 }
456439
457440 /* *
@@ -1024,6 +1007,27 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
10241007 generateDeepEqualsOrNullAssertion(expected.expression, actual)
10251008 }
10261009
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+
10271031 /* *
10281032 * We can't use standard deepEquals method in parametrized tests
10291033 * because nullable objects require different asserts.
@@ -1264,9 +1268,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
12641268 currentMethodParameters[CgParameterKind .Argument (index)] = argument.parameter
12651269 }
12661270
1267- val method = currentExecutable as MethodId
1268- val containsFailureExecution = containsFailureExecution(testSet)
1269-
1271+ val method = currentExecutable!!
12701272 val expectedResultClassId = wrapTypeIfRequired(method.returnType)
12711273
12721274 if (expectedResultClassId != voidClassId) {
@@ -1284,6 +1286,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
12841286 currentMethodParameters[CgParameterKind .ExpectedResult ] = expectedResult.parameter
12851287 }
12861288
1289+ val containsFailureExecution = containsFailureExecution(testSet)
12871290 if (containsFailureExecution) {
12881291 val classClassId = Class ::class .id
12891292 val expectedException = CgParameterDeclaration (
@@ -1349,7 +1352,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
13491352 arguments + = variableConstructor.getOrCreateVariable(paramModel, argumentName)
13501353 }
13511354
1352- val method = currentExecutable as MethodId
1355+ val method = currentExecutable!!
13531356 val needsReturnValue = method.returnType != voidClassId
13541357 val containsFailureExecution = containsFailureExecution(testSet)
13551358 execution.result
0 commit comments