Skip to content

Commit 096fda1

Browse files
Enlarge ModelId in codegen with testSetId (#2059)
1 parent de91104 commit 096fda1

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/domain/Domain.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -780,13 +780,16 @@ object SpringBoot : DependencyInjectionFramework(
780780
/**
781781
* Extended id of [UtModel], unique for whole test set.
782782
*
783-
* Allows to distinguish models from different executions,
784-
* even if they have the same value of `UtModel.id`.
783+
* Allows distinguishing models from different executions and test sets,
784+
* even if they have the same value of `UtModel.id` that is allowed.
785785
*/
786-
data class ModelId(
786+
data class ModelId private constructor(
787787
private val id: Int?,
788788
private val executionId: Int,
789-
)
790-
791-
fun UtModel.withExecutionId(executionId: Int = -1) = ModelId(this.idOrNull(), executionId)
789+
private val testSetId: Int,
790+
) {
791+
companion object {
792+
fun create(model: UtModel, executionId: Int = -1, testSetId: Int = -1) = ModelId(model.idOrNull(), executionId, testSetId)
793+
}
794+
}
792795

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/domain/context/CgContext.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import org.utbot.framework.codegen.domain.builtin.UtilClassFileMethodProvider
3030
import org.utbot.framework.codegen.domain.builtin.UtilMethodProvider
3131
import org.utbot.framework.codegen.domain.models.SimpleTestClassModel
3232
import org.utbot.framework.codegen.domain.models.CgParameterKind
33-
import org.utbot.framework.codegen.domain.withExecutionId
3433
import org.utbot.framework.codegen.services.access.Block
3534
import org.utbot.framework.codegen.tree.EnvironmentFieldStateCache
3635
import org.utbot.framework.codegen.tree.importIfNeeded
@@ -571,7 +570,7 @@ data class CgContext(
571570
}
572571
}
573572

574-
override fun getIdByModel(model: UtModel): ModelId = modelIds.getOrPut(model) { model.withExecutionId() }
573+
override fun getIdByModel(model: UtModel): ModelId = modelIds.getOrPut(model) { ModelId.create(model) }
575574

576575
private fun createClassIdForNestedClass(testClassModel: SimpleTestClassModel): ClassId {
577576
val simpleName = "${testClassModel.classUnderTest.simpleName}Test"

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/domain/models/builders/SpringTestClassModelBuilder.kt

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package org.utbot.framework.codegen.domain.models.builders
22

3+
import org.utbot.framework.codegen.domain.ModelId
34
import org.utbot.framework.codegen.domain.context.CgContext
45
import org.utbot.framework.codegen.domain.models.CgMethodTestSet
56
import org.utbot.framework.codegen.domain.models.ClassModels
67
import org.utbot.framework.codegen.domain.models.SpringTestClassModel
7-
import org.utbot.framework.codegen.domain.withExecutionId
88
import org.utbot.framework.plugin.api.ClassId
99
import org.utbot.framework.plugin.api.UtArrayModel
1010
import org.utbot.framework.plugin.api.UtAssembleModel
@@ -39,17 +39,15 @@ class SpringTestClassModelBuilder(val context: CgContext): TestClassModelBuilder
3939
val thisInstances = mutableSetOf<UtModel>()
4040
val thisInstancesDependentModels = mutableSetOf<UtModel>()
4141

42-
for (testSet in testSets) {
43-
for ((index, execution) in testSet.executions.withIndex()) {
44-
execution.stateBefore.thisInstance?.let { model ->
45-
thisInstances += model
46-
thisInstancesDependentModels += collectByThisInstanceModel(model, index)
47-
}
42+
for ((testSetIndex, testSet) in testSets.withIndex()) {
43+
for ((executionIndex, execution) in testSet.executions.withIndex()) {
4844

49-
execution.stateAfter.thisInstance?.let { model ->
50-
thisInstances += model
51-
thisInstancesDependentModels += collectByThisInstanceModel(model, index)
52-
}
45+
setOf(execution.stateBefore.thisInstance, execution.stateAfter.thisInstance)
46+
.filterNotNull()
47+
.forEach { model ->
48+
thisInstances += model
49+
thisInstancesDependentModels += collectByThisInstanceModel(model, executionIndex, testSetIndex)
50+
}
5351
}
5452
}
5553

@@ -59,14 +57,14 @@ class SpringTestClassModelBuilder(val context: CgContext): TestClassModelBuilder
5957
return thisInstances.groupByClassId() to dependentMockModels.groupByClassId()
6058
}
6159

62-
private fun collectByThisInstanceModel(model: UtModel, executionIndex: Int): Set<UtModel> {
63-
context.modelIds[model] = model.withExecutionId(executionIndex)
60+
private fun collectByThisInstanceModel(model: UtModel, executionIndex: Int, testSetIndex: Int): Set<UtModel> {
61+
context.modelIds[model] = ModelId.create(model, executionIndex, testSetIndex)
6462

6563
val dependentModels = mutableSetOf<UtModel>()
6664
collectRecursively(model, dependentModels)
6765

6866
dependentModels.forEach { model ->
69-
context.modelIds[model] = model.withExecutionId(executionIndex)
67+
context.modelIds[model] = ModelId.create(model, executionIndex, testSetIndex)
7068
}
7169

7270
return dependentModels

0 commit comments

Comments
 (0)