Skip to content

Commit 399a8b8

Browse files
committed
Refactor to only transform JavaValueProvider via applicationContext (avoid redundant lambdas)
1 parent 7405050 commit 399a8b8

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ class UtBotSymbolicEngine(
425425
* @param until is used by fuzzer to cancel all tasks if the current time is over this value
426426
* @param transform provides model values for a method
427427
*/
428-
fun fuzzing(until: Long = Long.MAX_VALUE, transform: (JavaValueProvider) -> JavaValueProvider = { it }) = flow {
428+
fun fuzzing(until: Long = Long.MAX_VALUE) = flow {
429429
val isFuzzable = methodUnderTest.parameters.all { classId ->
430430
classId != Method::class.java.id && // causes the instrumented process crash at invocation
431431
classId != Class::class.java.id // causes java.lang.IllegalAccessException: java.lang.Class at sun.misc.Unsafe.allocateInstance(Native Method)
@@ -453,7 +453,7 @@ class UtBotSymbolicEngine(
453453
methodUnderTest,
454454
constants = collectConstantsForFuzzer(graph),
455455
names = names,
456-
providers = listOf(transform(fuzzingContext.valueProvider)),
456+
providers = listOf(fuzzingContext.valueProvider),
457457
) { thisInstance, descr, values ->
458458
val diff = until - System.currentTimeMillis()
459459
val thresholdMillisForFuzzingOperation = 0 // may be better use 10-20 millis as it might not be possible

utbot-framework/src/main/kotlin/org/utbot/external/api/UtBotJavaApi.kt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import org.utbot.framework.codegen.domain.TestFramework
1212
import org.utbot.framework.codegen.generator.CodeGenerator
1313
import org.utbot.framework.codegen.generator.CodeGeneratorParams
1414
import org.utbot.framework.codegen.services.language.CgLanguageAssistant
15+
import org.utbot.framework.context.simple.SimpleApplicationContext
16+
import org.utbot.framework.context.utils.transformValueProvider
1517
import org.utbot.instrumentation.instrumentation.execution.UtConcreteExecutionData
1618
import org.utbot.instrumentation.instrumentation.execution.UtConcreteExecutionResult
1719
import org.utbot.instrumentation.instrumentation.execution.UtExecutionInstrumentation
@@ -181,19 +183,23 @@ object UtBotJavaApi {
181183

182184
return withUtContext(UtContext(classUnderTest.classLoader)) {
183185
val buildPath = FileUtil.isolateClassFiles(classUnderTest).toPath()
184-
TestCaseGenerator(listOf(buildPath), classpath, dependencyClassPath, jdkInfo = JdkInfoDefaultProvider().info)
186+
TestCaseGenerator(
187+
listOf(buildPath),
188+
classpath,
189+
dependencyClassPath,
190+
jdkInfo = JdkInfoDefaultProvider().info,
191+
applicationContext = SimpleApplicationContext().transformValueProvider { defaultModelProvider ->
192+
customModelProvider.withFallback(defaultModelProvider)
193+
}
194+
)
185195
.generate(
186196
methodsForAutomaticGeneration.map {
187197
it.methodToBeTestedFromUserInput.executableId
188198
},
189199
mockStrategyApi,
190200
chosenClassesToMockAlways = emptySet(),
191201
generationTimeoutInMillis,
192-
generate = { symbolicEngine ->
193-
symbolicEngine.fuzzing { defaultModelProvider ->
194-
customModelProvider.withFallback(defaultModelProvider)
195-
}
196-
}
202+
generate = { symbolicEngine -> symbolicEngine.fuzzing() }
197203
)
198204
}.toMutableList()
199205
}

utbot-framework/src/main/kotlin/org/utbot/framework/context/simple/SimpleApplicationContext.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ import org.utbot.framework.context.TypeReplacer
1313
* A context to use when no specific data is required.
1414
*/
1515
class SimpleApplicationContext(
16-
override val mockerContext: MockerContext,
16+
override val mockerContext: MockerContext = SimpleMockerContext(
17+
mockFrameworkInstalled = true,
18+
staticsMockingIsConfigured = true
19+
),
1720
override val typeReplacer: TypeReplacer = SimpleTypeReplacer(),
1821
override val nonNullSpeculator: NonNullSpeculator = SimpleNonNullSpeculator()
1922
) : ApplicationContext {

0 commit comments

Comments
 (0)