Skip to content

Commit 6d7339f

Browse files
authored
Enable anonymous class test in parameterized mode #1136 (#1351)
Fix anonymous class types wrapping & enable anonymous class tests
1 parent b55fef0 commit 6d7339f

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/AnonymousClassesExampleTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import org.utbot.tests.infrastructure.TestExecution
1212
class AnonymousClassesExampleTest : UtValueTestCaseChecker(
1313
testClass = AnonymousClassesExample::class,
1414
pipelines = listOf(
15-
TestLastStage(CodegenLanguage.JAVA, lastStage = TestExecution, parameterizedModeLastStage = Compilation),
16-
TestLastStage(CodegenLanguage.KOTLIN, lastStage = TestExecution)
15+
TestLastStage(CodegenLanguage.JAVA),
16+
TestLastStage(CodegenLanguage.KOTLIN)
1717
)
1818
) {
1919
@Test

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,14 @@ data class CgMethodTestSet constructor(
127127
* A separate test set is created for each combination of modified statics.
128128
*/
129129
private fun splitExecutionsByChangedStatics(): List<CgMethodTestSet> {
130-
val executionsByStaticsUsage: Map<Set<FieldId>, List<UtExecution>> =
131-
executions.groupBy { it.stateBefore.statics.keys }
130+
val executionsByStaticsUsage = executions.groupBy { it.stateBefore.statics.keys }
132131

133-
return executionsByStaticsUsage.map { (_, executions) -> substituteExecutions(executions) }
132+
val executionsByStaticsUsageAndTheirTypes = executionsByStaticsUsage
133+
.flatMap { (_, executions) ->
134+
executions.groupBy { it.stateBefore.statics.values.map { model -> model.classId } }.values
135+
}
136+
137+
return executionsByStaticsUsageAndTheirTypes.map { executions -> substituteExecutions(executions) }
134138
}
135139

136140
/**

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ import org.utbot.framework.plugin.api.util.fieldClassId
7373
import org.utbot.framework.plugin.api.util.isPrimitive
7474
import org.utbot.framework.plugin.api.util.methodClassId
7575
import org.utbot.framework.plugin.api.util.denotableType
76+
import org.utbot.framework.plugin.api.util.supertypeOfAnonymousClass
7677
import java.lang.reflect.Constructor
7778
import java.lang.reflect.Method
7879
import kotlin.reflect.KFunction
@@ -484,7 +485,13 @@ internal class CgStatementConstructorImpl(context: CgContext) :
484485
}
485486

486487
override fun wrapTypeIfRequired(baseType: ClassId): ClassId =
487-
if (baseType.isAccessibleFrom(testClassPackageName)) baseType else objectClassId
488+
when {
489+
baseType.isAccessibleFrom(testClassPackageName) -> baseType
490+
baseType.isAnonymous && baseType.supertypeOfAnonymousClass.isAccessibleFrom(testClassPackageName) ->
491+
baseType.supertypeOfAnonymousClass
492+
493+
else -> objectClassId
494+
}
488495

489496
// utils
490497

0 commit comments

Comments
 (0)