Skip to content

Commit b7b18b9

Browse files
authored
Fix duplication of nested testclasses #779 (#780)
Fix duplication of nested testclasses #779 * also fix naming of outermost testclass to correspond to generated file's name
1 parent f578c21 commit b7b18b9

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/TestClassModel.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ data class TestClassModel(
2020
val class2methodTestSets = testSets.groupBy { it.executableId.classId }
2121

2222
val classesWithMethodsUnderTest = testSets
23-
.distinctBy { it.executableId.classId }
2423
.map { it.executableId.classId }
24+
.distinct()
2525

2626
// For each class stores list of its "direct" nested classes
27-
val class2nestedClasses = mutableMapOf<ClassId, MutableList<ClassId>>()
27+
val class2nestedClasses = mutableMapOf<ClassId, MutableSet<ClassId>>()
2828

2929
for (classId in classesWithMethodsUnderTest) {
3030
var currentClass = classId
3131
var enclosingClass = currentClass.enclosingClass
3232
// while we haven't reached the top of nested class hierarchy or the main class under test
3333
while (enclosingClass != null && currentClass != classUnderTest) {
34-
class2nestedClasses.getOrPut(enclosingClass) { mutableListOf() } += currentClass
34+
class2nestedClasses.getOrPut(enclosingClass) { mutableSetOf() } += currentClass
3535
currentClass = enclosingClass
3636
enclosingClass = enclosingClass.enclosingClass
3737
}
@@ -42,7 +42,7 @@ data class TestClassModel(
4242
private fun constructRecursively(
4343
clazz: ClassId,
4444
class2methodTestSets: Map<ClassId, List<CgMethodTestSet>>,
45-
class2nestedClasses: Map<ClassId, List<ClassId>>
45+
class2nestedClasses: Map<ClassId, Set<ClassId>>
4646
): TestClassModel {
4747
val currentNestedClasses = class2nestedClasses.getOrDefault(clazz, listOf())
4848
val currentMethodTestSets = class2methodTestSets.getOrDefault(clazz, listOf())

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import org.utbot.framework.codegen.model.tree.CgTestMethod
3333
import org.utbot.framework.codegen.model.tree.CgThisInstance
3434
import org.utbot.framework.codegen.model.tree.CgValue
3535
import org.utbot.framework.codegen.model.tree.CgVariable
36-
import org.utbot.framework.codegen.model.util.createTestClassName
3736
import java.util.IdentityHashMap
3837
import kotlinx.collections.immutable.PersistentList
3938
import kotlinx.collections.immutable.PersistentMap
@@ -449,7 +448,7 @@ internal data class CgContext(
449448

450449
override val outerMostTestClass: ClassId by lazy {
451450
val packagePrefix = if (testClassPackageName.isNotEmpty()) "$testClassPackageName." else ""
452-
val simpleName = testClassCustomName ?: "${createTestClassName(classUnderTest.name)}Test"
451+
val simpleName = testClassCustomName ?: "${classUnderTest.simpleName}Test"
453452
val name = "$packagePrefix$simpleName"
454453
BuiltinClassId(
455454
name = name,

0 commit comments

Comments
 (0)