@@ -568,17 +568,19 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte
568
568
expected : CgVariable ? ,
569
569
actual : CgVariable ,
570
570
depth : Int ,
571
- visitedModels : MutableSet <UtModel >,
571
+ visitedModels : MutableSet <ModelWithField >,
572
+ expectedModelField : FieldId ? = null,
572
573
) {
573
- if (expectedModel in visitedModels) return
574
+ val modelWithField = ModelWithField (expectedModel, expectedModelField)
575
+ if (modelWithField in visitedModels) return
574
576
575
577
var expected = expected
576
578
if (expected == null ) {
577
579
require(! needExpectedDeclaration(expectedModel))
578
580
expected = actual
579
581
}
580
582
581
- visitedModels + = expectedModel
583
+ visitedModels + = modelWithField
582
584
583
585
with (testFrameworkManager) {
584
586
if (depth >= DEEP_EQUALS_MAX_DEPTH ) {
@@ -897,7 +899,7 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte
897
899
expected : CgVariable ,
898
900
actual : CgVariable ,
899
901
depth : Int ,
900
- visitedModels : MutableSet <UtModel >
902
+ visitedModels : MutableSet <ModelWithField >
901
903
) {
902
904
// if field is static, it is represents itself in "before" and
903
905
// "after" state: no need to assert its equality to itself.
@@ -906,7 +908,8 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte
906
908
}
907
909
908
910
// if model is already processed, so we don't want to add new statements
909
- if (fieldModel in visitedModels) {
911
+ val modelWithField = ModelWithField (fieldModel, fieldId)
912
+ if (modelWithField in visitedModels) {
910
913
currentBlock + = testFrameworkManager.getDeepEqualsAssertion(expected, actual).toStatement()
911
914
return
912
915
}
@@ -928,7 +931,7 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte
928
931
expected : CgVariable ,
929
932
actual : CgVariable ,
930
933
depth : Int ,
931
- visitedModels : MutableSet <UtModel >
934
+ visitedModels : MutableSet <ModelWithField >
932
935
) {
933
936
// fieldModel is not visited and will be marked in assertDeepEquals call
934
937
val fieldName = fieldId.name
@@ -950,6 +953,7 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte
950
953
actualFieldDeclaration.variable,
951
954
depth + 1 ,
952
955
visitedModels,
956
+ fieldId,
953
957
)
954
958
emptyLineIfNeeded()
955
959
}
@@ -960,7 +964,7 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte
960
964
expected : CgVariable ,
961
965
actual : CgVariable ,
962
966
depth : Int ,
963
- visitedModels : MutableSet <UtModel >
967
+ visitedModels : MutableSet <ModelWithField >
964
968
) {
965
969
val fieldResultModels = fieldsOfExecutionResults[fieldId to depth]
966
970
val nullResultModelInExecutions = fieldResultModels?.find { it.isNull() }
@@ -999,6 +1003,7 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte
999
1003
actualFieldDeclaration.variable,
1000
1004
depth + 1 ,
1001
1005
visitedModels,
1006
+ fieldId,
1002
1007
)
1003
1008
}
1004
1009
)
@@ -1009,6 +1014,7 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte
1009
1014
actualFieldDeclaration.variable,
1010
1015
depth + 1 ,
1011
1016
visitedModels,
1017
+ fieldId,
1012
1018
)
1013
1019
}
1014
1020
emptyLineIfNeeded()
@@ -1270,6 +1276,14 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte
1270
1276
.onFailure { exception -> processExecutionFailure(exception, executionResult) }
1271
1277
}
1272
1278
1279
+ // Class is required to verify, if current model has already been analyzed in deepEquals.
1280
+ // Using model without related field (if it is present) in comparison is incorrect,
1281
+ // for example, for [UtNullModel] as they are equal to each other..
1282
+ private data class ModelWithField (
1283
+ val fieldModel : UtModel ,
1284
+ val relatedField : FieldId ? ,
1285
+ )
1286
+
1273
1287
/* *
1274
1288
* We can't use standard deepEquals method in parametrized tests
1275
1289
* because nullable objects require different asserts.
0 commit comments