Skip to content

Commit d24bf73

Browse files
committed
Refactor engine actions
1 parent b0fadae commit d24bf73

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
@@ -57,9 +57,9 @@ open class TestCaseGenerator(
5757
private val buildDir: Path,
5858
private val classpath: String?,
5959
private val dependencyPaths: String,
60-
val engineActions: MutableList<(UtBotSymbolicEngine) -> Unit> = mutableListOf(),
6160
val isCanceled: () -> Boolean = { false },
6261
) {
62+
val engineActions: EngineActionsController = EngineActionsController()
6363
private val logger: KLogger = KotlinLogging.logger {}
6464
private val timeoutLogger: KLogger = KotlinLogging.logger(logger.name + ".timeout")
6565

@@ -117,9 +117,9 @@ open class TestCaseGenerator(
117117
chosenClassesToMockAlways: Set<ClassId> = Mocker.javaDefaultClasses.mapTo(mutableSetOf()) { it.id },
118118
executionTimeEstimator: ExecutionTimeEstimator = ExecutionTimeEstimator(utBotGenerationTimeoutInMillis, 1)
119119
): Flow<UtResult> {
120-
val engine = createSymbolicEngine(controller, method, mockStrategy, chosenClassesToMockAlways, executionTimeEstimator)
121-
engineActions.map { engine.apply(it) }
122-
engineActions.clear()
120+
val engine =
121+
createSymbolicEngine(controller, method, mockStrategy, chosenClassesToMockAlways, executionTimeEstimator)
122+
.also { engine -> engineActions.apply(engine) }
123123
return defaultTestFlow(engine, executionTimeEstimator.userTimeout)
124124
}
125125

@@ -156,10 +156,7 @@ open class TestCaseGenerator(
156156
mockStrategy,
157157
chosenClassesToMockAlways,
158158
executionTimeEstimator
159-
)
160-
161-
engineActions.map { engine.apply(it) }
162-
engineActions.clear()
159+
).also { engine -> engineActions.apply(engine) }
163160

164161
generate(engine)
165162
.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) {
33+
): TestCaseGenerator(buildDir, classpath, dependencyPaths, isCanceled) {
3534

3635
private val logger = KotlinLogging.logger {}
3736

0 commit comments

Comments
 (0)