Skip to content

Commit e01465f

Browse files
committed
Refactor engine actions
1 parent d004d34 commit e01465f

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.utbot.framework.plugin.api
2+
3+
import org.utbot.engine.UtBotSymbolicEngine
4+
5+
class EngineActionsController {
6+
private val actions: MutableList<(UtBotSymbolicEngine) -> Unit> = mutableListOf()
7+
8+
fun add(action: (UtBotSymbolicEngine) -> Unit) {
9+
actions.add(action)
10+
}
11+
12+
fun apply(symbolicEngine: UtBotSymbolicEngine) {
13+
actions.forEach { symbolicEngine.apply(it) }
14+
actions.clear()
15+
}
16+
}

utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ open class TestCaseGenerator(
6060
private val buildDir: Path,
6161
private val classpath: String?,
6262
private val dependencyPaths: String,
63-
val engineActions: MutableList<(UtBotSymbolicEngine) -> Unit> = mutableListOf(),
6463
val isCanceled: () -> Boolean = { false },
6564
val forceSootReload: Boolean = true
6665
) {
66+
val engineActions: EngineActionsController = EngineActionsController()
6767
private val logger: KLogger = KotlinLogging.logger {}
6868
private val timeoutLogger: KLogger = KotlinLogging.logger(logger.name + ".timeout")
6969

@@ -121,9 +121,9 @@ open class TestCaseGenerator(
121121
chosenClassesToMockAlways: Set<ClassId> = Mocker.javaDefaultClasses.mapTo(mutableSetOf()) { it.id },
122122
executionTimeEstimator: ExecutionTimeEstimator = ExecutionTimeEstimator(utBotGenerationTimeoutInMillis, 1)
123123
): Flow<UtResult> {
124-
val engine = createSymbolicEngine(controller, method, mockStrategy, chosenClassesToMockAlways, executionTimeEstimator)
125-
engineActions.map { engine.apply(it) }
126-
engineActions.clear()
124+
val engine =
125+
createSymbolicEngine(controller, method, mockStrategy, chosenClassesToMockAlways, executionTimeEstimator)
126+
.also { engine -> engineActions.apply(engine) }
127127
return defaultTestFlow(engine, executionTimeEstimator.userTimeout)
128128
}
129129

@@ -160,10 +160,7 @@ open class TestCaseGenerator(
160160
mockStrategy,
161161
chosenClassesToMockAlways,
162162
executionTimeEstimator
163-
)
164-
165-
engineActions.map { engine.apply(it) }
166-
engineActions.clear()
163+
).also { engine -> engineActions.apply(engine) }
167164

168165
generate(engine)
169166
.catch {

utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/TestSpecificTestCaseGenerator.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ class TestSpecificTestCaseGenerator(
2929
buildDir: Path,
3030
classpath: String?,
3131
dependencyPaths: String,
32-
engineActions: MutableList<(UtBotSymbolicEngine) -> Unit> = mutableListOf(),
3332
isCanceled: () -> Boolean = { false },
34-
): TestCaseGenerator(buildDir, classpath, dependencyPaths, engineActions, isCanceled, forceSootReload = false) {
33+
): TestCaseGenerator(buildDir, classpath, dependencyPaths, isCanceled, forceSootReload = false) {
3534

3635
private val logger = KotlinLogging.logger {}
3736

0 commit comments

Comments
 (0)