Skip to content

Commit 290b930

Browse files
Refactor CgTestClassConstructor for Spring properties (#1783)
1 parent 1ed6efa commit 290b930

File tree

16 files changed

+220
-197
lines changed

16 files changed

+220
-197
lines changed

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/CodeGenerator.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import org.utbot.framework.codegen.domain.models.TestClassModel
1212
import org.utbot.framework.codegen.domain.context.CgContext
1313
import org.utbot.framework.codegen.renderer.CgAbstractRenderer
1414
import org.utbot.framework.codegen.reports.TestsGenerationReport
15-
import org.utbot.framework.codegen.tree.CgTestClassConstructor
15+
import org.utbot.framework.codegen.tree.CgSimpleTestClassConstructor
1616
import org.utbot.framework.codegen.tree.ututils.UtilClassKind
1717
import org.utbot.framework.codegen.services.language.CgLanguageAssistant
1818
import org.utbot.framework.plugin.api.ClassId
@@ -73,7 +73,7 @@ open class CodeGenerator(
7373
val cgTestSets = testSets.map { CgMethodTestSet(it) }.toList()
7474
return withCustomContext(testClassCustomName) {
7575
context.withTestClassFileScope {
76-
val astConstructor = CgTestClassConstructor(context)
76+
val astConstructor = CgSimpleTestClassConstructor(context)
7777
val renderer = CgAbstractRenderer.makeRenderer(context)
7878
val testClassModel = TestClassModel.fromTestSets(classUnderTest, cgTestSets)
7979

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/services/access/CgCallableAccessManager.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import org.utbot.framework.codegen.domain.models.CgThisInstance
2626
import org.utbot.framework.codegen.domain.models.CgValue
2727
import org.utbot.framework.codegen.domain.models.CgVariable
2828
import org.utbot.framework.codegen.services.access.CgCallableAccessManagerImpl.FieldAccessorSuitability.*
29-
import org.utbot.framework.codegen.tree.CgTestClassConstructor.CgComponents.getStatementConstructorBy
30-
import org.utbot.framework.codegen.tree.CgTestClassConstructor.CgComponents.getVariableConstructorBy
29+
import org.utbot.framework.codegen.tree.CgComponents.getStatementConstructorBy
30+
import org.utbot.framework.codegen.tree.CgComponents.getVariableConstructorBy
3131
import org.utbot.framework.codegen.tree.getAmbiguousOverloadsOf
3232
import org.utbot.framework.codegen.tree.importIfNeeded
3333
import org.utbot.framework.codegen.tree.isUtil

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/services/access/CgFieldStateManager.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import org.utbot.framework.codegen.domain.models.CgExpression
88
import org.utbot.framework.codegen.domain.models.CgGetJavaClass
99
import org.utbot.framework.codegen.domain.models.CgValue
1010
import org.utbot.framework.codegen.domain.models.CgVariable
11+
import org.utbot.framework.codegen.tree.CgComponents.getCallableAccessManagerBy
12+
import org.utbot.framework.codegen.tree.CgComponents.getStatementConstructorBy
1113
import org.utbot.framework.codegen.tree.CgFieldState
1214
import org.utbot.framework.codegen.tree.CgStatementConstructor
13-
import org.utbot.framework.codegen.tree.CgTestClassConstructor.CgComponents.getCallableAccessManagerBy
14-
import org.utbot.framework.codegen.tree.CgTestClassConstructor.CgComponents.getStatementConstructorBy
1515
import org.utbot.framework.codegen.tree.FieldStateCache
1616
import org.utbot.framework.codegen.tree.classCgClassId
1717
import org.utbot.framework.codegen.tree.getFieldVariableName

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/services/framework/MockFrameworkManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ import org.utbot.framework.codegen.domain.models.CgValue
3939
import org.utbot.framework.codegen.domain.models.CgVariable
4040
import org.utbot.framework.codegen.services.access.CgCallableAccessManager
4141
import org.utbot.framework.codegen.services.access.CgCallableAccessManagerImpl
42+
import org.utbot.framework.codegen.tree.CgComponents.getVariableConstructorBy
4243
import org.utbot.framework.codegen.tree.CgStatementConstructor
4344
import org.utbot.framework.codegen.tree.CgStatementConstructorImpl
44-
import org.utbot.framework.codegen.tree.CgTestClassConstructor.CgComponents.getVariableConstructorBy
4545
import org.utbot.framework.codegen.tree.CgVariableConstructor
4646
import org.utbot.framework.codegen.tree.hasAmbiguousOverloadsOf
4747
import org.utbot.framework.codegen.util.isAccessibleFrom

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/services/framework/TestFrameworkManager.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import org.utbot.framework.codegen.domain.models.CgSingleArgAnnotation
2222
import org.utbot.framework.codegen.domain.models.CgValue
2323
import org.utbot.framework.codegen.domain.models.CgVariable
2424
import org.utbot.framework.codegen.services.access.CgCallableAccessManager
25-
import org.utbot.framework.codegen.tree.CgTestClassConstructor.CgComponents.getCallableAccessManagerBy
26-
import org.utbot.framework.codegen.tree.CgTestClassConstructor.CgComponents.getStatementConstructorBy
25+
import org.utbot.framework.codegen.tree.CgComponents.getCallableAccessManagerBy
26+
import org.utbot.framework.codegen.tree.CgComponents.getStatementConstructorBy
2727
import org.utbot.framework.codegen.tree.addToListMethodId
2828
import org.utbot.framework.codegen.tree.argumentsClassId
2929
import org.utbot.framework.codegen.tree.argumentsMethodId
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package org.utbot.framework.codegen.tree
2+
3+
import org.utbot.framework.codegen.domain.context.CgContext
4+
import org.utbot.framework.codegen.services.CgNameGenerator
5+
import org.utbot.framework.codegen.services.access.CgCallableAccessManager
6+
import org.utbot.framework.codegen.services.framework.MockFrameworkManager
7+
import org.utbot.framework.codegen.services.framework.TestFrameworkManager
8+
9+
object CgComponents {
10+
11+
/**
12+
* Clears all stored data for current [CgContext].
13+
* As far as context is created per class under test,
14+
* no related data is required after it's processing.
15+
*/
16+
fun clearContextRelatedStorage() {
17+
nameGenerators.clear()
18+
statementConstructors.clear()
19+
callableAccessManagers.clear()
20+
testFrameworkManagers.clear()
21+
mockFrameworkManagers.clear()
22+
variableConstructors.clear()
23+
methodConstructors.clear()
24+
}
25+
26+
private val nameGenerators: MutableMap<CgContext, CgNameGenerator> = mutableMapOf()
27+
private val statementConstructors: MutableMap<CgContext, CgStatementConstructor> = mutableMapOf()
28+
private val callableAccessManagers: MutableMap<CgContext, CgCallableAccessManager> = mutableMapOf()
29+
private val testFrameworkManagers: MutableMap<CgContext, TestFrameworkManager> = mutableMapOf()
30+
private val mockFrameworkManagers: MutableMap<CgContext, MockFrameworkManager> = mutableMapOf()
31+
32+
private val variableConstructors: MutableMap<CgContext, CgVariableConstructor> = mutableMapOf()
33+
private val methodConstructors: MutableMap<CgContext, CgMethodConstructor> = mutableMapOf()
34+
35+
fun getNameGeneratorBy(context: CgContext) = nameGenerators.getOrPut(context) {
36+
context.cgLanguageAssistant.getNameGeneratorBy(context)
37+
}
38+
fun getCallableAccessManagerBy(context: CgContext) = callableAccessManagers.getOrPut(context) {
39+
context.cgLanguageAssistant.getCallableAccessManagerBy(context)
40+
}
41+
fun getStatementConstructorBy(context: CgContext) = statementConstructors.getOrPut(context) {
42+
context.cgLanguageAssistant.getStatementConstructorBy(context)
43+
}
44+
45+
fun getTestFrameworkManagerBy(context: CgContext) =
46+
testFrameworkManagers.getOrDefault(context, context.cgLanguageAssistant.getLanguageTestFrameworkManager().managerByFramework(context))
47+
48+
fun getMockFrameworkManagerBy(context: CgContext) = mockFrameworkManagers.getOrPut(context) { MockFrameworkManager(context) }
49+
fun getVariableConstructorBy(context: CgContext) = variableConstructors.getOrPut(context) {
50+
context.cgLanguageAssistant.getVariableConstructorBy(context)
51+
}
52+
fun getMethodConstructorBy(context: CgContext) = methodConstructors.getOrPut(context) {
53+
context.cgLanguageAssistant.getMethodConstructorBy(context)
54+
}
55+
}

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/tree/CgMethodConstructor.kt

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package org.utbot.framework.codegen.tree
22

3-
import org.utbot.common.PathUtil
43
import org.utbot.common.WorkaroundReason
54
import org.utbot.common.isStatic
65
import org.utbot.common.workaround
76
import org.utbot.engine.ArtificialError
7+
import org.utbot.framework.UtSettings
88
import org.utbot.framework.assemble.assemble
99
import org.utbot.framework.codegen.domain.ForceStaticMocking
1010
import org.utbot.framework.codegen.domain.ParametrizedTestSource
1111
import org.utbot.framework.codegen.domain.RuntimeExceptionTestsBehaviour.PASS
12-
import org.utbot.framework.codegen.domain.models.CgMethodTestSet
1312
import org.utbot.framework.codegen.domain.builtin.closeMethodIdOrNull
1413
import org.utbot.framework.codegen.domain.builtin.forName
1514
import org.utbot.framework.codegen.domain.builtin.getClass
@@ -22,8 +21,6 @@ import org.utbot.framework.codegen.domain.models.CgAllocateArray
2221
import org.utbot.framework.codegen.domain.models.CgArrayElementAccess
2322
import org.utbot.framework.codegen.domain.models.CgClassId
2423
import org.utbot.framework.codegen.domain.models.CgDeclaration
25-
import org.utbot.framework.codegen.domain.models.CgDocPreTagStatement
26-
import org.utbot.framework.codegen.domain.models.CgDocRegularStmt
2724
import org.utbot.framework.codegen.domain.models.CgDocumentationComment
2825
import org.utbot.framework.codegen.domain.models.CgEqualTo
2926
import org.utbot.framework.codegen.domain.models.CgErrorTestMethod
@@ -34,6 +31,7 @@ import org.utbot.framework.codegen.domain.models.CgGetJavaClass
3431
import org.utbot.framework.codegen.domain.models.CgLiteral
3532
import org.utbot.framework.codegen.domain.models.CgMethod
3633
import org.utbot.framework.codegen.domain.models.CgMethodCall
34+
import org.utbot.framework.codegen.domain.models.CgMethodTestSet
3735
import org.utbot.framework.codegen.domain.models.CgMultilineComment
3836
import org.utbot.framework.codegen.domain.models.CgNotNullAssertion
3937
import org.utbot.framework.codegen.domain.models.CgParameterDeclaration
@@ -53,10 +51,19 @@ import org.utbot.framework.codegen.domain.models.CgValue
5351
import org.utbot.framework.codegen.domain.models.CgVariable
5452
import org.utbot.framework.codegen.domain.models.convertDocToCg
5553
import org.utbot.framework.codegen.domain.models.toStatement
54+
import org.utbot.framework.codegen.services.access.CgCallableAccessManager
55+
import org.utbot.framework.codegen.services.access.CgFieldStateManagerImpl
56+
import org.utbot.framework.codegen.services.framework.TestFrameworkManager
57+
import org.utbot.framework.codegen.tree.CgComponents.getCallableAccessManagerBy
58+
import org.utbot.framework.codegen.tree.CgComponents.getMockFrameworkManagerBy
59+
import org.utbot.framework.codegen.tree.CgComponents.getNameGeneratorBy
60+
import org.utbot.framework.codegen.tree.CgComponents.getStatementConstructorBy
61+
import org.utbot.framework.codegen.tree.CgComponents.getTestFrameworkManagerBy
62+
import org.utbot.framework.codegen.tree.CgComponents.getVariableConstructorBy
63+
import org.utbot.framework.codegen.util.canBeReadFrom
5664
import org.utbot.framework.codegen.util.canBeSetFrom
5765
import org.utbot.framework.codegen.util.equalTo
5866
import org.utbot.framework.codegen.util.inc
59-
import org.utbot.framework.codegen.util.canBeReadFrom
6067
import org.utbot.framework.codegen.util.length
6168
import org.utbot.framework.codegen.util.lessThan
6269
import org.utbot.framework.codegen.util.nullLiteral
@@ -67,10 +74,10 @@ import org.utbot.framework.plugin.api.BuiltinClassId
6774
import org.utbot.framework.plugin.api.BuiltinMethodId
6875
import org.utbot.framework.plugin.api.ClassId
6976
import org.utbot.framework.plugin.api.CodegenLanguage
70-
import org.utbot.framework.plugin.api.InstrumentedProcessDeathException
7177
import org.utbot.framework.plugin.api.ConstructorId
7278
import org.utbot.framework.plugin.api.ExecutableId
7379
import org.utbot.framework.plugin.api.FieldId
80+
import org.utbot.framework.plugin.api.InstrumentedProcessDeathException
7481
import org.utbot.framework.plugin.api.MethodId
7582
import org.utbot.framework.plugin.api.TimeoutException
7683
import org.utbot.framework.plugin.api.TypeParameters
@@ -83,79 +90,69 @@ import org.utbot.framework.plugin.api.UtDirectSetFieldModel
8390
import org.utbot.framework.plugin.api.UtEnumConstantModel
8491
import org.utbot.framework.plugin.api.UtExecution
8592
import org.utbot.framework.plugin.api.UtExecutionFailure
93+
import org.utbot.framework.plugin.api.UtExecutionResult
8694
import org.utbot.framework.plugin.api.UtExecutionSuccess
8795
import org.utbot.framework.plugin.api.UtExplicitlyThrownException
8896
import org.utbot.framework.plugin.api.UtLambdaModel
8997
import org.utbot.framework.plugin.api.UtModel
9098
import org.utbot.framework.plugin.api.UtNewInstanceInstrumentation
9199
import org.utbot.framework.plugin.api.UtNullModel
100+
import org.utbot.framework.plugin.api.UtOverflowFailure
92101
import org.utbot.framework.plugin.api.UtPrimitiveModel
93102
import org.utbot.framework.plugin.api.UtReferenceModel
94103
import org.utbot.framework.plugin.api.UtSandboxFailure
95104
import org.utbot.framework.plugin.api.UtStaticMethodInstrumentation
105+
import org.utbot.framework.plugin.api.UtStreamConsumingFailure
96106
import org.utbot.framework.plugin.api.UtSymbolicExecution
97107
import org.utbot.framework.plugin.api.UtTimeoutException
98108
import org.utbot.framework.plugin.api.UtVoidModel
99109
import org.utbot.framework.plugin.api.isNotNull
100110
import org.utbot.framework.plugin.api.isNull
101111
import org.utbot.framework.plugin.api.onFailure
102112
import org.utbot.framework.plugin.api.onSuccess
113+
import org.utbot.framework.plugin.api.util.allSuperTypes
114+
import org.utbot.framework.plugin.api.util.baseStreamClassId
103115
import org.utbot.framework.plugin.api.util.doubleArrayClassId
104116
import org.utbot.framework.plugin.api.util.doubleClassId
117+
import org.utbot.framework.plugin.api.util.doubleStreamClassId
118+
import org.utbot.framework.plugin.api.util.doubleStreamToArrayMethodId
105119
import org.utbot.framework.plugin.api.util.doubleWrapperClassId
106120
import org.utbot.framework.plugin.api.util.executable
107-
import org.utbot.framework.plugin.api.util.jField
108121
import org.utbot.framework.plugin.api.util.floatArrayClassId
109122
import org.utbot.framework.plugin.api.util.floatClassId
110123
import org.utbot.framework.plugin.api.util.floatWrapperClassId
111124
import org.utbot.framework.plugin.api.util.hasField
112125
import org.utbot.framework.plugin.api.util.id
113126
import org.utbot.framework.plugin.api.util.intClassId
127+
import org.utbot.framework.plugin.api.util.intStreamClassId
128+
import org.utbot.framework.plugin.api.util.intStreamToArrayMethodId
114129
import org.utbot.framework.plugin.api.util.isArray
130+
import org.utbot.framework.plugin.api.util.isInaccessibleViaReflection
115131
import org.utbot.framework.plugin.api.util.isInnerClassEnclosingClassReference
116132
import org.utbot.framework.plugin.api.util.isIterableOrMap
117133
import org.utbot.framework.plugin.api.util.isPrimitive
118134
import org.utbot.framework.plugin.api.util.isPrimitiveArray
119135
import org.utbot.framework.plugin.api.util.isPrimitiveWrapper
120136
import org.utbot.framework.plugin.api.util.isRefType
137+
import org.utbot.framework.plugin.api.util.isStatic
138+
import org.utbot.framework.plugin.api.util.isSubtypeOf
121139
import org.utbot.framework.plugin.api.util.jClass
140+
import org.utbot.framework.plugin.api.util.jField
122141
import org.utbot.framework.plugin.api.util.kClass
142+
import org.utbot.framework.plugin.api.util.longStreamClassId
143+
import org.utbot.framework.plugin.api.util.longStreamToArrayMethodId
123144
import org.utbot.framework.plugin.api.util.objectArrayClassId
124145
import org.utbot.framework.plugin.api.util.objectClassId
146+
import org.utbot.framework.plugin.api.util.streamClassId
147+
import org.utbot.framework.plugin.api.util.streamToArrayMethodId
125148
import org.utbot.framework.plugin.api.util.stringClassId
126149
import org.utbot.framework.plugin.api.util.voidClassId
127150
import org.utbot.framework.plugin.api.util.wrapIfPrimitive
128-
import org.utbot.framework.plugin.api.util.isInaccessibleViaReflection
129151
import org.utbot.framework.util.isUnit
130152
import org.utbot.summary.SummarySentenceConstants.TAB
131153
import java.lang.reflect.InvocationTargetException
132-
import java.security.AccessControlException
133154
import java.lang.reflect.ParameterizedType
134-
import org.utbot.framework.UtSettings
135-
import org.utbot.framework.codegen.services.access.CgCallableAccessManager
136-
import org.utbot.framework.codegen.services.access.CgFieldStateManagerImpl
137-
import org.utbot.framework.codegen.services.framework.TestFrameworkManager
138-
import org.utbot.framework.codegen.tree.CgTestClassConstructor.CgComponents.getCallableAccessManagerBy
139-
import org.utbot.framework.codegen.tree.CgTestClassConstructor.CgComponents.getMockFrameworkManagerBy
140-
import org.utbot.framework.codegen.tree.CgTestClassConstructor.CgComponents.getNameGeneratorBy
141-
import org.utbot.framework.codegen.tree.CgTestClassConstructor.CgComponents.getStatementConstructorBy
142-
import org.utbot.framework.codegen.tree.CgTestClassConstructor.CgComponents.getTestFrameworkManagerBy
143-
import org.utbot.framework.codegen.tree.CgTestClassConstructor.CgComponents.getVariableConstructorBy
144-
import org.utbot.framework.plugin.api.UtExecutionResult
145-
import org.utbot.framework.plugin.api.UtOverflowFailure
146-
import org.utbot.framework.plugin.api.UtStreamConsumingFailure
147-
import org.utbot.framework.plugin.api.util.allSuperTypes
148-
import org.utbot.framework.plugin.api.util.baseStreamClassId
149-
import org.utbot.framework.plugin.api.util.doubleStreamClassId
150-
import org.utbot.framework.plugin.api.util.doubleStreamToArrayMethodId
151-
import org.utbot.framework.plugin.api.util.intStreamClassId
152-
import org.utbot.framework.plugin.api.util.intStreamToArrayMethodId
153-
import org.utbot.framework.plugin.api.util.isSubtypeOf
154-
import org.utbot.framework.plugin.api.util.longStreamClassId
155-
import org.utbot.framework.plugin.api.util.longStreamToArrayMethodId
156-
import org.utbot.framework.plugin.api.util.streamClassId
157-
import org.utbot.framework.plugin.api.util.streamToArrayMethodId
158-
import org.utbot.framework.plugin.api.util.isStatic
155+
import java.security.AccessControlException
159156

160157
private const val DEEP_EQUALS_MAX_DEPTH = 5 // TODO move it to plugin settings?
161158

0 commit comments

Comments
 (0)