@@ -45,7 +45,7 @@ class SpringTestClassModelBuilder(val context: CgContext): TestClassModelBuilder
4545 private fun collectModelsForClassVariables (testSets : List <CgMethodTestSet >): SpringSpecificInformation {
4646 val thisInstanceModels = mutableSetOf<UtModelWrapper >()
4747 val thisInstancesDependentModels = mutableSetOf<UtModelWrapper >()
48- val applicationContextModels = mutableSetOf<UtModelWrapper >()
48+ val stateBeforeDependentModels = mutableSetOf<UtModelWrapper >()
4949
5050 with (context) {
5151 for ((testSetIndex, testSet) in testSets.withIndex()) {
@@ -56,16 +56,13 @@ class SpringTestClassModelBuilder(val context: CgContext): TestClassModelBuilder
5656 .filterNotNull()
5757 .forEach { model ->
5858 thisInstanceModels + = model.wrap()
59- thisInstancesDependentModels + = collectByThisInstanceModel (model)
59+ thisInstancesDependentModels + = collectByModel (model)
6060
6161 }
62- // TODO: собрать рекурснивно все модели, как в моках, и из них уже выбрать что надо
63- execution.stateBefore.parameters + setOf (execution.stateBefore.thisInstance)
64- .filterNotNull()
65- .forEach { model ->
66- applicationContextModels + = collectApplicationContextModels(model)
67- }
6862
63+ (execution.stateBefore.parameters + setOf (execution.stateBefore.thisInstance))
64+ .filterNotNull()
65+ .forEach { model -> stateBeforeDependentModels + = collectByModel(model) }
6966 }
7067 }
7168 }
@@ -78,14 +75,18 @@ class SpringTestClassModelBuilder(val context: CgContext): TestClassModelBuilder
7875 cgModel.model.isMockModel() && cgModel !in thisInstanceModels
7976 }
8077
78+ val applicationContextModels = stateBeforeDependentModels
79+ .filter { it.model is UtSpringContextModel }
80+ .toSet()
81+
8182 return SpringSpecificInformation (
8283 thisInstanceModels.groupByClassId(),
8384 dependentMockModels.groupByClassId(),
84- mapOf (applicationContextClassId to applicationContextModels),
85+ applicationContextModels.groupByClassId( ),
8586 )
8687 }
8788
88- private fun collectByThisInstanceModel (model : UtModel ): Set <UtModelWrapper > {
89+ private fun collectByModel (model : UtModel ): Set <UtModelWrapper > {
8990 val dependentModels = mutableSetOf<UtModelWrapper >()
9091 collectRecursively(model, dependentModels)
9192
@@ -147,21 +148,4 @@ class SpringTestClassModelBuilder(val context: CgContext): TestClassModelBuilder
147148 // Python, JavaScript, Go models are not required in Spring
148149 }
149150 }
150-
151- private fun collectApplicationContextModels (model : UtModel ): Set <UtModelWrapper > {
152- if (model !is UtAssembleModel ) {
153- return emptySet()
154- }
155-
156- with (context) {
157- val innerModels = mutableSetOf<UtModel >()
158- model.instantiationCall.instance?.let { innerModels + = it }
159- model.modificationsChain.mapNotNull { it.instance }.forEach { innerModels + = it }
160-
161- return innerModels
162- .filterIsInstance<UtSpringContextModel >()
163- .map { it.wrap() }
164- .toSet()
165- }
166- }
167151}
0 commit comments