Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import org.utbot.framework.plugin.api.UtNullModel
import org.utbot.framework.plugin.api.UtPrimitiveModel
import org.utbot.framework.plugin.api.UtVoidModel
import org.utbot.framework.plugin.api.isMockModel
import org.utbot.framework.plugin.api.UtStatementCallModel
import org.utbot.framework.plugin.api.UtDirectSetFieldModel
import org.utbot.framework.plugin.api.util.SpringModelUtils.isAutowiredFromContext
import org.utbot.framework.plugin.api.canBeSpied

Expand Down Expand Up @@ -59,7 +61,7 @@ class SpringTestClassModelBuilder(val context: CgContext) :

(execution.stateBefore.parameters + execution.stateBefore.thisInstance)
.filterNotNull()
.forEach { model -> stateBeforeDependentModels += collectDependentModels(model) }
.forEach { model -> stateBeforeDependentModels += collectAutowiredModels(model) }
}
}
}
Expand Down Expand Up @@ -88,11 +90,24 @@ class SpringTestClassModelBuilder(val context: CgContext) :
)
}

private fun collectAutowiredModels(model: UtModel): Set<UtModelWrapper> {
val allDependentModels = mutableSetOf<UtModelWrapper>()

collectRecursively(model, allDependentModels)

return allDependentModels
}

private fun collectRecursively(model: UtModel, allDependentModels: MutableSet<UtModelWrapper>){
if(!allDependentModels.add(model.wrap())){
return
}
collectDependentModels(model).forEach { collectRecursively(it.model, allDependentModels) }
}

private fun collectDependentModels(model: UtModel): Set<UtModelWrapper> {
val dependentModels = mutableSetOf<UtModelWrapper>()

dependentModels.add(model.wrap())

when (model) {
is UtNullModel,
is UtPrimitiveModel,
Expand All @@ -118,6 +133,16 @@ class SpringTestClassModelBuilder(val context: CgContext) :
is UtAssembleModel -> {
model.instantiationCall.instance?.let { dependentModels.add(it.wrap()) }
model.instantiationCall.params.forEach { dependentModels.add(it.wrap()) }

if(model.isAutowiredFromContext()) {
model.modificationsChain.forEach { stmt ->
stmt.instance?.let { dependentModels.add(it.wrap()) }
when (stmt) {
is UtStatementCallModel -> stmt.params.forEach { dependentModels.add(it.wrap()) }
is UtDirectSetFieldModel -> dependentModels.add(stmt.fieldModel.wrap())
}
}
}
}
}

Expand Down