Skip to content

Commit 4a28360

Browse files
committed
Fix duplication of nested testclasses
* also fix naming of outermost testclass to correspond to generated file's name
1 parent 1c44797 commit 4a28360

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ internal data class CgContext(
449449

450450
override val outerMostTestClass: ClassId by lazy {
451451
val packagePrefix = if (testClassPackageName.isNotEmpty()) "$testClassPackageName." else ""
452-
val simpleName = testClassCustomName ?: "${createTestClassName(classUnderTest.name)}Test"
452+
val simpleName = testClassCustomName ?: "${createTestClassName(classUnderTest.simpleName)}Test"
453453
val name = "$packagePrefix$simpleName"
454454
BuiltinClassId(
455455
name = name,

0 commit comments

Comments
 (0)